33 Author: Andrews54757
44 License: MIT (https://github.com/ThreeLetters/SuperSQL/blob/master/LICENSE)
55 Source: https://github.com/ThreeLetters/SQL-Library
6- Build: v1.0.0
6+ Build: v1.0.1
77 Built on: 09/08/2017
88*/
99
@@ -259,7 +259,7 @@ public static function DELETE($table, $where)
259259// lib/parser/Advanced.php
260260class AdvParser
261261{
262- private static function getArg (&$ str )
262+ static function getArg (&$ str )
263263 {
264264 if (substr ($ str , 0 , 1 ) == "[ " && substr ($ str , 3 , 1 ) == "] " ) {
265265 $ out = substr ($ str , 1 , 2 );
@@ -269,7 +269,7 @@ private static function getArg(&$str)
269269 return false ;
270270 }
271271 }
272- private static function append (&$ args , $ val , $ index , $ values )
272+ static function append (&$ args , $ val , $ index , $ values )
273273 {
274274 if (gettype ($ val ) == "array " && $ values [$ index ][2 ] < 5 ) {
275275 $ len = count ($ val );
@@ -280,7 +280,7 @@ private static function append(&$args, $val, $index, $values)
280280 }
281281 }
282282 }
283- private static function append2 (&$ insert , $ indexes , $ dt , $ values )
283+ static function append2 (&$ insert , $ indexes , $ dt , $ values )
284284 {
285285 function stripArgs (&$ key )
286286 {
@@ -356,7 +356,7 @@ function recurse(&$holder, $val, $indexes, $par, $values)
356356 recurse ($ insert [$ key ], $ val , $ indexes , "" , $ values );
357357 }
358358 }
359- private static function quote ($ str )
359+ static function quote ($ str )
360360 {
361361 $ str = explode (". " , $ str );
362362 $ out = "" ;
@@ -367,7 +367,7 @@ private static function quote($str)
367367 }
368368 return $ out ;
369369 }
370- private static function table ($ table )
370+ static function table ($ table )
371371 {
372372 if (gettype ($ table ) == "array " ) {
373373 $ sql = "" ;
@@ -384,7 +384,7 @@ private static function table($table)
384384 return self ::quote ($ table );
385385 }
386386 }
387- private static function value ($ type , $ value , &$ typeString )
387+ static function value ($ type , $ value , &$ typeString )
388388 {
389389 $ var = strtolower ($ type );
390390 if (!$ var )
@@ -432,7 +432,7 @@ private static function value($type, $value, &$typeString)
432432 $ dtype
433433 );
434434 }
435- private static function getType (&$ str )
435+ static function getType (&$ str )
436436 {
437437 if (substr ($ str , -1 ) == "] " ) {
438438 $ start = strrpos ($ str , "[ " );
@@ -445,14 +445,14 @@ private static function getType(&$str)
445445 } else
446446 return "" ;
447447 }
448- private static function rmComments ($ str ) {
448+ static function rmComments ($ str ) {
449449 $ i = strpos ($ str ,"# " );
450450 if ($ i !== false ) {
451451 $ str = substr ($ str ,0 ,$ i );
452452 }
453453 return trim ($ str );
454454 }
455- private static function conditions ($ dt , &$ values = false , &$ map = false , &$ typeString = "" , &$ index = 0 )
455+ static function conditions ($ dt , &$ values = false , &$ map = false , &$ typeString = "" , &$ index = 0 )
456456 {
457457 $ build = function (&$ build , $ dt , &$ map , &$ index , &$ values , &$ typeString , $ join = " AND " , $ operator = " = " , $ parent = "" )
458458 {
@@ -566,6 +566,37 @@ private static function conditions($dt, &$values = false, &$map = false, &$typeS
566566 };
567567 return $ build ($ build , $ dt , $ map , $ index , $ values , $ typeString );
568568 }
569+ static function JOIN ($ join , &$ sql ) {
570+ foreach ($ join as $ key => $ val ) {
571+ if (substr ($ key , 0 , 1 ) === "# " ) {
572+ $ raw = true ;
573+ $ key = substr ($ key , 1 );
574+ } else {
575+ $ raw = false ;
576+ }
577+ $ arg = self ::getArg ($ key );
578+ switch ($ arg ) {
579+ case "<< " :
580+ $ sql .= " RIGHT JOIN " ;
581+ break ;
582+ case ">> " :
583+ $ sql .= " LEFT JOIN " ;
584+ break ;
585+ case "<> " :
586+ $ sql .= " FULL JOIN " ;
587+ break ;
588+ default :
589+ $ sql .= " JOIN " ;
590+ break ;
591+ }
592+ $ sql .= self ::quote ($ key ) . " ON " ;
593+ if ($ raw ) {
594+ $ sql .= "val " ;
595+ } else {
596+ $ sql .= self ::conditions ($ val );
597+ }
598+ }
599+ }
569600 static function SELECT ($ table , $ columns , $ where , $ join , $ limit )
570601 {
571602 $ sql = "SELECT " ;
@@ -622,35 +653,7 @@ static function SELECT($table, $columns, $where, $join, $limit)
622653 }
623654 $ sql .= " FROM " . self ::table ($ table );
624655 if ($ join ) {
625- foreach ($ join as $ key => $ val ) {
626- if (substr ($ key , 0 , 1 ) === "# " ) {
627- $ raw = true ;
628- $ key = substr ($ key , 1 );
629- } else {
630- $ raw = false ;
631- }
632- $ arg = self ::getArg ($ key );
633- switch ($ arg ) {
634- case "<< " :
635- $ sql .= " RIGHT JOIN " ;
636- break ;
637- case ">> " :
638- $ sql .= " LEFT JOIN " ;
639- break ;
640- case "<> " :
641- $ sql .= " FULL JOIN " ;
642- break ;
643- default :
644- $ sql .= " JOIN " ;
645- break ;
646- }
647- $ sql .= self ::quote ($ key ) . " ON " ;
648- if ($ raw ) {
649- $ sql .= "val " ;
650- } else {
651- $ sql .= self ::conditions ($ val );
652- }
653- }
656+ self ::JOIN ($ join ,$ sql );
654657 }
655658 $ typeString = "" ;
656659 if (count ($ where ) != 0 ) {
0 commit comments