Skip to content

Commit 0059cca

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

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

Database/SybaseConnection.php

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ private function compileForSelect(Builder $builder, $bindings) {
102102
$tables = $alias['table'];
103103
}
104104

105-
$queryRes = $this->getPdo()->query("select a.name, b.name AS type FROM syscolumns a noholdlock JOIN systypes b noholdlock ON a.usertype = b.usertype and object_name(a.id) = '".$tables."'");
105+
$explicitDB = explode('..', $tables);
106+
if(isset($explicitDB[1])){
107+
$queryRes = $this->getPdo()->query("select b.name, c.name AS type from ".$explicitDB[0]."..sysobjects a noholdlock JOIN ".$explicitDB[0]."..syscolumns b noholdlock ON a.id = b.id JOIN ".$explicitDB[0]."..systypes c noholdlock ON b.usertype = c.usertype and a.name = '".$explicitDB[1]."'");
108+
}else{
109+
$queryRes = $this->getPdo()->query("select a.name, b.name AS type FROM syscolumns a noholdlock JOIN systypes b noholdlock ON a.usertype = b.usertype and object_name(a.id) = '".$tables."'");
110+
}
111+
106112
$types[$tables] = $queryRes->fetchAll(\PDO::FETCH_NAMED);
107113

108114
foreach ($types[$tables] as &$row) {
@@ -253,32 +259,14 @@ private function compileNewQuery($query, $bindings)
253259
}
254260
}
255261
}
262+
$newQuery = str_replace( "[]", '' ,$newQuery);
256263
return $newQuery;
257264
}
258265

259-
/**
260-
* Run a select statement against the database.
261-
*
262-
* @param string $query
263-
* @param array $bindings
264-
* @param bool $useReadPdo
265-
* @return array
266-
*/
267-
public function select($query, $bindings = array(), $useReadPdo = true)
268-
{
269-
return $this->run($query, $bindings, function($me, $query, $bindings) use ($useReadPdo)
270-
{
271-
if ($me->pretending()) return array();
272-
273-
if($this->queryGrammar->getBuilder() != NULL){
274-
275-
$offset = $this->queryGrammar->getBuilder()->offset;
266+
public function compileOffset($me){
267+
276268
$limit = $this->queryGrammar->getBuilder()->limit;
277269
$from = explode(" ", $this->queryGrammar->getBuilder()->from)[0];
278-
}else{
279-
$offset = 0;
280-
}
281-
if($offset>0){
282270
if(!isset($limit)){
283271
$limit = 999999999999999999999999999;
284272
}
@@ -304,10 +292,33 @@ public function select($query, $bindings = array(), $useReadPdo = true)
304292
return $this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primaries." WHERE #tmpTable.idTmp "
305293
. "BETWEEN ".($offset+1) ." AND ". ($offset+$limit)
306294
." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode());
295+
296+
}
297+
/**
298+
* Run a select statement against the database.
299+
*
300+
* @param string $query
301+
* @param array $bindings
302+
* @param bool $useReadPdo
303+
* @return array
304+
*/
305+
public function select($query, $bindings = array(), $useReadPdo = true)
306+
{
307+
return $this->run($query, $bindings, function($me, $query, $bindings) use ($useReadPdo)
308+
{
309+
if ($me->pretending()) return array();
310+
311+
if($this->queryGrammar->getBuilder() != NULL){
312+
$offset = $this->queryGrammar->getBuilder()->offset;
307313
}else{
308-
return $this->getPdo()->query($this->compileNewQuery($query, $bindings))->fetchAll($me->getFetchMode());
314+
$offset = 0;
315+
}
316+
317+
if($offset>0){
318+
return $this->compileOffset($me);
319+
}else{
320+
return $this->getPdo()->query($this->compileNewQuery($query, $bindings))->fetchAll($me->getFetchMode());
309321
}
310-
311322
});
312323
}
313324

0 commit comments

Comments
 (0)