Commit f5e54ad7 authored by pookey's avatar pookey

Doctrine_Session_Mssql::modifyLimitQuery() added

parent 46965043
......@@ -3,6 +3,13 @@
* standard session, the parent of pgsql, mysql and sqlite
*/
class Doctrine_Session_Common extends Doctrine_Session {
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query
* @param mixed $limit
* @param mixed $offset
*/
public function modifyLimitQuery($query,$limit = false,$offset = false) {
if($limit && $offset) {
$query .= " LIMIT ".$limit." OFFSET ".$offset;
......
......@@ -14,5 +14,59 @@ class Doctrine_Session_Mssql extends Doctrine_Session {
$data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0];
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
* [ borrowed from Zend Framework ]
*
* @param string $query
* @param mixed $limit
* @param mixed $offset
* @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html
* @return string
*/
public function modifyLimitQuery($query, $limit, $offset) {
if ($limit) {
// we need the starting SELECT clause for later
$select = 'SELECT ';
if (preg_match('/^[[:space:]*SELECT[[:space:]]*DISTINCT/i', $query, $matches) == 1)
$select .= 'DISTINCT ';
$length = strlen($select);
// is there an offset?
if (! $offset) {
// no offset, it's a simple TOP count
return "$select TOP $count" . substr($query, $length);
}
// the total of the count **and** the offset, combined.
// this will be used in the "internal" portion of the
// hacked-up statement.
$total = $count + $offset;
// build the "real" order for the external portion.
$order = implode(',', $parts['order']);
// build a "reverse" order for the internal portion.
$reverse = $order;
$reverse = str_ireplace(" ASC", " \xFF", $reverse);
$reverse = str_ireplace(" DESC", " ASC", $reverse);
$reverse = str_ireplace(" \xFF", " DESC", $reverse);
// create a main statement that replaces the SELECT
// with a SELECT TOP
$main = "\n$select TOP $total" . substr($query, $length) . "\n";
// build the hacked-up statement.
// do we really need the "as" aliases here?
$query = "SELECT * FROM ("
. "SELECT TOP $count * FROM ($main) AS select_limit_rev ORDER BY $reverse"
. ") AS select_limit ORDER BY $order";
}
return $query;
}
}
?>
......@@ -3,6 +3,13 @@
* oracle driver
*/
class Doctrine_Session_Oracle extends Doctrine_Session {
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query
* @param mixed $limit
* @param mixed $offset
*/
public function modifyLimitQuery($query,$limit,$offset) {
$e = explode("select ",strtolower($query));
$e2 = explode(" from ",$e[1]);
......
......@@ -30,11 +30,21 @@
*/
class Doctrine_Tree_NestedSet extends Doctrine_Record {
public function getLeafNodes() { }
public function getLeafNodes() {
$query = "SELECT ".implode(", ",$this->table->getColumnNames()).
" FROM ".$this->table->getTableName().
" WHERE rgt = lft + 1";
}
public function getPath() { }
public function getDepth() { }
public function getDepth() {
$query = "SELECT (COUNT(parent.name) - 1) AS depth
FROM ".$this->table->getTableName()." AS node,".
$this->table->getTableName()." AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.name";
}
public function removeNode() { }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment