@@ -292,102 +292,99 @@ public function limit($numberOf, $offset = null)
292292 return 'LIMIT ' .$ rows .$ value ;
293293 }
294294
295- public function where ( ...$ whereKeyArray )
295+ public function where ( ...$ whereConditions )
296296 {
297- if (empty ($ whereKeyArray ))
297+ if (empty ($ whereConditions ))
298298 return false ;
299299
300300 $ whereOrHaving = ($ this ->isWhere ) ? 'WHERE ' : 'HAVING ' ;
301301 $ this ->isWhere = true ;
302302
303- $ whereKey = [];
303+ $ whereClause = [];
304304 $ operator = [];
305305 $ extra = [];
306306 $ combiner = [];
307307 $ combineWith = '' ;
308- if (\is_string ($ whereKeyArray [0 ])) {
309- if ((\strpos ($ whereKeyArray [0 ], 'WHERE ' ) !== false )
310- || (\strpos ($ whereKeyArray [0 ], 'HAVING ' ) !== false )
308+
309+ $ storeWhereConditions = $ whereConditions ;
310+ if (\is_string ($ whereConditions [0 ])) {
311+ if ((\strpos ($ whereConditions [0 ], 'WHERE ' ) !== false )
312+ || (\strpos ($ whereConditions [0 ], 'HAVING ' ) !== false )
311313 )
312- return $ whereKeyArray [0 ];
314+ return $ whereConditions [0 ];
313315
314- foreach ( $ whereKeyArray as $ makeArray )
315- $ whereKeys [] = \explode ( ' ' , $ makeArray );
316- } else
317- $ whereKeys = $ whereKeyArray ;
316+ $ storeWhereConditions = [];
317+ foreach ( $ whereConditions as $ makeWhereArray )
318+ $ storeWhereConditions [] = \explode ( ' ' , $ makeWhereArray );
319+ }
318320
319- foreach ($ whereKeys as $ values ) {
320- $ operator [] = (isset ($ values [1 ])) ? $ values [1 ]: '' ;
321- if (!empty ($ values [1 ])){
322- if (\strtoupper ($ values [1 ]) == 'IN ' ) {
323- $ whereKey [ $ values [0 ] ] = \array_slice ((array ) $ values , 2 );
324- $ combiner [] = (isset ($ values [3 ])) ? $ values [3 ]: \_AND ;
325- $ extra [] = (isset ($ values [4 ])) ? $ values [4 ]: null ;
326- } else {
327- $ whereKey [ (isset ($ values [0 ])) ? $ values [0 ] : '1 ' ] = (isset ($ values [2 ])) ? $ values [2 ] : '' ;
328- $ combiner [] = (isset ($ values [3 ])) ? $ values [3 ]: \_AND ;
329- $ extra [] = (isset ($ values [4 ])) ? $ values [4 ]: null ;
330- }
331- } else {
321+ foreach ($ storeWhereConditions as $ checkFields ) {
322+ $ operator [] = (isset ($ checkFields [1 ])) ? $ checkFields [1 ]: '' ;
323+ if (empty ($ checkFields [1 ]))
332324 return $ this ->clearPrepare ();
333- }
325+
326+ if (\strtoupper ($ checkFields [1 ]) == 'IN ' ) {
327+ $ whereClause [ $ checkFields [0 ] ] = \array_slice ((array ) $ checkFields , 2 );
328+ $ combiner [] = (isset ($ checkFields [3 ])) ? $ checkFields [3 ]: \_AND ;
329+ $ extra [] = (isset ($ checkFields [4 ])) ? $ checkFields [4 ]: null ;
330+ } else {
331+ $ whereClause [ (isset ($ checkFields [0 ])) ? $ checkFields [0 ] : '1 ' ] = (isset ($ checkFields [2 ])) ? $ checkFields [2 ] : '' ;
332+ $ combiner [] = (isset ($ checkFields [3 ])) ? $ checkFields [3 ]: \_AND ;
333+ $ extra [] = (isset ($ checkFields [4 ])) ? $ checkFields [4 ]: null ;
334+ }
334335 }
335336
336337 $ where = '1 ' ;
337- if (! isset ($ whereKey ['1 ' ])) {
338+ if (! isset ($ whereClause ['1 ' ])) {
338339 $ where = '' ;
339340 $ i = 0 ;
340- foreach ($ whereKey as $ key => $ val ) {
341+ foreach ($ whereClause as $ key => $ val ) {
341342 $ isCondition = \strtoupper ($ operator [$ i ]);
342343 $ combine = $ combiner [$ i ];
344+ $ combineWith = \_AND ;
343345 if ( \in_array (\strtoupper ($ combine ), \_COMBINERS ) || isset ($ extra [$ i ]))
344346 $ combineWith = (isset ($ extra [$ i ])) ? $ combine : \strtoupper ($ combine );
345- else
346- $ combineWith = \_AND ;
347347
348- if (! \in_array ( $ isCondition , \_BOOLEAN_OPERATORS )) {
348+ if (! \in_array ( $ isCondition , \_BOOLEAN_OPERATORS ))
349349 return $ this ->clearPrepare ();
350- } else {
351- if (($ isCondition == \_BETWEEN ) || ($ isCondition == \_notBETWEEN)) {
352- $ value = $ this ->escape ($ combineWith );
353- if (\in_array (\strtoupper ($ extra [$ i ]), \_COMBINERS ))
354- $ myCombineWith = \strtoupper ($ extra [$ i ]);
355- else
356- $ myCombineWith = \_AND ;
357350
358- if ($ this ->isPrepareOn ()) {
359- $ where .= "$ key " .$ isCondition .' ' .\_TAG ." AND " .\_TAG ." $ myCombineWith " ;
360- $ this ->addPrepare ($ val );
361- $ this ->addPrepare ($ combineWith );
362- } else
363- $ where .= "$ key " .$ isCondition ." ' " .$ this ->escape ($ val )."' AND ' " .$ value ."' $ myCombineWith " ;
351+ if (($ isCondition == \_BETWEEN ) || ($ isCondition == \_notBETWEEN)) {
352+ $ value = $ this ->escape ($ combineWith );
353+ $ myCombineWith = \_AND ;
354+ if (\in_array (\strtoupper ($ extra [$ i ]), \_COMBINERS ))
355+ $ myCombineWith = \strtoupper ($ extra [$ i ]);
356+
357+ if ($ this ->isPrepareOn ()) {
358+ $ where .= "$ key " .$ isCondition .' ' .\_TAG ." AND " .\_TAG ." $ myCombineWith " ;
359+ $ this ->addPrepare ($ val );
360+ $ this ->addPrepare ($ combineWith );
361+ } else
362+ $ where .= "$ key " .$ isCondition ." ' " .$ this ->escape ($ val )."' AND ' " .$ value ."' $ myCombineWith " ;
364363
365- $ combineWith = $ myCombineWith ;
366- } elseif ($ isCondition == \_IN ) {
367- $ value = '' ;
368- foreach ($ val as $ inValues ) {
369- if ($ this ->isPrepareOn ()) {
370- $ value .= \_TAG .', ' ;
371- $ this ->addPrepare ($ inValues );
372- } else
373- $ value .= "' " .$ this ->escape ($ inValues )."', " ;
374- }
375- $ where .= "$ key " .$ isCondition ." ( " .\rtrim ($ value , ', ' )." ) $ combineWith " ;
376- } elseif (((\strtolower ($ val ) == 'null ' ) || ($ isCondition == 'IS ' ) || ($ isCondition == 'IS NOT ' ))) {
377- $ isCondition = (($ isCondition == 'IS ' ) || ($ isCondition == 'IS NOT ' )) ? $ isCondition : 'IS ' ;
378- $ where .= "$ key " .$ isCondition ." NULL $ combineWith " ;
379- } elseif ((($ isCondition == \_LIKE ) || ($ isCondition == \_notLIKE)) && ! \preg_match ('/[_%?]/ ' , $ val )) {
380- return $ this ->clearPrepare ();
381- } else {
364+ $ combineWith = $ myCombineWith ;
365+ } elseif ($ isCondition == \_IN ) {
366+ $ value = '' ;
367+ foreach ($ val as $ inValues ) {
382368 if ($ this ->isPrepareOn ()) {
383- $ where .= " $ key " . $ isCondition . ' ' . \_TAG ." $ combineWith " ;
384- $ this ->addPrepare ($ val );
369+ $ value .= \_TAG .' , ' ;
370+ $ this ->addPrepare ($ inValues );
385371 } else
386- $ where .= "$ key " .$ isCondition ." ' " .$ this ->escape ($ val )."' $ combineWith " ;
387- }
388-
389- $ i ++;
390- }
372+ $ value .= "' " .$ this ->escape ($ inValues )."', " ;
373+ }
374+ $ where .= "$ key " .$ isCondition ." ( " .\rtrim ($ value , ', ' )." ) $ combineWith " ;
375+ } elseif (((\strtolower ($ val ) == 'null ' ) || ($ isCondition == 'IS ' ) || ($ isCondition == 'IS NOT ' ))) {
376+ $ isCondition = (($ isCondition == 'IS ' ) || ($ isCondition == 'IS NOT ' )) ? $ isCondition : 'IS ' ;
377+ $ where .= "$ key " .$ isCondition ." NULL $ combineWith " ;
378+ } elseif ((($ isCondition == \_LIKE ) || ($ isCondition == \_notLIKE)) && ! \preg_match ('/[_%?]/ ' , $ val )) {
379+ return $ this ->clearPrepare ();
380+ } else {
381+ if ($ this ->isPrepareOn ()) {
382+ $ where .= "$ key " .$ isCondition .' ' .\_TAG ." $ combineWith " ;
383+ $ this ->addPrepare ($ val );
384+ } else
385+ $ where .= "$ key " .$ isCondition ." ' " .$ this ->escape ($ val )."' $ combineWith " ;
386+ }
387+ $ i ++;
391388 }
392389 $ where = \rtrim ($ where , " $ combineWith " );
393390 }
@@ -507,15 +504,15 @@ public function unionAll(string $table = null, $columnFields = '*', ...$conditio
507504 return 'UNION ALL ' .$ this ->select_sql ($ table , $ columnFields , ...$ conditions );
508505 }
509506
510- public function create_select (string $ newTable , $ fromColumns , $ oldTable = null , ...$ fromWhere )
507+ public function create_select (string $ newTable , $ fromColumns , $ oldTable = null , ...$ conditions )
511508 {
512509 if (isset ($ oldTable ))
513510 $ this ->fromTable = $ oldTable ;
514511 else {
515512 return $ this ->clearPrepare ();
516513 }
517514
518- $ newTableFromTable = $ this ->select_sql ($ newTable , $ fromColumns , ...$ fromWhere );
515+ $ newTableFromTable = $ this ->select_sql ($ newTable , $ fromColumns , ...$ conditions );
519516 if (is_string ($ newTableFromTable ))
520517 return (($ this ->isPrepareOn ()) && !empty ($ this ->prepareValues ()))
521518 ? $ this ->query ($ newTableFromTable , true )
@@ -524,15 +521,15 @@ public function create_select(string $newTable, $fromColumns, $oldTable = null,
524521 return $ this ->clearPrepare ();
525522 }
526523
527- public function select_into (string $ newTable , $ fromColumns , $ oldTable = null , ...$ fromWhere )
524+ public function select_into (string $ newTable , $ fromColumns , $ oldTable = null , ...$ conditions )
528525 {
529526 $ this ->isInto = true ;
530527 if (isset ($ oldTable ))
531528 $ this ->fromTable = $ oldTable ;
532529 else
533530 return $ this ->clearPrepare ();
534531
535- $ newTableFromTable = $ this ->select_sql ($ newTable , $ fromColumns , ...$ fromWhere );
532+ $ newTableFromTable = $ this ->select_sql ($ newTable , $ fromColumns , ...$ conditions );
536533 if (is_string ($ newTableFromTable ))
537534 return (($ this ->isPrepareOn ()) && !empty ($ this ->prepareValues ()))
538535 ? $ this ->query ($ newTableFromTable , true )
@@ -541,7 +538,7 @@ public function select_into(string $newTable, $fromColumns, $oldTable = null, ..
541538 return $ this ->clearPrepare ();
542539 }
543540
544- public function update (string $ table = null , $ keyAndValue , ...$ whereKeys )
541+ public function update (string $ table = null , $ keyAndValue , ...$ whereConditions )
545542 {
546543 if ( ! is_array ( $ keyAndValue ) || empty ($ table ) ) {
547544 return $ this ->clearPrepare ();
@@ -563,7 +560,7 @@ public function update(string $table = null, $keyAndValue, ...$whereKeys)
563560 }
564561 }
565562
566- $ where = $ this ->where (...$ whereKeys );
563+ $ where = $ this ->where (...$ whereConditions );
567564 if (\is_string ($ where )) {
568565 $ sql = \rtrim ($ sql , ', ' ) . $ where ;
569566 return (($ this ->isPrepareOn ()) && !empty ($ this ->prepareValues ()))
@@ -574,15 +571,15 @@ public function update(string $table = null, $keyAndValue, ...$whereKeys)
574571 return $ this ->clearPrepare ();
575572 }
576573
577- public function delete (string $ table = null , ...$ whereKeys )
574+ public function delete (string $ table = null , ...$ whereConditions )
578575 {
579576 if ( empty ($ table ) ) {
580577 return $ this ->clearPrepare ();
581578 }
582579
583580 $ sql = "DELETE FROM $ table " ;
584581
585- $ where = $ this ->where (...$ whereKeys );
582+ $ where = $ this ->where (...$ whereConditions );
586583 if (\is_string ($ where )) {
587584 $ sql .= $ where ;
588585 return (($ this ->isPrepareOn ()) && !empty ($ this ->prepareValues ()))
@@ -664,10 +661,10 @@ public function insert(string $table = null, $keyAndValue)
664661 return $ this ->_query_insert_replace ($ table , $ keyAndValue , 'INSERT ' );
665662 }
666663
667- public function insert_select (string $ toTable = null , $ toColumns = '* ' , $ fromTable = null , $ fromColumns = '* ' , ...$ fromWhere )
664+ public function insert_select (string $ toTable = null , $ toColumns = '* ' , $ fromTable = null , $ fromColumns = '* ' , ...$ conditions )
668665 {
669666 $ putToTable = $ this ->_query_insert_replace ($ toTable , $ toColumns , 'INSERT ' , false );
670- $ getFromTable = $ this ->select_sql ($ fromTable , $ fromColumns , ...$ fromWhere );
667+ $ getFromTable = $ this ->select_sql ($ fromTable , $ fromColumns , ...$ conditions );
671668
672669 if (\is_string ($ putToTable ) && \is_string ($ getFromTable ))
673670 return (($ this ->isPrepareOn ()) && !empty ($ this ->prepareValues ()))
0 commit comments