Skip to content

Commit fe8b367

Browse files
author
Gabriel Tadra Mainginski
committed
Merging dev in master
2 parents 208a2ce + 751bf6d commit fe8b367

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

Database/SybaseConnection.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ private function compileForSelect(Builder $builder, $bindings) {
118118
} else {
119119
$tables = $alias['table'];
120120
}
121-
122121
$queryString = $this->queryStringForSelect($tables);
123122
$queryRes = $this->getPdo()->query($queryString);
124123
$types[$tables] = $queryRes->fetchAll(\PDO::FETCH_NAMED);
@@ -128,6 +127,32 @@ private function compileForSelect(Builder $builder, $bindings) {
128127
$tipos[strtolower($tables.'.'.$row['name'])] = $row['type'];
129128
if (!empty($alias['alias'])) {
130129
$tipos[strtolower($alias['alias'].'.'.$row['name'])] = $row['type'];
130+
}
131+
}
132+
$wheres = [];
133+
foreach($builder->wheres as $w){
134+
switch($w['type']){
135+
default:
136+
array_push($wheres, $w);
137+
break;
138+
case "Nested":
139+
$wheres += $w['query']->wheres;
140+
break;
141+
}
142+
}
143+
$i = 0;
144+
for($ind = 0; $ind < count($wheres); $ind++ ){
145+
if(isset($wheres[$ind]['value'])){
146+
if(in_array(strtolower($tipos[strtolower($wheres[$ind]['column'])]), $this->without_quotes)){
147+
if(!is_null($bindings[$i])){
148+
$new_binds[$i] = $bindings[$i]/1;
149+
}else{
150+
$new_binds[$i] = null;
151+
}
152+
}else{
153+
$new_binds[$i] = (string)$bindings[$i];
154+
}
155+
$i++;
131156
}
132157
}
133158

@@ -372,17 +397,15 @@ public function compileOffset($offset, $query, $bindings = array(), $me)
372397
} else {
373398
$res_primaries = $identity->column.'+0 AS '.$identity->column;
374399
$where_primaries = "#tmpPaginate.".$identity->column.' = #tmpTable.'.$identity->column;
400+
//Offset operation
401+
$this->getPdo()->query(str_replace(" from ", " into #tmpPaginate from ", $this->compileNewQuery($query, $bindings)));
402+
$this->getPdo()->query("SELECT ".$res_primaries.", idTmp=identity(18) INTO #tmpTable FROM #tmpPaginate");
403+
return $this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primaries." WHERE #tmpTable.idTmp "
404+
. "BETWEEN ".($offset+1) ." AND ". ($offset+$limit)
405+
." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode());
406+
375407
}
376-
377-
//Offset operation
378-
$this->getPdo()->query(str_replace(" from ", " into #tmpPaginate from ", $this->compileNewQuery($query, $bindings)));
379-
$this->getPdo()->query("SELECT ".$res_primaries.", idTmp=identity(18) INTO #tmpTable FROM #tmpPaginate");
380-
return $this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primaries." WHERE #tmpTable.idTmp "
381-
. "BETWEEN ".($offset+1) ." AND ". ($offset+$limit)
382-
." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode());
383-
384-
}
385-
408+
}
386409
private function queryStringForIdentity($from)
387410
{
388411
$explicitDB = explode('..', $from);
@@ -425,13 +448,11 @@ public function select($query, $bindings = array(), $useReadPdo = true)
425448
if ($me->pretending()) {
426449
return array();
427450
}
428-
429451
if ($this->queryGrammar->getBuilder() != NULL) {
430452
$offset = $this->queryGrammar->getBuilder()->offset;
431453
} else {
432454
$offset = 0;
433455
}
434-
435456
if ($offset > 0) {
436457
return $this->compileOffset($offset, $query, $bindings, $me);
437458
} else {
@@ -445,6 +466,7 @@ public function select($query, $bindings = array(), $useReadPdo = true)
445466
});
446467
}
447468

469+
448470
/**
449471
* @param string $query
450472
* @param mixed array $bindings
@@ -471,4 +493,4 @@ public function affectingStatement($query, $bindings = array())
471493
return $this->getPdo()->query($this->compileNewQuery($query, $bindings))->rowCount();
472494
});
473495
}
474-
}
496+
}

0 commit comments

Comments
 (0)