@@ -117,7 +117,11 @@ private function compileForSelect(Builder $builder, $bindings) {
117
117
}
118
118
$ newFormat = [];
119
119
foreach ($ arrTables as $ tables ) {
120
- preg_match ("/(?:(?'table'.*)(?: as )(?'alias'.*))|(?'tables'.*)/ " , $ tables , $ alias );
120
+ preg_match (
121
+ "/(?:(?'table'.*)(?: as )(?'alias'.*))|(?'tables'.*)/ " ,
122
+ $ tables ,
123
+ $ alias
124
+ );
121
125
if (empty ($ alias ['alias ' ])) {
122
126
$ tables = $ alias ['tables ' ];
123
127
} else {
@@ -132,7 +136,9 @@ private function compileForSelect(Builder $builder, $bindings) {
132
136
$ tipos [strtolower ($ tables . '. ' . $ row ['name ' ])] = $ row ['type ' ];
133
137
134
138
if (!empty ($ alias ['alias ' ])) {
135
- $ tipos [strtolower ($ alias ['alias ' ] . '. ' . $ row ['name ' ])] = $ row ['type ' ];
139
+ $ tipos [
140
+ strtolower ($ alias ['alias ' ] . '. ' . $ row ['name ' ])
141
+ ] = $ row ['type ' ];
136
142
}
137
143
}
138
144
@@ -153,9 +159,19 @@ private function compileForSelect(Builder $builder, $bindings) {
153
159
$ wheresCount = count ($ wheres );
154
160
155
161
for ($ ind = 0 ; $ ind < $ wheresCount ; $ ind ++) {
156
- if (isset ($ wheres [$ ind ]['value ' ]) && isset ($ tipos [strtolower ($ wheres [$ ind ]['column ' ])])) {
162
+ if (
163
+ isset ($ wheres [$ ind ]['value ' ]) &&
164
+ isset ($ tipos [strtolower ($ wheres [$ ind ]['column ' ])])
165
+ ) {
157
166
if (is_object ($ wheres [$ ind ]['value ' ]) === false ) {
158
- if (in_array (strtolower ($ tipos [strtolower ($ wheres [$ ind ]['column ' ])]), $ this ->withoutQuotes )) {
167
+ if (
168
+ in_array (
169
+ strtolower ($ tipos [
170
+ strtolower ($ wheres [$ ind ]['column ' ])
171
+ ]),
172
+ $ this ->withoutQuotes
173
+ )
174
+ ) {
159
175
if (!is_null ($ bindings [$ i ])) {
160
176
$ newBinds [$ i ] = $ bindings [$ i ] / 1 ;
161
177
} else {
@@ -179,7 +195,14 @@ private function compileForSelect(Builder $builder, $bindings) {
179
195
for ($ ind = 0 ; $ ind < $ wheresCount ; $ ind ++) {
180
196
if (isset ($ wheres [$ ind ]['value ' ])) {
181
197
if (is_object ($ wheres [$ ind ]['value ' ]) === false ) {
182
- if (in_array (strtolower ($ tipos [strtolower ($ wheres [$ ind ]['column ' ])]), $ this ->withoutQuotes )) {
198
+ if (
199
+ in_array (
200
+ strtolower ($ tipos [
201
+ strtolower ($ wheres [$ ind ]['column ' ])
202
+ ]),
203
+ $ this ->withoutQuotes
204
+ )
205
+ ) {
183
206
if (!is_null ($ bindings [$ i ])) {
184
207
$ newBinds [$ i ] = $ bindings [$ i ] / 1 ;
185
208
} else {
@@ -277,20 +300,35 @@ private function compileBindings($query, $bindings)
277
300
return $ bindings ;
278
301
}
279
302
case "insert " :
280
- preg_match ("/(?'tables'.*) \((?'attributes'.*)\) values/i " , $ query , $ matches );
303
+ preg_match (
304
+ "/(?'tables'.*) \((?'attributes'.*)\) values/i " ,
305
+ $ query ,
306
+ $ matches
307
+ );
281
308
break ;
282
309
case "update " :
283
- preg_match ("/(?'tables'.*) set (?'attributes'.*)/i " , $ query , $ matches );
310
+ preg_match (
311
+ "/(?'tables'.*) set (?'attributes'.*)/i " ,
312
+ $ query ,
313
+ $ matches
314
+ );
284
315
break ;
285
316
case "delete " :
286
- preg_match ("/(?'tables'.*) where (?'attributes'.*)/i " , $ query , $ matches );
317
+ preg_match (
318
+ "/(?'tables'.*) where (?'attributes'.*)/i " ,
319
+ $ query ,
320
+ $ matches
321
+ );
287
322
break ;
288
323
default :
289
324
return $ bindings ;
290
325
break ;
291
326
}
292
327
293
- $ desQuery = array_intersect_key ($ matches , array_flip (array_filter (array_keys ($ matches ), 'is_string ' )));
328
+ $ desQuery = array_intersect_key (
329
+ $ matches ,
330
+ array_flip (array_filter (array_keys ($ matches ), 'is_string ' ))
331
+ );
294
332
295
333
if (is_array ($ desQuery ['tables ' ])) {
296
334
$ desQuery ['tables ' ] = implode ($ desQuery ['tables ' ], ' ' );
@@ -302,7 +340,11 @@ private function compileBindings($query, $bindings)
302
340
unset($ matches );
303
341
unset($ queryType );
304
342
preg_match_all ("/\[([^\]]*)\]/ " , $ desQuery ['attributes ' ], $ arrQuery );
305
- preg_match_all ("/\[([^\]]*)\]/ " , str_replace ("].[].[ " , '.. ' , $ desQuery ['tables ' ]), $ arrTables );
343
+ preg_match_all (
344
+ "/\[([^\]]*)\]/ " ,
345
+ str_replace ("].[].[ " , '.. ' , $ desQuery ['tables ' ]),
346
+ $ arrTables
347
+ );
306
348
307
349
$ arrQuery = $ arrQuery [1 ];
308
350
$ arrTables = $ arrTables [1 ];
@@ -323,10 +365,14 @@ private function compileBindings($query, $bindings)
323
365
$ table = $ campos ;
324
366
}
325
367
if (!array_key_exists ($ table , $ newFormat )) {
326
- $ queryRes = $ this ->getPdo ()->query ($ this ->queryStringForCompileBindings ($ table ));
368
+ $ queryRes = $ this ->getPdo ()->query (
369
+ $ this ->queryStringForCompileBindings ($ table )
370
+ );
327
371
$ types [$ table ] = $ queryRes ->fetchAll (\PDO ::FETCH_ASSOC );
328
372
for ($ k = 0 ; $ k < count ($ types [$ table ]); $ k ++) {
329
- $ types [$ table ][$ types [$ table ][$ k ]['name ' ]] = $ types [$ table ][$ k ];
373
+ $ types [$ table ][
374
+ $ types [$ table ][$ k ]['name ' ]
375
+ ] = $ types [$ table ][$ k ];
330
376
unset($ types [$ table ][$ k ]);
331
377
}
332
378
$ newFormat [$ table ] = [];
@@ -335,8 +381,18 @@ private function compileBindings($query, $bindings)
335
381
336
382
if (!$ itsTable ) {
337
383
if (count ($ bindings ) > $ ind ) {
338
- array_push ($ newFormat [$ table ], ['campo ' => $ campos , 'binding ' => $ ind ]);
339
- if (in_array (strtolower ($ types [$ table ][$ campos ]['type ' ]), $ this ->withoutQuotes )) {
384
+ array_push (
385
+ $ newFormat [$ table ], [
386
+ 'campo ' => $ campos ,
387
+ 'binding ' => $ ind
388
+ ]
389
+ );
390
+ if (
391
+ in_array (
392
+ strtolower ($ types [$ table ][$ campos ]['type ' ]),
393
+ $ this ->withoutQuotes
394
+ )
395
+ ) {
340
396
if (!is_null ($ bindings [$ ind ])) {
341
397
$ newBinds [$ ind ] = $ bindings [$ ind ] / 1 ;
342
398
} else {
@@ -413,9 +469,11 @@ private function queryStringForCompileBindings($table)
413
469
414
470
/**
415
471
* Set new bindings with specified column types to Sybase.
416
- * Poderia compilar novamente dos bindings usando os PDO::PARAM, porém, não tem nenhuma constante que lide
417
- * com decimais, logo, a única maneira seria colocando PDO::PARAM_STR, que colocaria plicas.
418
- * Detalhes: http://stackoverflow.com/questions/2718628/pdoparam-for-type-decimal
472
+ * Poderia compilar novamente dos bindings usando os PDO::PARAM, porém,
473
+ * não tem nenhuma constante que lide com decimais, logo, a única maneira
474
+ * seria colocando PDO::PARAM_STR, que colocaria plicas.
475
+ * Detalhes:
476
+ * http://stackoverflow.com/questions/2718628/pdoparam-for-type-decimal
419
477
*
420
478
* @param string $query
421
479
* @param array $bindings
@@ -453,22 +511,33 @@ public function compileOffset($offset, $query, $bindings = array(), $me)
453
511
$ limit = 999999999999999999999999999 ;
454
512
}
455
513
$ queryString = $ this ->queryStringForIdentity ($ from );
456
- $ identity = $ this ->getPdo ()->query ($ queryString )->fetchAll ($ me ->getFetchMode ())[0 ];
514
+ $ identity = $ this ->getPdo ()->query ($ queryString )->fetchAll (
515
+ $ me ->getFetchMode ()
516
+ )[0 ];
457
517
458
518
if (count ($ identity ) === 0 ) {
459
519
$ queryString = $ this ->queryStringForPrimaries ($ from );
460
- $ primaries = $ this ->getPdo ()->query ($ queryString )->fetchAll ($ me ->getFetchMode ());
520
+ $ primaries = $ this ->getPdo ()->query ($ queryString )->fetchAll (
521
+ $ me ->getFetchMode ()
522
+ );
461
523
foreach ($ primaries as $ primary ) {
462
- $ newArr [] = $ primary ->primary_key . '+0 AS ' . $ primary ->primary_key ;
463
- $ whereArr [] = "#tmpPaginate. " . $ primary ->primary_key . ' = #tmpTable. ' . $ primary ->primary_key ;
524
+ $ newArr [] = $ primary ->primary_key . '+0 AS ' .
525
+ $ primary ->primary_key ;
526
+ $ whereArr [] = "#tmpPaginate. " . $ primary ->primary_key .
527
+ ' = #tmpTable. ' . $ primary ->primary_key ;
464
528
}
465
529
$ resPrimaries = implode (', ' , $ newArr );
466
530
$ wherePrimaries = implode (' AND ' , $ whereArr );
467
531
} else {
468
532
$ resPrimaries = $ identity ->column . '+0 AS ' . $ identity ->column ;
469
- $ wherePrimaries = "#tmpPaginate. " . $ identity ->column . ' = #tmpTable. ' . $ identity ->column ;
533
+ $ wherePrimaries = "#tmpPaginate. " . $ identity ->column .
534
+ ' = #tmpTable. ' . $ identity ->column ;
470
535
// Offset operation
471
- $ this ->getPdo ()->query (str_replace (" from " , " into #tmpPaginate from " , $ this ->compileNewQuery ($ query , $ bindings )));
536
+ $ this ->getPdo ()->query (str_replace (
537
+ " from " ,
538
+ " into #tmpPaginate from " ,
539
+ $ this ->compileNewQuery ($ query , $ bindings )
540
+ ));
472
541
$ this ->getPdo ()->query ("
473
542
SELECT
474
543
" . $ resPrimaries . ",
@@ -569,7 +638,10 @@ private function queryStringForPrimaries($from)
569
638
*/
570
639
public function select ($ query , $ bindings = array (), $ useReadPdo = true )
571
640
{
572
- return $ this ->run ($ query , $ bindings , function ($ query , $ bindings ) use ($ useReadPdo ) {
641
+ return $ this ->run ($ query , $ bindings , function (
642
+ $ query ,
643
+ $ bindings
644
+ ) use ($ useReadPdo ) {
573
645
if ($ this ->pretending ()) {
574
646
return [];
575
647
}
@@ -584,7 +656,10 @@ public function select($query, $bindings = array(), $useReadPdo = true)
584
656
return $ this ->compileOffset ($ offset , $ query , $ bindings , $ this );
585
657
} else {
586
658
$ result = [];
587
- $ statement = $ this ->getPdo ()->query ($ this ->compileNewQuery ($ query , $ bindings ));
659
+ $ statement = $ this ->getPdo ()->query ($ this ->compileNewQuery (
660
+ $ query ,
661
+ $ bindings
662
+ ));
588
663
do {
589
664
$ result += $ statement ->fetchAll ($ this ->getFetchMode ());
590
665
} while ($ statement ->nextRowset ());
@@ -604,7 +679,10 @@ public function statement($query, $bindings = array())
604
679
if ($ this ->pretending ()) {
605
680
return true ;
606
681
}
607
- return $ this ->getPdo ()->query ($ this ->compileNewQuery ($ query , $ bindings ));
682
+ return $ this ->getPdo ()->query ($ this ->compileNewQuery (
683
+ $ query ,
684
+ $ bindings
685
+ ));
608
686
});
609
687
}
610
688
@@ -614,7 +692,10 @@ public function affectingStatement($query, $bindings = [])
614
692
if ($ this ->pretending ()) {
615
693
return 0 ;
616
694
}
617
- return $ this ->getPdo ()->query ($ this ->compileNewQuery ($ query , $ bindings ))->rowCount ();
695
+ return $ this ->getPdo ()->query ($ this ->compileNewQuery (
696
+ $ query ,
697
+ $ bindings
698
+ ))->rowCount ();
618
699
});
619
700
}
620
701
0 commit comments