Изменения

Funq

342 байта убрано, 21:28, 20 сентября 2009
Примеры запросов
== Примеры запросов ==
 
=== Пример 1: Сложный запрос ===
Вот, например, запрос из начала статьи на Perl:
<source lang="perl">$query = $dbhfunq
->query(album2album => "t1")->where("t1.parent=? and t1.pid=?pid")
->join($dbhfunq->query(albums => "t0")->where("t0.id=t1.child and t0.?t0where"))->leftjoin($dbhfunq->query(album2album => "t3")->where("t3.parent=t1.parent and t3.pid=?pid"))->join($dbhfunq->query(album2album => "t4")->where("t4.parent=t3.child and t4.child=t1.child and t4.pid=?pid"))->select("t0.*", "(t3.parent is null) as t1._direct")->hint({calc-found-rows => 1}'calc_found_rows')
->group("t0.id")
->where("t1._direct=1")
<source lang="perl">
$rows = $query->stmt->hasharray({
parent => $parent,
pid => $pid,
</source>
А вот он же, но с вызовами join у объекта запроса, а не у $dbh: <source lang="perl">$dbh->query(album2album => "t1")->where("t1.parent=? and t1.pid=?pid")->join($dbh->query(albums => "t0")->where("t0.id=t1.child and t0.?t0where"))->join(left => $dbh->query(album2album => "t3")->where("t3.parent=t1.parent and t3.pid=?pid"))->join($dbh->query(album2album => "t4")->where("t4.parent=t3.child and t4.child=t1.child and t4.pidПример 2: Запрос попроще =?pid"))->select("t0.*", "(t3.parent is null) as t1._direct")->hint({calc-found-rows => 1})->group("t0.id")->where("t1._direct=1")->order("t0.ord desc, t0.name")->limit("?offset", "?limit")</source>
Запрос попроще:
->limit("?offset", "?limit")
</source>
 
=== Пример 3: Очень простой ===
Или совсем простой:
$dbh->query("exif")->where("file=?")
</source>
 
=== Пример 4: Подзапрос ===
А вот подзапрос:
)
</source>
 
=== Пример 5: Вложенный подзапрос ===
Или даже два вложенных подзапроса:
)
</source>
 
=== Пример 6: Запрос из DBIx::Class::Cookbook ===
SQL-запрос: