Permalink
Browse files

Add Limit Offset support.

  • Loading branch information...
1 parent bb6b27b commit 7cbf1257493ed3e8dbcd0787406d1f0b85148efa @c0rrupt c0rrupt committed Jan 18, 2013
Showing with 18 additions and 11 deletions.
  1. +1 −0 .gitignore
  2. +17 −11 Platforms/DblibPlatform.php
View
1 .gitignore
@@ -0,0 +1 @@
+.idea
View
28 Platforms/DblibPlatform.php
@@ -38,7 +38,6 @@
*/
class DblibPlatform extends SQLServerPlatform
{
-
/**
* Whether the platform supports transactions.
*
@@ -58,7 +57,6 @@ public function supportsSavepoints()
{
return false;
}
-
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
@@ -81,14 +79,14 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
if ($offset == 0) {
// SELECT TOP DISTINCT does not work with mssql
- if(preg_match('#^SELECT\s+DISTINCT#i', $query) > 0) {
+ if (preg_match('#^SELECT\s+DISTINCT#i', $query) > 0) {
$query = preg_replace('/^SELECT\s+DISTINCT\s/i', 'SELECT DISTINCT TOP ' . $count . ' ', $query);
} else {
$query = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . $count . ' ', $query);
}
-
-
} else {
+ // Remove DISTINCT from query string
+ $query = preg_replace('/\s+DISTINCT/', '', $query);
$orderby = stristr($query, 'ORDER BY');
if (!$orderby) {
@@ -101,21 +99,22 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
$query = preg_replace('/\s+ORDER BY(.*)/', '', $query);
// Add ORDER BY clause as an argument for ROW_NUMBER()
- //$query = "SELECT ROW_NUMBER() OVER ($over) AS \"doctrine_rownum\", * FROM ($query) AS inner_tbl";
+ // $query = "SELECT ROW_NUMBER() OVER ($over) AS \"doctrine_rownum\", * FROM ($query) AS inner_tbl";
$query = preg_replace('/^SELECT\s/', '', $query);
$start = $offset + 1;
$end = $offset + $count;
- //$query = "WITH outer_tbl AS ($query) SELECT * FROM outer_tbl WHERE \"doctrine_rownum\" BETWEEN $start AND $end";
- $query = "SELECT * FROM (SELECT ROW_NUMBER() OVER ($over) AS \"doctrine_rownum\", $query) AS doctrine_tbl WHERE doctrine_rownum BETWEEN $start AND $end";
+ // $query = "WITH outer_tbl AS ($query) SELECT * FROM outer_tbl WHERE \"doctrine_rownum\""
+ // . "BETWEEN $start AND $end";
+ $query = "SELECT * FROM (SELECT ROW_NUMBER() OVER ($over) AS \"doctrine_rownum\", $query)"
+ . "AS doctrine_tbl WHERE doctrine_rownum BETWEEN $start AND $end";
}
}
return $query;
}
-
/**
* Get the platform name for this instance
*
@@ -126,8 +125,6 @@ public function getName()
return 'mssql';
}
-
- /**
/**
* @override
*/
@@ -146,4 +143,13 @@ public function getDateTimeFormatString()
{
return 'Y-m-d H:i:s.u';
}
+
+ /**
+ * @override
+ * @return bool
+ */
+ public function supportsLimitOffset()
+ {
+ return true;
+ }
}

0 comments on commit 7cbf125

Please sign in to comment.