Skip to content

Commit 47a89e4

Browse files
author
Gabriel Tadra Mainginski
committed
Minor fixes and better stability.
1 parent 7581980 commit 47a89e4

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Database/SybaseConnection.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,31 @@ public function select($query, $bindings = array(), $useReadPdo = true)
268268
if ($me->pretending()) return array();
269269
$offset = $this->queryGrammar->getBuilder()->offset;
270270
$limit = $this->queryGrammar->getBuilder()->limit;
271+
$from = explode(" ", $this->queryGrammar->getBuilder()->from)[0];
271272
if($offset>0){
272273
if(!isset($limit)){
273274
$limit = 999999999999999999999999999;
274275
}
275-
$primarys = $this->getPdo()->query("SELECT index_col(object_name(i.id), i.indid, c.colid) AS primary_key
276-
FROM sysindexes i, syscolumns c WHERE i.id = c.id AND c.colid <= i.keycnt AND i.id = object_id('precos')")->fetchAll($me->getFetchMode());
277-
foreach($primarys as $primary)
278-
{
279-
$new_arr[] = $primary->primary_key.'+0 AS '.$primary->primary_key;
280-
$where_arr[] = "#tmpPaginate.".$primary->primary_key.' = #tmpTable.'.$primary->primary_key;
276+
$indentity = $this->getPdo()->query("select name as 'column' from syscolumns where status & 128 = 128 AND object_name(id)='".$from."'")->fetchAll($me->getFetchMode())[0];
277+
278+
if(count($indentity) == 0){
279+
$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());
280+
foreach($primaries as $primary)
281+
{
282+
$new_arr[] = $primary->primary_key.'+0 AS '.$primary->primary_key;
283+
$where_arr[] = "#tmpPaginate.".$primary->primary_key.' = #tmpTable.'.$primary->primary_key;
284+
}
285+
$res_primaries = implode(', ',$new_arr);
286+
$where_primaries = implode(' AND ',$where_arr);
287+
}else{
288+
$res_primaries = $indentity->column.'+0 AS '.$indentity->column;
289+
$where_primaries = "#tmpPaginate.".$indentity->column.' = #tmpTable.'.$indentity->column;
281290
}
282-
$res_primarys = implode(', ',$new_arr);
283-
$where_primarys = implode(' AND ',$where_arr);
284291

285292
//Offset operation
286293
$this->getPdo()->query(str_replace(" from ", " into #tmpPaginate from ", $this->compileNewQuery($query, $bindings)));
287-
$this->getPdo()->query("SELECT ".$res_primarys.", idTmp=identity(18) INTO #tmpTable FROM #tmpPaginate");
288-
return $this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primarys." WHERE #tmpTable.idTmp "
294+
$this->getPdo()->query("SELECT ".$res_primaries.", idTmp=identity(18) INTO #tmpTable FROM #tmpPaginate");
295+
return $this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primaries." WHERE #tmpTable.idTmp "
289296
. "BETWEEN ".($offset+1) ." AND ". ($offset+$limit)
290297
." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode());
291298
}else{

0 commit comments

Comments
 (0)