Skip to content

Commit 50273c0

Browse files
author
Gabriel Tadra Mainginski
committed
Trying to solve #5, for now, without success
1 parent cd400c3 commit 50273c0

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

Database/SybaseConnection.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,14 @@ protected function getDoctrineDriver()
103103
*/
104104
private function compileBindings($query, $bindings)
105105
{
106-
if(count($bindings)<=0){
106+
if(count($bindings)==0){
107107
return [];
108108
}
109109

110110
$bindings = $this->prepareBindings($bindings);
111111
$new_format = [];
112112

113-
$query_type = explode(' ', $query);
114-
switch($query_type[0]){
113+
switch(explode(' ', $query)[0]){
115114
case "select":
116115
preg_match_all("/(?:from |join )(?'tables'.*?)(?: (?:on(?:(?!join ).)*|)where(?'attributes'.*)| on|$)/i" ,$query, $matches);
117116
break;
@@ -126,17 +125,20 @@ private function compileBindings($query, $bindings)
126125
break;
127126
}
128127

129-
$desQuery = array_intersect_key($matches, array_flip(array_filter(array_keys($matches), 'is_string')));
130-
131-
if(is_array($desQuery['tables'])){
132-
$desQuery['tables'] = implode($desQuery['tables'], ' ');
128+
129+
if(is_array($matches['tables'])){
130+
$desQuery['tables'] = implode($matches['tables'], ' ');
131+
}else if(isset($matches['tables'])){
132+
$desQuery['tables'] = $matches['tables'];
133133
}
134-
if(is_array($desQuery['attributes'])){
135-
$desQuery['attributes'] = implode($desQuery['attributes'], ' ');
134+
135+
if(is_array($matches['attributes'])){
136+
$desQuery['attributes'] = implode($matches['attributes'], ' ');
137+
}else if(isset($matches['attributes'])){
138+
$desQuery['attributes'] = $matches['attributes'];
136139
}
137140

138141
unset($matches);
139-
unset($query_type);
140142
preg_match_all("/\[([^\]]*)\]/", $desQuery['attributes'], $arrQuery);
141143
preg_match_all("/\[([^\]]*)\]/", $desQuery['tables'], $arrTables);
142144

@@ -145,31 +147,28 @@ private function compileBindings($query, $bindings)
145147
$ind = 0;
146148
$numTables = count($arrTables);
147149

148-
if($numTables == 1){
149-
$table = $arrTables[0];
150-
}else if($numTables == 0){
150+
if($numTables == 0){
151151
return $bindings;
152152
}
153153

154-
foreach($arrQuery as $key=>$campos){
155-
$itsTable = in_array($campos, $arrTables);
156-
157-
if($itsTable || ($numTables == 1 && isset($table) && $key == 0)){
158-
if($numTables > 1){
159-
$table = $campos;
160-
}
161-
if(!array_key_exists($table, $new_format)){
162-
$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) = '".$table."'");
163-
$types[$table] = $queryRes->fetchAll(\PDO::FETCH_ASSOC);
164-
for($k = 0; $k < count($types[$table]); $k++){
165-
$types[$table][$types[$table][$k]['name']] = $types[$table][$k];
166-
unset($types[$table][$k]);
167-
}
168-
$new_format[$table] = [];
154+
foreach($arrTables as $tables){
155+
$table = $tables;
156+
157+
if(!array_key_exists($table, $new_format)){
158+
$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."'");
159+
$types[$tables] = $queryRes->fetchAll(\PDO::FETCH_NAMED);
160+
foreach ($types[$tables] as &$row) {
161+
$types[$tables][$row['name']] = &$row;
169162
}
163+
164+
$new_format[$tables] = [];
170165
}
171-
172-
if(!$itsTable){
166+
}
167+
168+
foreach($arrQuery as $campos){
169+
if(in_array($campos, $arrTables)){
170+
if($campos!=$table) $table = $campos;
171+
}else{
173172
if(count($bindings)>$ind){
174173
array_push($new_format[$table], ['campo' => $campos, 'binding' => $ind]);
175174
if(in_array(strtolower($types[$table][$campos]['type']), $this->without_quotes)){
@@ -183,7 +182,6 @@ private function compileBindings($query, $bindings)
183182
$ind++;
184183
}
185184
}
186-
187185
return $new_binds;
188186
}
189187
/**
@@ -198,6 +196,7 @@ private function compileBindings($query, $bindings)
198196
// Detalhes: http://stackoverflow.com/questions/2718628/pdoparam-for-type-decimal
199197
private function compileNewQuery($query, $bindings)
200198
{
199+
$time_start = microtime(true);
201200
$bindings = $this->compileBindings($query, $bindings);
202201

203202
$newQuery = "";
@@ -213,6 +212,7 @@ private function compileNewQuery($query, $bindings)
213212
}
214213
}
215214
}
215+
echo 'Total execution time in seconds: ' . (microtime(true) - $time_start).'<br>';
216216
return $newQuery;
217217
}
218218

0 commit comments

Comments
 (0)