@@ -116,53 +116,55 @@ private function compileBindings($query, $bindings)
116116 preg_match_all ("/(?:from |join )(?'tables'.*?)(?: (?:on(?:(?!join ).)*|)where(?'attributes'.*)| on|$)/i " ,$ query , $ matches );
117117 break ;
118118 case "insert " :
119- preg_match ("/(?'tables'.*) \(.* \) values/i " ,$ query , $ matches );
119+ preg_match ("/(?'tables'.*) \((?'attributes'.*) \) values/i " ,$ query , $ matches );
120120 break ;
121121 case "update " :
122- preg_match ("/(?'tables'.*) set/i " ,$ query , $ matches );
122+ preg_match ("/(?'tables'.*) set (?'attributes'.*) /i " ,$ query , $ matches );
123123 break ;
124124 case "delete " :
125- preg_match ("/(?'tables'.*) where/i " ,$ query , $ matches );
125+ preg_match ("/(?'tables'.*) where (?'attributes'.*) /i " ,$ query , $ matches );
126126 break ;
127127 }
128128
129129 $ desQuery = array_intersect_key ($ matches , array_flip (array_filter (array_keys ($ matches ), 'is_string ' )));
130130
131- if (is_array ($ desQuery ['tables ' ]) && is_array ( $ desQuery [ ' attributes ' ]) ){
131+ if (is_array ($ desQuery ['tables ' ])){
132132 $ desQuery ['tables ' ] = implode ($ desQuery ['tables ' ], ' ' );
133+ }
134+ if (is_array ($ desQuery ['attributes ' ])){
133135 $ desQuery ['attributes ' ] = implode ($ desQuery ['attributes ' ], ' ' );
134- }else {
135- $ desQuery ['attributes ' ] = $ query ;
136136 }
137137
138138 unset($ matches );
139139 unset($ query_type );
140-
141140 preg_match_all ("/\[([^\]]*)\]/ " , $ desQuery ['attributes ' ], $ arrQuery );
142- if (count ($ arrQuery [1 ]) == 0 ){
143- return $ bindings ;
144- }
145141 preg_match_all ("/\[([^\]]*)\]/ " , $ desQuery ['tables ' ], $ arrTables );
142+
146143 $ arrQuery = $ arrQuery [1 ];
147144 $ arrTables = $ arrTables [1 ];
148-
149145
150146 $ ind = 0 ;
151- foreach ($ arrQuery as $ campos ){
152-
153- if (in_array ($ campos , $ arrTables )) {//|| count($arrTables) == 1) && (isset($table) && $table != $arrTables)){
154- $ table = $ campos ;
155-
156- if (!array_key_exists ($ campos , $ new_format )){
157- $ 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) = ' " .$ campos ."' " );
158- $ types [$ campos ] = $ queryRes ->fetchAll (\PDO ::FETCH_ASSOC );
159- for ($ k = 0 ; $ k < count ($ types [$ campos ]); $ k ++){
160- $ types [$ campos ][$ types [$ campos ][$ k ]['name ' ]] = $ types [$ campos ][$ k ];
161- unset($ types [$ campos ][$ k ]);
147+ if (count ($ arrTables ) == 1 ){
148+ $ table = $ arrTables [0 ];
149+ }
150+
151+ foreach ($ arrQuery as $ key =>$ campos ){
152+ if (in_array ($ campos , $ arrTables ) || (count ($ arrTables ) == 1 && isset ($ table ) && $ key == 0 )){
153+ if (count ($ arrTables ) > 1 ){
154+ $ table = $ campos ;
155+ }
156+ if (!array_key_exists ($ table , $ new_format )){
157+ $ 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 ."' " );
158+ $ types [$ table ] = $ queryRes ->fetchAll (\PDO ::FETCH_ASSOC );
159+ for ($ k = 0 ; $ k < count ($ types [$ table ]); $ k ++){
160+ $ types [$ table ][$ types [$ table ][$ k ]['name ' ]] = $ types [$ table ][$ k ];
161+ unset($ types [$ table ][$ k ]);
162162 }
163- $ new_format [$ campos ] = [];
163+ $ new_format [$ table ] = [];
164164 }
165- }else {
165+ }
166+
167+ if (!in_array ($ campos , $ arrTables )){
166168 if (count ($ bindings )>$ ind ){
167169 array_push ($ new_format [$ table ], ['campo ' => $ campos , 'binding ' => $ ind ]);
168170 if (in_array (strtolower ($ types [$ table ][$ campos ]['type ' ]), $ this ->without_quotes )){
@@ -176,7 +178,6 @@ private function compileBindings($query, $bindings)
176178 $ ind ++;
177179 }
178180 }
179-
180181 return $ new_binds ;
181182 }
182183 /**
@@ -191,8 +192,9 @@ private function compileBindings($query, $bindings)
191192 // Detalhes: http://stackoverflow.com/questions/2718628/pdoparam-for-type-decimal
192193 private function compileNewQuery ($ query , $ bindings )
193194 {
195+
194196 $ bindings = $ this ->compileBindings ($ query , $ bindings );
195-
197+
196198 $ newQuery = "" ;
197199 $ partQuery = explode ("? " , $ query );
198200 for ($ i = 0 ; $ i <count ($ partQuery ); $ i ++){
0 commit comments