Skip to content

Commit aaba2f9

Browse files
author
Gabriel Tadra Mainginski
committed
Fix #6, but this is very slow and not guaranteed to tables with more than one primary key.
1 parent 458672d commit aaba2f9

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

Database/SybaseConnection.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,9 @@ protected function getDoctrineDriver()
9595
}
9696

9797
private function compileForSelect(Builder $builder, $bindings) {
98-
99-
if(count($bindings)==0){
100-
return [];
101-
}
102-
$bindings = $this->prepareBindings($bindings);
10398

99+
100+
104101
$arrTables = [];
105102
array_push($arrTables, $builder->from);
106103

@@ -159,7 +156,6 @@ private function compileForSelect(Builder $builder, $bindings) {
159156
*/
160157
private function compileBindings($query, $bindings)
161158
{
162-
163159

164160
if(count($bindings)==0){
165161
return [];
@@ -168,7 +164,7 @@ private function compileBindings($query, $bindings)
168164
$bindings = $this->prepareBindings($bindings);
169165
$new_format = [];
170166

171-
switch(\explode(' ', $query)[0]){
167+
switch(explode(' ', $query)[0]){
172168
case "select":
173169
return $this->compileForSelect($this->queryGrammar->getBuilder(), $bindings);
174170
case "insert":
@@ -284,8 +280,33 @@ public function select($query, $bindings = array(), $useReadPdo = true)
284280
return $this->run($query, $bindings, function($me, $query, $bindings) use ($useReadPdo)
285281
{
286282
if ($me->pretending()) return array();
287-
return $this->getPdo()->query($this->compileNewQuery($query, $bindings))->fetchAll($me->getFetchMode());
288-
});
283+
$offset = $this->queryGrammar->getBuilder()->offset;
284+
$limit = $this->queryGrammar->getBuilder()->limit;
285+
if($offset>0){
286+
if(!isset($limit)){
287+
$limit = 999999999999999999999999999;
288+
}
289+
$primarys = $this->getPdo()->query("SELECT index_col(object_name(i.id), i.indid, c.colid) AS primary_key
290+
FROM sysindexes i, syscolumns c WHERE i.id = c.id AND c.colid <= i.keycnt AND i.id = object_id('precos')")->fetchAll($me->getFetchMode());
291+
foreach($primarys as $primary)
292+
{
293+
$new_arr[] = $primary->primary_key.'+0 AS '.$primary->primary_key;
294+
$where_arr[] = "#tmpPaginate.".$primary->primary_key.' = #tmpTable.'.$primary->primary_key;
295+
}
296+
$res_primarys = implode(', ',$new_arr);
297+
$where_primarys = implode(' AND ',$where_arr);
298+
299+
//Offset operation
300+
$this->getPdo()->query(str_replace(" from ", " into #tmpPaginate from ", $this->compileNewQuery($query, $bindings)));
301+
$this->getPdo()->query("SELECT ".$res_primarys.", idTmp=identity(18) INTO #tmpTable FROM #tmpPaginate");
302+
return $this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primarys." WHERE #tmpTable.idTmp "
303+
. "BETWEEN ".($offset+1) ." AND ". ($offset+$limit)
304+
." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode());
305+
}else{
306+
return $this->getPdo()->query($this->compileNewQuery($query, $bindings))->fetchAll($me->getFetchMode());
307+
}
308+
309+
});
289310
}
290311

291312
/**

0 commit comments

Comments
 (0)