diff --git a/Database/SybaseConnection.php b/Database/SybaseConnection.php index b0d7e08..846424d 100644 --- a/Database/SybaseConnection.php +++ b/Database/SybaseConnection.php @@ -120,58 +120,71 @@ private function compileForSelect(Builder $builder, $bindings) { } $queryString = $this->queryStringForSelect($tables); $queryRes = $this->getPdo()->query($queryString); - $types[$tables] = $queryRes->fetchAll(\PDO::FETCH_NAMED); + $types[$tables] = $queryRes->fetchAll(\PDO::FETCH_NAMED); foreach ($types[$tables] as &$row) { $tipos[strtolower($row['name'])] = $row['type']; $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; - } - } + } + } + + $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++ ){ + $wheresCount = count($wheres); + + for($ind = 0; $ind < $wheresCount; $ind++ ){ if(isset($wheres[$ind]['value']) && isset($tipos[strtolower($wheres[$ind]['column'])])){ - if(in_array(strtolower($tipos[strtolower($wheres[$ind]['column'])]), $this->without_quotes)){ - if(!is_null($bindings[$i])){ + if (is_object($wheres[$ind]['value']) === false) { + if(in_array(strtolower($tipos[strtolower($wheres[$ind]['column'])]), $this->without_quotes)){ + if(!is_null($bindings[$i])){ $new_binds[$i] = $bindings[$i]/1; - }else{ + }else{ $new_binds[$i] = null; + } + }else{ + $new_binds[$i] = (string)$bindings[$i]; } - }else{ - $new_binds[$i] = (string)$bindings[$i]; + $i++; } - $i++; } } $new_format[$tables] = []; } + $wheres = (array)$builder->wheres; $i = 0; - for ($ind = 0; $ind < count($wheres); $ind++ ) { + $wheresCount = count($wheres); + + for ($ind = 0; $ind < $wheresCount; $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; + if (is_object($wheres[$ind]['value']) === false) { + 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] = null; + $new_binds[$i] = (string)$bindings[$i]; } - } else { - $new_binds[$i] = (string)$bindings[$i]; + $i++; } - $i++; } } @@ -185,24 +198,24 @@ private function queryStringForSelect($tables) return <<compileBindings($query, $bindings); $partQuery = explode("?", $query); for ($i = 0; $iqueryGrammar->getBuilder()->limit; - $from = explode(" ", $this->queryGrammar->getBuilder()->from)[0]; + $from = explode(" ", $this->queryGrammar->getBuilder()->from)[0]; if (!isset($limit)) { $limit = 999999999999999999999999999; } @@ -401,11 +414,11 @@ public function compileOffset($offset, $query, $bindings = array(), $me) $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) + . "BETWEEN ".($offset+1) ." AND ". ($offset+$limit) ." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode()); - + } - } + } private function queryStringForIdentity($from) { $explicitDB = explode('..', $from); @@ -432,7 +445,7 @@ private function queryStringForPrimaries($from) WHERE i.id = c.id AND c.colid <= i.keycnt AND i.id = object_id('".$from."')"; } } - + /** * Run a select statement against the database. * @@ -455,9 +468,9 @@ public function select($query, $bindings = array(), $useReadPdo = true) } if ($offset > 0) { return $this->compileOffset($offset, $query, $bindings, $me); - } else { + } else { $result = []; - $statement = $this->getPdo()->query($this->compileNewQuery($query, $bindings)); + $statement = $this->getPdo()->query($this->compileNewQuery($query, $bindings)); do { $result+= $statement->fetchAll($me->getFetchMode()); } while ($statement->nextRowset()); @@ -467,7 +480,7 @@ public function select($query, $bindings = array(), $useReadPdo = true) } - /** + /** * @param string $query * @param mixed array $bindings * @return bool @@ -484,7 +497,7 @@ public function statement($query, $bindings = array()) } public function affectingStatement($query, $bindings = array()) - { + { return $this->run($query, $bindings, function($me, $query, $bindings) { if ($me->pretending()) {