Skip to content

Commit

Permalink
Merging dev in master
Browse files Browse the repository at this point in the history
  • Loading branch information
mainginski committed Jan 24, 2017
2 parents 208a2ce + 751bf6d commit fe8b367
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions Database/SybaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ private function compileForSelect(Builder $builder, $bindings) {
} else {
$tables = $alias['table'];
}

$queryString = $this->queryStringForSelect($tables);
$queryRes = $this->getPdo()->query($queryString);
$types[$tables] = $queryRes->fetchAll(\PDO::FETCH_NAMED);
Expand All @@ -128,6 +127,32 @@ private function compileForSelect(Builder $builder, $bindings) {
$tipos[strtolower($tables.'.'.$row['name'])] = $row['type'];
if (!empty($alias['alias'])) {
$tipos[strtolower($alias['alias'].'.'.$row['name'])] = $row['type'];
}
}
$wheres = [];
foreach($builder->wheres as $w){
switch($w['type']){
default:
array_push($wheres, $w);
break;
case "Nested":
$wheres += $w['query']->wheres;
break;
}
}
$i = 0;
for($ind = 0; $ind < count($wheres); $ind++ ){
if(isset($wheres[$ind]['value'])){
if(in_array(strtolower($tipos[strtolower($wheres[$ind]['column'])]), $this->without_quotes)){
if(!is_null($bindings[$i])){
$new_binds[$i] = $bindings[$i]/1;
}else{
$new_binds[$i] = null;
}
}else{
$new_binds[$i] = (string)$bindings[$i];
}
$i++;
}
}

Expand Down Expand Up @@ -372,17 +397,15 @@ public function compileOffset($offset, $query, $bindings = array(), $me)
} else {
$res_primaries = $identity->column.'+0 AS '.$identity->column;
$where_primaries = "#tmpPaginate.".$identity->column.' = #tmpTable.'.$identity->column;
//Offset operation
$this->getPdo()->query(str_replace(" from ", " into #tmpPaginate from ", $this->compileNewQuery($query, $bindings)));
$this->getPdo()->query("SELECT ".$res_primaries.", idTmp=identity(18) INTO #tmpTable FROM #tmpPaginate");
return $this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primaries." WHERE #tmpTable.idTmp "
. "BETWEEN ".($offset+1) ." AND ". ($offset+$limit)
." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode());

}

//Offset operation
$this->getPdo()->query(str_replace(" from ", " into #tmpPaginate from ", $this->compileNewQuery($query, $bindings)));
$this->getPdo()->query("SELECT ".$res_primaries.", idTmp=identity(18) INTO #tmpTable FROM #tmpPaginate");
return $this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primaries." WHERE #tmpTable.idTmp "
. "BETWEEN ".($offset+1) ." AND ". ($offset+$limit)
." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode());

}

}
private function queryStringForIdentity($from)
{
$explicitDB = explode('..', $from);
Expand Down Expand Up @@ -425,13 +448,11 @@ public function select($query, $bindings = array(), $useReadPdo = true)
if ($me->pretending()) {
return array();
}

if ($this->queryGrammar->getBuilder() != NULL) {
$offset = $this->queryGrammar->getBuilder()->offset;
} else {
$offset = 0;
}

if ($offset > 0) {
return $this->compileOffset($offset, $query, $bindings, $me);
} else {
Expand All @@ -445,6 +466,7 @@ public function select($query, $bindings = array(), $useReadPdo = true)
});
}


/**
* @param string $query
* @param mixed array $bindings
Expand All @@ -471,4 +493,4 @@ public function affectingStatement($query, $bindings = array())
return $this->getPdo()->query($this->compileNewQuery($query, $bindings))->rowCount();
});
}
}
}

0 comments on commit fe8b367

Please sign in to comment.