Skip to content

Commit da2a5cd

Browse files
committed
remove cursored pagination as default since this only works for order queries on a unique field
1 parent 766f362 commit da2a5cd

File tree

4 files changed

+26
-41
lines changed

4 files changed

+26
-41
lines changed

lib/vendor/creole/drivers/mssqlsrv/MSSQLSRVConnection.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ public function createStatement()
126126
*/
127127
public function applyLimit(&$sql, $offset, $limit)
128128
{
129-
if($limit > 0)
130-
{
131-
$sql .= ' offset ' . ($offset?: 0) . ' rows ';
132-
$sql .= ' fetch next ' . $limit . ' rows only ';
133-
}
134-
else if($offset > 0) {
135-
$sql .= ' offset ' . ($offset?: 0) . ' rows ';
136-
}
129+
// MSSQL doesn't support this method.
130+
// It could however do a 'cursor' based query.
131+
// The only problem is you can not do this in a generic way
132+
// since a cursor query requires an order by clause on a unique table.
133+
// (ex. "name" is not unique so applying this by default would break the query)
134+
135+
// Therefor we don't apply this method anymore until we have a way of letting the
136+
// query itself pass to this method if it can use cursor query.
137137
}
138138

139139
/**

lib/vendor/creole/drivers/mssqlsrv/MSSQLSRVPreparedStatement.php

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,44 +61,27 @@ protected function escape($subject)
6161
*/
6262
public function executeQuery($p1 = null, $fetchmode = null)
6363
{
64-
$params = null;
65-
if ($fetchmode !== null) {
66-
$params = $p1;
67-
} elseif ($p1 !== null) {
68-
if (is_array($p1)) $params = $p1;
69-
else $fetchmode = $p1;
70-
}
71-
72-
if ($params) {
73-
for($i=0,$cnt=count($params); $i < $cnt; $i++) {
74-
$this->set($i+1, $params[$i]);
64+
$params = null;
65+
if ($fetchmode !== null) {
66+
$params = $p1;
67+
} elseif ($p1 !== null) {
68+
if (is_array($p1)) $params = $p1;
69+
else $fetchmode = $p1;
7570
}
76-
}
77-
78-
$this->updateCount = null; // reset
79-
$sql = $this->replaceParams();
80-
81-
if(stripos($sql, 'ORDER BY'))
82-
$offsetBefore = true;
83-
else
84-
$offsetBefore = false;
8571

86-
if($offsetBefore)
87-
{
88-
if ($this->limit > 0 || $this->offset > 0) {
89-
$this->conn->applyLimit($sql, $this->offset, $this->limit);
72+
if ($params) {
73+
for($i=0,$cnt=count($params); $i < $cnt; $i++) {
74+
$this->set($i+1, $params[$i]);
75+
}
9076
}
91-
}
9277

93-
$this->resultSet = $this->conn->executeQuery($sql, $fetchmode);
78+
$this->updateCount = null; // reset
79+
$sql = $this->replaceParams();
9480

95-
if(!$offsetBefore)
96-
{
81+
$this->resultSet = $this->conn->executeQuery($sql, $fetchmode);
9782
$this->resultSet->_setOffset($this->offset);
9883
$this->resultSet->_setLimit($this->limit);
99-
}
100-
101-
return $this->resultSet;
84+
return $this->resultSet;
10285
}
10386

10487
/**

lib/vendor/creole/drivers/mssqlsrv/MSSQLSRVResultSet.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function seek($rownum)
8787
return false;
8888
}
8989

90-
if (($this->limit > 0 && $rownum >= $this->limit) || $rownum < 0) {
90+
if (($this->limit > 0 && $rownum >= $this->limit)) {
9191
// have to check for rownum < 0, because mssql_seek() won't
9292
// complain if the $actual is valid.
9393
return false;
@@ -96,7 +96,7 @@ function seek($rownum)
9696
// MSSQL rows start w/ 0, but this works, because we are
9797
// looking to move the position _before_ the next desired position
9898
if (!sqlsrv_fetch($this->result, SQLSRV_SCROLL_ABSOLUTE, $rownum + $this->offset)) {
99-
return false;
99+
return false;
100100
}
101101

102102
$this->cursorPos = $rownum;

lib/vendor/propel/adapter/DBMSSQL.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class DBMSSQL extends DBSybase {
3838
*/
3939
public function applyLimit(&$sql, $offset, $limit)
4040
{
41+
42+
4143
// make sure offset and limit are numeric
4244
if(!is_numeric($offset) || !is_numeric($limit)){
4345
throw new Exception("DBMSSQL ::applyLimit() expects a number for argument 2 and 3");

0 commit comments

Comments
 (0)