44 License: MIT (https://github.com/ThreeLetters/SuperSQL/blob/master/LICENSE)
55 Source: https://github.com/ThreeLetters/SQL-Library
66 Build: v1.0.2
7- Built on: 10 /08/2017
7+ Built on: 11 /08/2017
88*/
99
1010// lib/connector/index.php
@@ -45,6 +45,13 @@ function init(&$data, &$mode) {
4545 $ this ->result = array ();
4646 }
4747 }
48+ function close () {
49+ $ this ->complete = true ;
50+ if ($ this ->stmt ) {
51+ $ this ->stmt ->closeCursor ();
52+ $ this ->stmt = null ;
53+ }
54+ }
4855 function fetchNextRow () {
4956 $ row = $ this ->stmt ->fetch ();
5057 if ($ row ) {
@@ -276,7 +283,7 @@ class AdvParser
276283{
277284 static function getArg (&$ str )
278285 {
279- if (substr ( $ str, 0 , 1 ) === '[ ' && substr ($ str , 3 , 1 ) === '] ' ) {
286+ if ($ str[ 0 ] === '[ ' && substr ($ str , 3 , 1 ) === '] ' ) {
280287 $ out = substr ($ str , 1 , 2 );
281288 $ str = substr ($ str , 4 );
282289 return $ out ;
@@ -306,7 +313,7 @@ function stripArgs(&$key)
306313 $ b = strrpos ($ key , '] ' , -1 );
307314 if ($ b !== false )
308315 $ key = substr ($ key , $ b + 1 );
309- if (substr ( $ key, 0 , 1 ) === '# ' ) {
316+ if ($ key[ 0 ] === '# ' ) {
310317 $ key = substr ($ key , 1 );
311318 }
312319 }
@@ -407,23 +414,21 @@ static function table($table)
407414 }
408415 static function value ($ type , $ value )
409416 {
410- $ var = strtolower ($ type );
411- if (!$ var )
412- $ var = strtolower (gettype ($ value ));
417+ $ var = $ type ? $ type : gettype ($ value );
413418 $ type = \PDO ::PARAM_STR ;
414419 $ dtype = 2 ;
415420 if ($ var === 'integer ' || $ var === 'int ' || $ var === 'double ' || $ var === 'doub ' ) {
421+ $ type = \PDO ::PARAM_INT ;
416422 $ dtype = 1 ;
417423 $ value = (int ) $ value ;
418424 } else if ($ var === 'string ' || $ var === 'str ' ) {
419- $ type = \PDO ::PARAM_STR ;
420425 $ value = (string ) $ value ;
421426 $ dtype = 2 ;
422427 } else if ($ var === 'boolean ' || $ var === 'bool ' ) {
423428 $ type = \PDO ::PARAM_BOOL ;
424429 $ value = $ value ? '1 ' : '0 ' ;
425430 $ dtype = 0 ;
426- } else if ($ var === 'null ' ) {
431+ } else if ($ var === 'null ' || $ var === ' NULL ' ) {
427432 $ dtype = 4 ;
428433 $ type = \PDO ::PARAM_NULL ;
429434 $ value = null ;
@@ -432,11 +437,9 @@ static function value($type, $value)
432437 $ dtype = 3 ;
433438 } else if ($ var === 'json ' ) {
434439 $ dtype = 5 ;
435- $ type = \PDO ::PARAM_STR ;
436440 $ value = json_encode ($ value );
437441 } else if ($ var === 'obj ' ) {
438442 $ dtype = 6 ;
439- $ type = \PDO ::PARAM_STR ;
440443 $ value = serialize ($ value );
441444 } else {
442445 $ value = (string )$ value ;
@@ -450,7 +453,8 @@ static function value($type, $value)
450453 }
451454 static function getType (&$ str )
452455 {
453- if (substr ($ str , -1 ) === '] ' ) {
456+ $ len = strlen ($ str );
457+ if ($ str [$ len - 1 ] === '] ' ) {
454458 $ start = strrpos ($ str , '[ ' );
455459 if ($ start === false ) {
456460 return '' ;
@@ -464,9 +468,9 @@ static function getType(&$str)
464468 static function rmComments ($ str ) {
465469 $ i = strpos ($ str ,'# ' );
466470 if ($ i !== false ) {
467- $ str = substr ($ str ,0 ,$ i );
471+ $ str = trim ( substr ($ str ,0 ,$ i) );
468472 }
469- return trim ( $ str) ;
473+ return $ str ;
470474 }
471475 static function conditions ($ dt , &$ values = false , &$ map = false , &$ index = 0 )
472476 {
@@ -475,7 +479,7 @@ static function conditions($dt, &$values = false, &$map = false, &$index = 0)
475479 $ num = 0 ;
476480 $ sql = '' ;
477481 foreach ($ dt as $ key => &$ val ) {
478- if (substr ( $ key, 0 , 1 ) === '# ' ) {
482+ if ($ key[ 0 ] === '# ' ) {
479483 $ raw = true ;
480484 $ key = substr ($ key , 1 );
481485 } else {
@@ -583,7 +587,7 @@ static function conditions($dt, &$values = false, &$map = false, &$index = 0)
583587 }
584588 static function JOIN ($ join , &$ sql ) {
585589 foreach ($ join as $ key => &$ val ) {
586- if (substr ( $ key, 0 , 1 ) === '# ' ) {
590+ if ($ key[ 0 ] === '# ' ) {
587591 $ raw = true ;
588592 $ key = substr ($ key , 1 );
589593 } else {
@@ -635,7 +639,7 @@ static function SELECT($table, $columns, $where, $join, $limit)
635639 $ into = ' ' . $ columns [0 ] . ' ' ;
636640 }
637641 if ($ len > $ req ) {
638- for ($ i = $ req ; $ i < $ len ; $ i ++) {
642+ for ($ i = $ req ; isset ( $ columns [ $ i ]) ; $ i ++) {
639643 $ b = self ::getType ($ columns [$ i ]);
640644 $ t = $ b ? self ::getType ($ columns [$ i ]) : false ;
641645 if (!$ t && $ b ) {
@@ -703,7 +707,7 @@ static function INSERT($table, $data)
703707 $ multi = isset ($ data [0 ]);
704708 $ dt = $ multi ? $ data [0 ] : $ data ;
705709 foreach ($ dt as $ key => &$ val ) {
706- if (substr ( $ key, 0 , 1 ) === '# ' ) {
710+ if ($ key[ 0 ] === '# ' ) {
707711 $ raw = true ;
708712 $ key = substr ($ key , 1 );
709713 } else {
@@ -748,7 +752,7 @@ static function UPDATE($table, $data, $where)
748752 $ multi = isset ($ data [0 ]);
749753 $ dt = $ multi ? $ data [0 ] : $ data ;
750754 foreach ($ dt as $ key => &$ val ) {
751- if (substr ( $ key, 0 , 1 ) === '# ' ) {
755+ if ($ key[ 0 ] === '# ' ) {
752756 $ raw = true ;
753757 $ key = substr ($ key , 1 );
754758 } else {
0 commit comments