Skip to content

Commit 369cd35

Browse files
author
Gabriel Tadra Mainginski
committed
The beginning to fix #9
1 parent 0059cca commit 369cd35

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Database/SybaseConnection.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,20 @@ private function compileNewQuery($query, $bindings)
263263
return $newQuery;
264264
}
265265

266-
public function compileOffset($me){
266+
public function compileOffset($offset, $query, $bindings = array(), $me){
267267

268268
$limit = $this->queryGrammar->getBuilder()->limit;
269269
$from = explode(" ", $this->queryGrammar->getBuilder()->from)[0];
270270
if(!isset($limit)){
271271
$limit = 999999999999999999999999999;
272272
}
273-
$indentity = $this->getPdo()->query("select name as 'column' from syscolumns where status & 128 = 128 AND object_name(id)='".$from."'")->fetchAll($me->getFetchMode())[0];
274-
275-
if(count($indentity) == 0){
273+
$explicitDB = explode('..', $from);
274+
if(isset($explicitDB[1])){
275+
$identity = $this->getPdo()->query("select b.name as 'column' from ".$explicitDB[0]."..syscolumns AS b INNER JOIN ".$explicitDB[0]."..sysobjects AS a ON a.id = b.id WHERE status & 128 = 128 AND a.name ='".$explicitDB[1]."'")->fetchAll($me->getFetchMode())[0];
276+
}else{
277+
$identity = $this->getPdo()->query("select name as 'column' from syscolumns where status & 128 = 128 AND object_name(id)='".$from."'")->fetchAll($me->getFetchMode())[0];
278+
}
279+
if(count($identity) == 0){
276280
$primaries = $this->getPdo()->query("SELECT index_col(object_name(i.id), i.indid, c.colid) AS primary_key FROM sysindexes i, syscolumns c WHERE i.id = c.id AND c.colid <= i.keycnt AND i.id = object_id('".$from."')")->fetchAll($me->getFetchMode());
277281
foreach($primaries as $primary)
278282
{
@@ -282,8 +286,8 @@ public function compileOffset($me){
282286
$res_primaries = implode(', ',$new_arr);
283287
$where_primaries = implode(' AND ',$where_arr);
284288
}else{
285-
$res_primaries = $indentity->column.'+0 AS '.$indentity->column;
286-
$where_primaries = "#tmpPaginate.".$indentity->column.' = #tmpTable.'.$indentity->column;
289+
$res_primaries = $identity->column.'+0 AS '.$identity->column;
290+
$where_primaries = "#tmpPaginate.".$identity->column.' = #tmpTable.'.$identity->column;
287291
}
288292

289293
//Offset operation
@@ -315,7 +319,7 @@ public function select($query, $bindings = array(), $useReadPdo = true)
315319
}
316320

317321
if($offset>0){
318-
return $this->compileOffset($me);
322+
return $this->compileOffset($offset, $query, $bindings, $me);
319323
}else{
320324
return $this->getPdo()->query($this->compileNewQuery($query, $bindings))->fetchAll($me->getFetchMode());
321325
}

0 commit comments

Comments
 (0)