Skip to content

Commit 9f961d6

Browse files
author
Gabriel Tadra Mainginski
committed
Probably fixed #4 and #5
1 parent 63986f0 commit 9f961d6

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

Database/SybaseConnection.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,35 +99,46 @@ private function compileForSelect(Builder $builder, $bindings) {
9999
if(count($bindings)==0){
100100
return [];
101101
}
102-
103102
$bindings = $this->prepareBindings($bindings);
104-
105103

106104
$arrTables = [];
107105
array_push($arrTables, $builder->from);
108-
//var_dump($builder);
106+
109107
if(!empty($builder->joins)){
110108
foreach($builder->joins as $join){
109+
111110
array_push($arrTables, $join->table);
112111
}
113112
}
114113
$new_format = [];
115114
foreach($arrTables as $tables){
116-
117-
$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."'");
118-
$types[$tables] = $queryRes->fetchAll(\PDO::FETCH_NAMED);
115+
preg_match("/(?:(?'table'.*)(?: as )(?'alias'.*))|(?'tables'.*)/", $tables, $alias);
116+
if(empty($alias['alias'])){
117+
$tables = $alias['tables'];
118+
}else{
119+
$tables = $alias['table'];
120+
}
119121

122+
$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."'");
123+
$types[$tables] = $queryRes->fetchAll(\PDO::FETCH_NAMED);
124+
120125
foreach ($types[$tables] as &$row) {
121-
$tipos[$row['name']] = $row['type'];
122-
$tipos[$tables.'.'.$row['name']] = $row['type'];
126+
$tipos[$row['name']] = $row['type'];
127+
$tipos[$tables.'.'.$row['name']] = $row['type'];
128+
if(!empty($alias['alias'])){
129+
$tipos[$alias['alias'].'.'.$row['name']] = $row['type'];
130+
}
123131
}
124132

125133
$new_format[$tables] = [];
126-
127134
}
128135
$wheres = (array)$builder->wheres;
129-
var_dump($wheres);
130136
for($ind = 0; $ind < count($wheres); $ind++ ){
137+
if(!isset($wheres[$ind]['value'])){
138+
$ind++;
139+
unset($wheres[$ind]);
140+
break;
141+
}
131142

132143
if(in_array(strtolower($tipos[$wheres[$ind]['column']]), $this->without_quotes)){
133144
$new_binds[$ind] = $bindings[$ind]/1;
@@ -169,14 +180,10 @@ private function compileBindings($query, $bindings)
169180
case "delete":
170181
preg_match("/(?'tables'.*) where (?'attributes'.*)/i" ,$query, $matches);
171182
break;
172-
default:
173-
return [];
174183
}
175184

176185
$desQuery = array_intersect_key($matches, array_flip(array_filter(array_keys($matches), 'is_string')));
177186

178-
179-
180187
if(is_array($desQuery['tables'])){
181188
$desQuery['tables'] = implode($desQuery['tables'], ' ');
182189
}
@@ -247,7 +254,6 @@ private function compileBindings($query, $bindings)
247254
// Detalhes: http://stackoverflow.com/questions/2718628/pdoparam-for-type-decimal
248255
private function compileNewQuery($query, $bindings)
249256
{
250-
$time_start = microtime(true);
251257
$newQuery = "";
252258
$bindings = $this->compileBindings($query, $bindings);
253259
$partQuery = explode("?", $query);
@@ -262,8 +268,6 @@ private function compileNewQuery($query, $bindings)
262268
}
263269
}
264270
}
265-
echo 'Total execution time in seconds: ' . (microtime(true) - $time_start).'<br>';
266-
var_dump($newQuery);
267271
return $newQuery;
268272
}
269273

0 commit comments

Comments
 (0)