1010// lib/connector/index.php
1111class Response{public $ result ;public $ affected ;public $ ind ;public $ error ;public $ errorData ;function __construct ($ a ,$ b ,$ c ){$ this ->error =!$ b ;if (!$ b ){$ this ->errorData =$ a ->errorInfo ();}else {$ d =$ a ->fetchAll ();$ this ->result =$ d ;if (count ($ c )!=0 ){foreach ($ d as $ e =>$ f ){foreach ($ c as $ g =>$ h ){if (isset ($ f [$ g ])){switch ($ h ){case "int " :$ this ->result [$ e ][$ g ]=(int )$ f [$ g ];break ;case "string " :$ this ->result [$ e ][$ g ]=(string )$ f [$ g ];break ;case "bool " :$ this ->result [$ e ][$ g ]=$ f [$ g ]? true : false ;break ;case "json " :$ this ->result [$ e ][$ g ]=json_decode ($ f [$ g ]);break ;case "obj " :$ this ->result [$ e ][$ g ]=unserialize ($ f [$ g ]);break ;}}}}}$ this ->affected =$ a ->rowCount ();}$ this ->ind =0 ;$ a ->closeCursor ();}function error (){return $ this ->error ?$ this ->errorData : false ;}function getData (){return $ this ->result ;}function getAffected (){return $ this ->affected ;}function next (){return $ this ->result [$ this ->ind ++];}function reset (){$ this ->ind =0 ;}}class Connector{public $ queries =array ();public $ db ;public $ log =array ();public $ dev =false ;function __construct ($ i ,$ j ,$ k ){$ this ->db =new \PDO ($ i ,$ j ,$ k );$ this ->log =array ();}function query ($ l ,$ m =null ,$ c =array ()){if (isset ($ this ->queries [$ l ])){$ n =$ this ->queries [$ l ];}else {$ n =$ this ->db ->prepare ($ l );$ this ->queries [$ l ]=$ n ;}if ($ m )$ o =$ n ->execute ($ m );else $ o =$ n ->execute ();if ($ this ->dev )array_push ($ this ->log ,array ($ l ,$ m ));return new Response ($ n ,$ o ,$ c );}function _query ($ p ,$ q ,$ r ,$ s ,$ c =array ()){if (isset ($ this ->queries [$ p ."| " .$ s ])){$ t =$ this ->queries [$ p ."| " .$ s ];$ n =$ t [1 ];$ u =&$ t [0 ];foreach ($ q as $ v =>$ w ){$ u [$ v ][0 ]=$ w [0 ];}if ($ this ->dev )array_push ($ this ->log ,array ("fromcache " ,$ p ,$ s ,$ q ,$ r ));}else {$ n =$ this ->db ->prepare ($ p );$ u =$ q ;foreach ($ u as $ v =>&$ x ){$ n ->bindParam ($ v +1 ,$ x [0 ],$ x [1 ]);}$ this ->queries [$ p ."| " .$ s ]=array (&$ u ,$ n );if ($ this ->dev )array_push ($ this ->log ,array ($ p ,$ s ,$ q ,$ r ));}if (count ($ r )==0 ){$ o =$ n ->execute ();return new Response ($ n ,$ o ,$ c );}else {$ y =array ();$ o =$ n ->execute ();array_push ($ y ,new Response ($ n ,$ o ,$ c ));foreach ($ r as $ v =>$ z ){foreach ($ z as $ aa =>$ ba ){$ u [$ aa ][0 ]=$ ba ;}$ o =$ n ->execute ();array_push ($ y ,new Response ($ n ,$ o ,$ c ));}return $ y ;}}function close (){$ this ->db =null ;$ this ->queries =null ;}function clearCache (){$ this ->queries =array ();}}
1212// lib/parser/Advanced.php
13- class AdvParser{private static function getArg (&$ a ){if (substr ($ a ,0 ,1 )=="[ " &&substr ($ a ,3 ,1 )=="] " ){$ b =substr ($ a ,1 ,2 );$ a =substr ($ a ,4 );return $ b ;}else {return false ;}}private static function append (&$ c ,$ d ,$ e ,$ f ){if (gettype ($ d )=="array " &&$ f [$ e ][2 ]<5 ){$ g =count ($ d );for ($ h =1 ;$ h <$ g ;$ h ++){if (!isset ($ c [$ h ]))$ c [$ h ]=array ();$ c [$ h ][$ e ]=$ d [$ h ];}}}private static function append2 (&$ i ,$ j ,$ k ,$ f ){function stripArgs (&$ l ){if (substr ($ l ,-1 )=="] " ){$ m =strrpos ($ l ,"[ " ,-1 );$ l =substr ($ l ,0 ,$ m );}$ m =strrpos ($ l ,"] " ,-1 );if ($ m !==false )$ l =substr ($ l ,$ m +1 );if (substr ($ l ,0 ,1 )==="# " ){$ l =substr ($ l ,1 );}}function escape ($ d ,$ k ){if (!isset ($ k [2 ]))return $ d ;switch ($ k [2 ]){case 0 : return $ d ? "1 " : "0 " ;break ;case 1 : return (int )$ d ;break ;case 2 : return (string )$ d ;break ;case 3 : return $ d ;break ;case 4 : return null ;break ;case 5 : return json_encode ($ d );break ;case 6 : return serialize ($ d );break ;}}function recurse (&$ n ,$ d ,$ j ,$ o ,$ f ){foreach ($ d as $ h =>$ p ){stripArgs ($ h );$ q =$ h ."# " .$ o ;if (isset ($ j [$ q ]))$ r =$ j [$ q ];else $ r =$ j [$ h ];$ s =gettype ($ p )=="array " &&(!isset ($ f [$ r ][2 ])||$ f [$ r ][2 ]<5 );if ($ s ){if (isset ($ p [0 ])){foreach ($ p as $ t =>$ u ){$ v =$ r +$ t ;if (isset ($ n [$ v ]))echo "SUPERSQL WARN: Key collision: " .$ h ;$ n [$ v ]=escape ($ u ,$ f [$ v ]);}}else {recurse ($ n ,$ p ,$ j ,$ o ."/ " .$ h ,$ f );}}else {if (isset ($ n [$ r ]))echo "SUPERSQL WARN: Key collision: " .$ h ;$ n [$ r ]=escape ($ p ,$ f [$ r ]);}}}$ g =count ($ k );for ($ l =1 ;$ l <$ g ;$ l ++){$ d =$ k [$ l ];if (!isset ($ i [$ l ]))$ i [$ l ]=array ();recurse ($ i [$ l ],$ d ,$ j ,"" ,$ f );}}private static function quote ($ a ){$ a =explode (". " ,$ a );$ b ="" ;for ($ t =0 ;$ t <count ($ a );$ t ++){if ($ t !=0 )$ b .=". " ;$ b .="` " .$ a [$ t ]."` " ;}return $ b ;}private static function table ($ w ){if (gettype ($ w )=="array " ){$ x ="" ;for ($ t =0 ;$ t <count ($ w );$ t ++){$ y =self ::getType ($ w [$ t ]);if ($ t !=0 )$ x .=", " ;$ x .=self ::quote ($ w [$ t ]);if ($ y )$ x .=" AS " .self ::quote ($ y );}return $ x ;}else {return self ::quote ($ w );}}private static function value ($ z ,$ aa ,&$ ba ){$ ca =strtolower ($ z );if (!$ ca )$ ca =strtolower (gettype ($ aa ));$ z =\PDO ::PARAM_STR ;$ da =2 ;if ($ ca =="boolean " ||$ ca =="bool " ){$ z =\PDO ::PARAM_BOOL ;$ aa =$ aa ? "1 " : "0 " ;$ da =0 ;$ ba .="b " ;}else if ($ ca =="integer " ||$ ca =="int " ||$ ca =="double " ||$ ca =="doub " ){$ ba .="i " ;$ da =1 ;$ aa =(int )$ aa ;}else if ($ ca =="string " ||$ ca =="str " ){$ z =\PDO ::PARAM_STR ;$ aa =(string )$ aa ;$ da =2 ;$ ba .="s " ;}else if ($ ca =="resource " ||$ ca =="lob " ){$ z =\PDO ::PARAM_LOB ;$ da =3 ;$ ba .="l " ;}else if ($ ca =="null " ){$ da =4 ;$ z =\PDO ::PARAM_NULL ;$ aa =null ;$ ba .="n " ;}else if ($ ca =="json " ){$ da =5 ;$ z =\PDO ::PARAM_STR ;$ aa =json_encode ($ aa );}else if ($ ca =="obj " ){$ da =6 ;$ z =\PDO ::PARAM_STR ;$ aa =serialize ($ aa );}else {$ aa =(string )$ aa ;echo "SUPERSQL WARN: Invalid type " .$ ca ." Assumed STRING " ;}return array ($ aa ,$ z ,$ da );}private static function getType (&$ a ){if (substr ($ a ,-1 )=="] " ){$ ea =strrpos ($ a ,"[ " );if ($ ea ===false ){return "" ;}$ b =substr ($ a ,$ ea +1 ,-1 );$ a =substr ($ a ,0 ,$ ea );return $ b ;}else return "" ;}private static function rmComments ($ a ){$ t =strpos ($ a ,"# " );if ($ t !==false ){$ a =substr ($ a ,0 ,$ t );}return trim ($ a );}private static function conditions ($ k ,&$ f =false ,&$ fa =false ,&$ ba ="" ,&$ e =0 ){$ ga =function (&$ ga ,$ k ,&$ fa ,&$ e ,&$ f ,&$ ba ,$ ha =" AND " ,$ ia =" = " ,$ ja ="" ){$ ka =0 ;$ x ="" ;foreach ($ k as $ l =>$ d ){if (substr ($ l ,0 ,1 )==="# " ){$ la =true ;$ l =substr ($ l ,1 );}else {$ la =false ;}$ ma =self ::getArg ($ l );$ na =$ ma ? self ::getArg ($ l ): false ;$ oa =gettype ($ d );$ pa =!isset ($ d [0 ]);$ qa =$ ha ;$ ra =$ ia ;$ z =$ la ? false : self ::getType ($ l );$ sa =self ::quote (self ::rmComments ($ l ));switch ($ ma ){case "|| " :$ ma =$ na ;$ qa =" OR " ;break ;case "&& " :$ ma =$ na ;$ qa =" AND " ;break ;}switch ($ ma ){case ">> " :$ ra =" > " ;break ;case "<< " :$ ra =" < " ;break ;case ">= " :$ ra =" >= " ;break ;case "<= " :$ ra =" <= " ;break ;case "!= " :$ ra =" != " ;break ;case "~~ " :$ ra =" LIKE " ;break ;case "!~ " :$ ra =" NOT LIKE " ;break ;default : if (!$ pa ||$ ma =="== " )$ ra =" = " ;break ;}if ($ ka !=0 )$ x .=$ ha ;if ($ oa =="array " &&$ z !="json " &&$ z !="obj " ){if ($ pa ){$ x .="( " .$ ga ($ ga ,$ d ,$ fa ,$ e ,$ f ,$ qa ,$ ra ,$ ja ."/ " .$ l ).") " ;}else {if ($ fa !==false &&!$ la ){$ fa [$ l ]=$ e ;$ fa [$ l ."# " .$ ja ]=$ e ++;}foreach ($ aa as $ h =>$ p ){if ($ h !=0 )$ x .=$ qa ;$ e ++;$ x .=$ sa .$ ra ;if ($ la ){$ x .=$ p ;}else if ($ f !==false ){$ x .="? " ;array_push ($ f ,self ::value ($ z ,$ p ,$ ba ));}else {if (gettype ($ p )=="integer " ){$ x .=$ p ;}else {$ x .=self ::quote ($ p );}}}}}else {$ x .=$ sa .$ ra ;if ($ la ){$ x .=$ d ;}else {if ($ f !==false ){$ x .="? " ;array_push ($ f ,self ::value ($ z ,$ d ,$ ba ));}else {if (gettype ($ d )=="integer " ){$ x .=$ d ;}else {$ x .=self ::quote ($ d );}}if ($ fa !==false ){$ fa [$ l ]=$ e ;$ fa [$ l ."# " .$ ja ]=$ e ++;}}}return $ x ;}$ ka ++;};return $ ga ($ ga ,$ k ,$ fa ,$ e ,$ f ,$ ba );}static function SELECT ($ w ,$ ta ,$ ua ,$ ha ,$ va ){$ x ="SELECT " ;$ g =count ($ ta );$ f =array ();$ i =array ();$ wa =array ();if ($ g ==0 ){$ x .="* " ;}else {$ t =0 ;$ xa =0 ;$ ya ="" ;if ($ ta [0 ]=="DISTINCT " ){$ t =1 ;$ xa =1 ;$ x .="DISTINCT " ;}else if (substr ($ ta [0 ],0 ,11 )=="INSERT INTO " ){$ t =1 ;$ xa =1 ;$ x =$ ta [0 ]." " .$ x ;}else if (substr ($ ta [0 ],0 ,4 )=="INTO " ){$ t =1 ;$ xa =1 ;$ ya =" " .$ ta [0 ]." " ;}if ($ g >$ xa ){for (;$ t <$ g ;$ t ++){$ m =self ::getType ($ ta [$ t ]);$ y =$ m ? self ::getType ($ ta [$ t ]): false ;if (!$ y &&$ m ){if (!($ m =="int " ||$ m =="string " ||$ m =="json " ||$ m =="obj " ||$ m =="bool " )){$ y =$ m ;$ m =false ;}}if ($ m ){if ($ y ){$ wa [$ y ]=$ m ;}else {$ wa [$ ta [$ t ]]=$ m ;}}if ($ t >$ xa ){$ x .=", " ;}$ x .=self ::quote ($ ta [$ t ]);if ($ y )$ x .=" AS ` " .$ y ."` " ;}}else $ x .="* " ;$ x .=$ ya ;}$ x .=" FROM " .self ::table ($ w );if ($ ha ){foreach ($ ha as $ l =>$ d ){if (substr ($ l ,0 ,1 )==="# " ){$ la =true ;$ l =substr ($ l ,1 );}else {$ la =false ;}$ ma =self ::getArg ($ l );switch ($ ma ){case "<< " :$ x .=" RIGHT JOIN " ;break ;case ">> " :$ x .=" LEFT JOIN " ;break ;case "<> " :$ x .=" FULL JOIN " ;break ;default :$ x .=" JOIN " ;break ;}$ x .=self ::quote ($ l )." ON " ;if ($ la ){$ x .="val " ;}else {$ x .=self ::conditions ($ d );}}}$ ba ="" ;if (count ($ ua )!=0 ){$ x .=" WHERE " ;$ e =array ();if (isset ($ ua [0 ])){$ x .=self ::conditions ($ ua [0 ],$ f ,$ e ,$ ba );self ::append2 ($ i ,$ e ,$ ua ,$ f );}else {$ x .=self ::conditions ($ ua ,$ f ,$ e ,$ ba );}}if ($ va ){if (gettype ($ va )=="integer " ){$ x .=" LIMIT " .$ va ;}else if (gettype ($ va )=="string " ){$ x .=" " .$ va ;}}return array ($ x ,$ f ,$ i ,$ ba ,$ wa );}static function INSERT ($ w ,$ za ){$ x ="INSERT INTO " .self ::table ($ w )." ( " ;$ f =array ();$ i =array ();$ ba ="" ;$ ab ="" ;$ t =0 ;$ m =0 ;$ j =array ();$ bb =isset ($ za [0 ]);$ k =$ bb ?$ za [0 ]:$ za ;foreach ($ k as $ l =>$ d ){if (substr ($ l ,0 ,1 )==="# " ){$ la =true ;$ l =substr ($ l ,1 );}else {$ la =false ;}if ($ m !=0 ){$ x .=", " ;$ ab .=", " ;}$ z =self ::getType ($ l );$ x .="` " .self ::rmComments ($ l )."` " ;if ($ la ){$ ab .=$ d ;}else {$ ab .="? " ;array_push ($ f ,self ::value ($ z ,$ d ,$ ba ));if ($ bb ){$ j [$ l ]=$ t ++;}else {self ::append ($ i ,$ d ,$ t ++,$ f );}}$ m ++;}if ($ bb )self ::append2 ($ i ,$ j ,$ za ,$ f );$ x .=") VALUES ( " .$ ab .") " ;return array ($ x ,$ f ,$ i ,$ ba );}static function UPDATE ($ w ,$ za ,$ ua ){$ x ="UPDATE " .self ::table ($ w )." SET " ;$ f =array ();$ i =array ();$ ba ="" ;$ t =0 ;$ m =0 ;$ j =array ();$ bb =isset ($ za [0 ]);$ k =$ bb ?$ za [0 ]:$ za ;foreach ($ k as $ l =>$ d ){if (substr ($ l ,0 ,1 )==="# " ){$ la =true ;$ l =substr ($ l ,1 );}else {$ la =false ;}if ($ m !=0 ){$ x .=", " ;}if ($ la ){$ x .="` " .$ l ."` = " .$ d ;}else {$ ma =self ::getArg ($ l );$ x .="` " .$ l ."` = " ;switch ($ ma ){case "+= " :$ x .="` " .$ l ."` + ? " ;break ;case "-= " :$ x .="` " .$ l ."` - ? " ;break ;case "/= " :$ x .="` " .$ l ."` / ? " ;break ;case "*= " :$ x .="` " .$ l ."` * ? " ;break ;default :$ x .="? " ;break ;}$ z =self ::getType ($ l );array_push ($ f ,self ::value ($ z ,$ d ,$ ba ));if ($ bb ){$ j [$ l ]=$ t ++;}else {self ::append ($ i ,$ d ,$ t ++,$ f );}}$ m ++;}if ($ bb )self ::append2 ($ i ,$ j ,$ za ,$ f );if (count ($ ua )!=0 ){$ x .=" WHERE " ;$ e =array ();if (isset ($ ua [0 ])){$ x .=self ::conditions ($ ua [0 ],$ f ,$ e ,$ ba ,$ t );self ::append2 ($ i ,$ e ,$ ua ,$ f );}else {$ x .=self ::conditions ($ ua ,$ f ,$ e ,$ ba ,$ t );}}return array ($ x ,$ f ,$ i ,$ ba );}static function DELETE ($ w ,$ ua ){$ x ="DELETE FROM " .self ::table ($ w );$ f =array ();$ i =array ();$ ba ="" ;if (count ($ ua )!=0 ){$ x .=" WHERE " ;$ e =array ();if (isset ($ ua [0 ])){$ x .=self ::conditions ($ ua [0 ],$ f ,$ e ,$ ba );self ::append2 ($ i ,$ e ,$ ua ,$ f );}else {$ x .=self ::conditions ($ ua ,$ f ,$ e ,$ ba );}}return array ($ x ,$ f ,$ i ,$ ba );}}
13+ class AdvParser{private static function getArg (&$ a ){if (substr ($ a ,0 ,1 )=="[ " &&substr ($ a ,3 ,1 )=="] " ){$ b =substr ($ a ,1 ,2 );$ a =substr ($ a ,4 );return $ b ;}else {return false ;}}private static function append (&$ c ,$ d ,$ e ,$ f ){if (gettype ($ d )=="array " &&$ f [$ e ][2 ]<5 ){$ g =count ($ d );for ($ h =1 ;$ h <$ g ;$ h ++){if (!isset ($ c [$ h ]))$ c [$ h ]=array ();$ c [$ h ][$ e ]=$ d [$ h ];}}}private static function append2 (&$ i ,$ j ,$ k ,$ f ){function stripArgs (&$ l ){if (substr ($ l ,-1 )=="] " ){$ m =strrpos ($ l ,"[ " ,-1 );$ l =substr ($ l ,0 ,$ m );}$ m =strrpos ($ l ,"] " ,-1 );if ($ m !==false )$ l =substr ($ l ,$ m +1 );if (substr ($ l ,0 ,1 )==="# " ){$ l =substr ($ l ,1 );}}function escape ($ d ,$ k ){if (!isset ($ k [2 ]))return $ d ;switch ($ k [2 ]){case 0 : return $ d ? "1 " : "0 " ;break ;case 1 : return (int )$ d ;break ;case 2 : return (string )$ d ;break ;case 3 : return $ d ;break ;case 4 : return null ;break ;case 5 : return json_encode ($ d );break ;case 6 : return serialize ($ d );break ;}}function recurse (&$ n ,$ d ,$ j ,$ o ,$ f ){foreach ($ d as $ h =>$ p ){stripArgs ($ h );$ q =$ h ."# " .$ o ;if (isset ($ j [$ q ]))$ r =$ j [$ q ];else $ r =$ j [$ h ];$ s =gettype ($ p )=="array " &&(!isset ($ f [$ r ][2 ])||$ f [$ r ][2 ]<5 );if ($ s ){if (isset ($ p [0 ])){foreach ($ p as $ t =>$ u ){$ v =$ r +$ t ;if (isset ($ n [$ v ]))echo "SUPERSQL WARN: Key collision: " .$ h ;$ n [$ v ]=escape ($ u ,$ f [$ v ]);}}else {recurse ($ n ,$ p ,$ j ,$ o ."/ " .$ h ,$ f );}}else {if (isset ($ n [$ r ]))echo "SUPERSQL WARN: Key collision: " .$ h ;$ n [$ r ]=escape ($ p ,$ f [$ r ]);}}}$ g =count ($ k );for ($ l =1 ;$ l <$ g ;$ l ++){$ d =$ k [$ l ];if (!isset ($ i [$ l ]))$ i [$ l ]=array ();recurse ($ i [$ l ],$ d ,$ j ,"" ,$ f );}}private static function quote ($ a ){$ a =explode (". " ,$ a );$ b ="" ;for ($ t =0 ;$ t <count ($ a );$ t ++){if ($ t !=0 )$ b .=". " ;$ b .="` " .$ a [$ t ]."` " ;}return $ b ;}private static function table ($ w ){if (gettype ($ w )=="array " ){$ x ="" ;for ($ t =0 ;$ t <count ($ w );$ t ++){$ y =self ::getType ($ w [$ t ]);if ($ t !=0 )$ x .=", " ;$ x .=self ::quote ($ w [$ t ]);if ($ y )$ x .=" AS " .self ::quote ($ y );}return $ x ;}else {return self ::quote ($ w );}}private static function value ($ z ,$ aa ,&$ ba ){$ ca =strtolower ($ z );if (!$ ca )$ ca =strtolower (gettype ($ aa ));$ z =\PDO ::PARAM_STR ;$ da =2 ;if ($ ca =="boolean " ||$ ca =="bool " ){$ z =\PDO ::PARAM_BOOL ;$ aa =$ aa ? "1 " : "0 " ;$ da =0 ;$ ba .="b " ;}else if ($ ca =="integer " ||$ ca =="int " ||$ ca =="double " ||$ ca =="doub " ){$ ba .="i " ;$ da =1 ;$ aa =(int )$ aa ;}else if ($ ca =="string " ||$ ca =="str " ){$ z =\PDO ::PARAM_STR ;$ aa =(string )$ aa ;$ da =2 ;$ ba .="s " ;}else if ($ ca =="resource " ||$ ca =="lob " ){$ z =\PDO ::PARAM_LOB ;$ da =3 ;$ ba .="l " ;}else if ($ ca =="null " ){$ da =4 ;$ z =\PDO ::PARAM_NULL ;$ aa =null ;$ ba .="n " ;}else if ($ ca =="json " ){$ da =5 ;$ z =\PDO ::PARAM_STR ;$ aa =json_encode ($ aa );}else if ($ ca =="obj " ){$ da =6 ;$ z =\PDO ::PARAM_STR ;$ aa =serialize ($ aa );}else {$ aa =(string )$ aa ;echo "SUPERSQL WARN: Invalid type " .$ ca ." Assumed STRING " ;}return array ($ aa ,$ z ,$ da );}private static function getType (&$ a ){if (substr ($ a ,-1 )=="] " ){$ ea =strrpos ($ a ,"[ " );if ($ ea ===false ){return "" ;}$ b =substr ($ a ,$ ea +1 ,-1 );$ a =substr ($ a ,0 ,$ ea );return $ b ;}else return "" ;}private static function rmComments ($ a ){$ t =strpos ($ a ,"# " );if ($ t !==false ){$ a =substr ($ a ,0 ,$ t );}return trim ($ a );}private static function conditions ($ k ,&$ f =false ,&$ fa =false ,&$ ba ="" ,&$ e =0 ){$ ga =function (&$ ga ,$ k ,&$ fa ,&$ e ,&$ f ,&$ ba ,$ ha =" AND " ,$ ia =" = " ,$ ja ="" ){$ ka =0 ;$ x ="" ;foreach ($ k as $ l =>$ d ){if (substr ($ l ,0 ,1 )==="# " ){$ la =true ;$ l =substr ($ l ,1 );}else {$ la =false ;}$ ma =self ::getArg ($ l );$ na =$ ma ? self ::getArg ($ l ): false ;$ oa =gettype ($ d );$ pa =!isset ($ d [0 ]);$ qa =$ ha ;$ ra =$ ia ;$ z =$ la ? false : self ::getType ($ l );$ sa =self ::quote (self ::rmComments ($ l ));switch ($ ma ){case "|| " :$ ma =$ na ;$ qa =" OR " ;break ;case "&& " :$ ma =$ na ;$ qa =" AND " ;break ;}switch ($ ma ){case ">> " :$ ra =" > " ;break ;case "<< " :$ ra =" < " ;break ;case ">= " :$ ra =" >= " ;break ;case "<= " :$ ra =" <= " ;break ;case "!= " :$ ra =" != " ;break ;case "~~ " :$ ra =" LIKE " ;break ;case "!~ " :$ ra =" NOT LIKE " ;break ;default : if (!$ pa ||$ ma =="== " )$ ra =" = " ;break ;}if ($ ka !=0 )$ x .=$ ha ;if ($ oa =="array " &&$ z !="json " &&$ z !="obj " ){if ($ pa ){$ x .="( " .$ ga ($ ga ,$ d ,$ fa ,$ e ,$ f ,$ qa ,$ ra ,$ ja ."/ " .$ l ).") " ;}else {if ($ fa !==false &&!$ la ){$ fa [$ l ]=$ e ;$ fa [$ l ."# " .$ ja ]=$ e ++;}foreach ($ aa as $ h =>$ p ){if ($ h !=0 )$ x .=$ qa ;$ e ++;$ x .=$ sa .$ ra ;if ($ la ){$ x .=$ p ;}else if ($ f !==false ){$ x .="? " ;array_push ($ f ,self ::value ($ z ,$ p ,$ ba ));}else {if (gettype ($ p )=="integer " ){$ x .=$ p ;}else {$ x .=self ::quote ($ p );}}}}}else {$ x .=$ sa .$ ra ;if ($ la ){$ x .=$ d ;}else {if ($ f !==false ){$ x .="? " ;array_push ($ f ,self ::value ($ z ,$ d ,$ ba ));}else {if (gettype ($ d )=="integer " ){$ x .=$ d ;}else {$ x .=self ::quote ($ d );}}if ($ fa !==false ){$ fa [$ l ]=$ e ;$ fa [$ l ."# " .$ ja ]=$ e ++;}}}$ ka ++;}return $ x ;};return $ ga ($ ga ,$ k ,$ fa ,$ e ,$ f ,$ ba );}static function SELECT ($ w ,$ ta ,$ ua ,$ ha ,$ va ){$ x ="SELECT " ;$ g =count ($ ta );$ f =array ();$ i =array ();$ wa =array ();if ($ g ==0 ){$ x .="* " ;}else {$ t =0 ;$ xa =0 ;$ ya ="" ;if ($ ta [0 ]=="DISTINCT " ){$ t =1 ;$ xa =1 ;$ x .="DISTINCT " ;}else if (substr ($ ta [0 ],0 ,11 )=="INSERT INTO " ){$ t =1 ;$ xa =1 ;$ x =$ ta [0 ]." " .$ x ;}else if (substr ($ ta [0 ],0 ,4 )=="INTO " ){$ t =1 ;$ xa =1 ;$ ya =" " .$ ta [0 ]." " ;}if ($ g >$ xa ){for (;$ t <$ g ;$ t ++){$ m =self ::getType ($ ta [$ t ]);$ y =$ m ? self ::getType ($ ta [$ t ]): false ;if (!$ y &&$ m ){if (!($ m =="int " ||$ m =="string " ||$ m =="json " ||$ m =="obj " ||$ m =="bool " )){$ y =$ m ;$ m =false ;}}if ($ m ){if ($ y ){$ wa [$ y ]=$ m ;}else {$ wa [$ ta [$ t ]]=$ m ;}}if ($ t >$ xa ){$ x .=", " ;}$ x .=self ::quote ($ ta [$ t ]);if ($ y )$ x .=" AS ` " .$ y ."` " ;}}else $ x .="* " ;$ x .=$ ya ;}$ x .=" FROM " .self ::table ($ w );if ($ ha ){foreach ($ ha as $ l =>$ d ){if (substr ($ l ,0 ,1 )==="# " ){$ la =true ;$ l =substr ($ l ,1 );}else {$ la =false ;}$ ma =self ::getArg ($ l );switch ($ ma ){case "<< " :$ x .=" RIGHT JOIN " ;break ;case ">> " :$ x .=" LEFT JOIN " ;break ;case "<> " :$ x .=" FULL JOIN " ;break ;default :$ x .=" JOIN " ;break ;}$ x .=self ::quote ($ l )." ON " ;if ($ la ){$ x .="val " ;}else {$ x .=self ::conditions ($ d );}}}$ ba ="" ;if (count ($ ua )!=0 ){$ x .=" WHERE " ;$ e =array ();if (isset ($ ua [0 ])){$ x .=self ::conditions ($ ua [0 ],$ f ,$ e ,$ ba );self ::append2 ($ i ,$ e ,$ ua ,$ f );}else {$ x .=self ::conditions ($ ua ,$ f ,$ e ,$ ba );}}if ($ va ){if (gettype ($ va )=="integer " ){$ x .=" LIMIT " .$ va ;}else if (gettype ($ va )=="string " ){$ x .=" " .$ va ;}}return array ($ x ,$ f ,$ i ,$ ba ,$ wa );}static function INSERT ($ w ,$ za ){$ x ="INSERT INTO " .self ::table ($ w )." ( " ;$ f =array ();$ i =array ();$ ba ="" ;$ ab ="" ;$ t =0 ;$ m =0 ;$ j =array ();$ bb =isset ($ za [0 ]);$ k =$ bb ?$ za [0 ]:$ za ;foreach ($ k as $ l =>$ d ){if (substr ($ l ,0 ,1 )==="# " ){$ la =true ;$ l =substr ($ l ,1 );}else {$ la =false ;}if ($ m !=0 ){$ x .=", " ;$ ab .=", " ;}$ z =self ::getType ($ l );$ x .="` " .self ::rmComments ($ l )."` " ;if ($ la ){$ ab .=$ d ;}else {$ ab .="? " ;array_push ($ f ,self ::value ($ z ,$ d ,$ ba ));if ($ bb ){$ j [$ l ]=$ t ++;}else {self ::append ($ i ,$ d ,$ t ++,$ f );}}$ m ++;}if ($ bb )self ::append2 ($ i ,$ j ,$ za ,$ f );$ x .=") VALUES ( " .$ ab .") " ;return array ($ x ,$ f ,$ i ,$ ba );}static function UPDATE ($ w ,$ za ,$ ua ){$ x ="UPDATE " .self ::table ($ w )." SET " ;$ f =array ();$ i =array ();$ ba ="" ;$ t =0 ;$ m =0 ;$ j =array ();$ bb =isset ($ za [0 ]);$ k =$ bb ?$ za [0 ]:$ za ;foreach ($ k as $ l =>$ d ){if (substr ($ l ,0 ,1 )==="# " ){$ la =true ;$ l =substr ($ l ,1 );}else {$ la =false ;}if ($ m !=0 ){$ x .=", " ;}if ($ la ){$ x .="` " .$ l ."` = " .$ d ;}else {$ ma =self ::getArg ($ l );$ x .="` " .$ l ."` = " ;switch ($ ma ){case "+= " :$ x .="` " .$ l ."` + ? " ;break ;case "-= " :$ x .="` " .$ l ."` - ? " ;break ;case "/= " :$ x .="` " .$ l ."` / ? " ;break ;case "*= " :$ x .="` " .$ l ."` * ? " ;break ;default :$ x .="? " ;break ;}$ z =self ::getType ($ l );array_push ($ f ,self ::value ($ z ,$ d ,$ ba ));if ($ bb ){$ j [$ l ]=$ t ++;}else {self ::append ($ i ,$ d ,$ t ++,$ f );}}$ m ++;}if ($ bb )self ::append2 ($ i ,$ j ,$ za ,$ f );if (count ($ ua )!=0 ){$ x .=" WHERE " ;$ e =array ();if (isset ($ ua [0 ])){$ x .=self ::conditions ($ ua [0 ],$ f ,$ e ,$ ba ,$ t );self ::append2 ($ i ,$ e ,$ ua ,$ f );}else {$ x .=self ::conditions ($ ua ,$ f ,$ e ,$ ba ,$ t );}}return array ($ x ,$ f ,$ i ,$ ba );}static function DELETE ($ w ,$ ua ){$ x ="DELETE FROM " .self ::table ($ w );$ f =array ();$ i =array ();$ ba ="" ;if (count ($ ua )!=0 ){$ x .=" WHERE " ;$ e =array ();if (isset ($ ua [0 ])){$ x .=self ::conditions ($ ua [0 ],$ f ,$ e ,$ ba );self ::append2 ($ i ,$ e ,$ ua ,$ f );}else {$ x .=self ::conditions ($ ua ,$ f ,$ e ,$ ba );}}return array ($ x ,$ f ,$ i ,$ ba );}}
1414// index.phpclass SuperSQL{public$con;function __construct($a,$b,$c){$this->con=new Connector($a,$b,$c);}function SELECT($d,$e=array(),$f=array(),$g=null,$h=false){if((gettype($g)=="integer"||gettype($g)=="string")&&!$h){$h=$g;$g=null;}$i=AdvParser::SELECT($d,$e,$f,$g,$h);return$this->con->_query($i[0],$i[1],$i[2],$i[3],$i[4]);}function INSERT($d,$j){$i=AdvParser::INSERT($d,$j);return$this->con->_query($i[0],$i[1],$i[2],$i[3]);}function UPDATE($d,$j,$f=array()){$i=AdvParser::UPDATE($d,$j,$f);return$this->con->_query($i[0],$i[1],$i[2],$i[3]);}function DELETE($d,$f=array()){$i=AdvParser::DELETE($d,$f);return$this->con->_query($i[0],$i[1],$i[2],$i[3]);}function query($k,$l=null){return$this->con->query($k,$l);}function close(){$this->con->close();}function dev(){$this->con->dev=true;}function getLog(){return$this->con->log;}function clearCache(){$this->con->clearCache();}function transact($m){$this->con->db->beginTransaction();$n=$m($o);if($n===false)$o->con->db->rollBack();else$o->con->db->commit();return$n;}}
1515?>
0 commit comments