@@ -670,21 +670,25 @@ private function getCondString($a, bool $and, bool $on = false) {
670
670
unset($ va [count ($ va -1 )]);
671
671
$ col = true ;
672
672
};
673
- if (!is_numeric ($ v2 ))
674
- $ v3 = $ this ->escape ($ v2 );
675
673
if (is_numeric ($ k ))
676
674
$ r .= $ v ;
677
675
else {
678
676
$ r .= "` {$ this ->escape ($ k )}` " ;
679
- $ r .= " = " ;
677
+ $ r .= $ v === NULL ? " IS " : " = " ;
680
678
if (is_numeric ($ v3 ))
681
679
$ v3 = intval ($ v3 );
682
- if ($ v3 ===NULL )
683
- $ r .= "IS NULL " ;
684
680
elseif (is_numeric ($ v3 ))
685
681
$ r .= $ v ;
682
+ elseif ($ on || $ col )
683
+ $ r .= "` " . $ this ->escape ($ v3 ) . "` " ;
684
+ elseif ($ value ===NULL )
685
+ $ r .= "NULL " ;
686
+ elseif (preg_match ("/^[\x{0020}-\x{007E}\x{00A0}-ſ]*$/ " , $ v3 ) && !preg_match ("/\x{0027}/ " , $ esc = $ this ->escape ($ v3 )))
687
+ $ r .= "' {$ esc }' " ;
688
+ elseif ($ this ->SQLite )
689
+ $ r .= "x' " . bin2hex ($ v3 ) . "' " ;
686
690
else
687
- $ r .= ( $ on || $ col ) ? " ` { $ v3 } ` " : " ' { $ v3} ' " ;
691
+ $ r .= " 0x " . bin2hex ( $ v3) ;
688
692
};
689
693
$ r .= $ and ? " AND " : " OR " ;
690
694
};
@@ -698,19 +702,25 @@ private function getCondString($a, bool $and, bool $on = false) {
698
702
unset($ va [count ($ va )]);
699
703
$ col = true ;
700
704
};
701
- if (!is_numeric ($ v ))
702
- $ v = $ this ->escape ($ v );
703
705
if (is_numeric ($ k ))
704
706
$ r .= $ v ;
705
707
else {
706
708
$ r .= "` " . $ this ->escape ($ k ) . "` " ;
707
- $ r .= " = " ;
709
+ $ r .= $ v === NULL ? " IS " : " = " ;
708
710
if (is_numeric ($ v ))
709
711
$ v = intval ($ v );
710
712
if (is_numeric ($ v ))
711
713
$ r .= $ v ;
714
+ elseif ($ on || $ col )
715
+ $ r .= "` " . $ this ->escape ($ v ) . "` " ;
716
+ elseif ($ v ===NULL )
717
+ $ r .= "NULL " ;
718
+ elseif (preg_match ("/^[\x{0020}-\x{007E}\x{00A0}-ſ]*$/ " , $ v ) && !preg_match ("/\x{0027}/ " , $ esc = $ this ->escape ($ v )))
719
+ $ r .= "' {$ esc }' " ;
720
+ elseif ($ this ->SQLite )
721
+ $ r .= "x' " . bin2hex ($ v ) . "' " ;
712
722
else
713
- $ r .= ( $ on || $ col ) ? " ` { $ v } ` " : " ' { $ v } ' " ;
723
+ $ r .= " 0x " . bin2hex ( $ v ) ;
714
724
};
715
725
$ r .= $ and ? " AND " : " OR " ;
716
726
};
@@ -917,17 +927,27 @@ public function __construct(SSQL $c, $cond = "") {
917
927
$ this ->c = $ c ;
918
928
$ this ->cond = $ cond ;
919
929
}
930
+ public function quote ($ v ) {
931
+ if (is_numeric ($ v ))
932
+ return $ v ;
933
+ elseif ($ v ===NULL )
934
+ return "NULL " ;
935
+ elseif (preg_match ("/^[\x{0020}-\x{007E}\x{00A0}-ſ]*$/ " , $ v ) && !preg_match ("/\x{0027}/ " , $ esc = $ this ->c ->escape ($ v )))
936
+ return "' {$ esc }' " ;
937
+ elseif ($ this ->c ->SQLite )
938
+ return "x' " . bin2hex ($ v ) . "' " ;
939
+ else
940
+ return "0x " . bin2hex ($ v );
941
+ }
920
942
public function eq (string $ k , $ v , int $ flags = 128 ) {
921
943
$ append = !empty ($ this ->cond );
922
944
$ quotes = "' " ;
923
- if (is_int ($ v ) || is_float ($ v )) {
945
+ if (is_int ($ v ) || is_float ($ v ))
924
946
$ v = [$ v ];
925
- $ quotes = "" ;
926
- };
927
947
if (is_array ($ v ) && count ($ v ) < 1 )
928
948
return false ;
929
949
if (is_array ($ v ))
930
- $ this ->cond = ($ append ? ("( {$ this ->cond }) " . ($ flags & SQ ::COND_OR ? "OR " : "AND " ) . " ( " ) : "" ) . ((count ($ v ) < 2 ) ? ("` " . $ this ->c ->escape ($ k ) . "` = " . $ quotes . $ this ->c -> escape ($ v [0 ]) . $ quotes ) : ("(` " . $ this ->c ->escape ($ k ) . "` = " . $ quotes . $ this ->c -> escape (array_shift ($ v )) . $ quotes . ") OR ( " . $ this ->c ->cond ()->eq ($ k , $ v ) . ") " )) . ($ append ? ") " : "" );
950
+ $ this ->cond = ($ append ? ("( {$ this ->cond }) " . ($ flags & SQ ::COND_OR ? "OR " : "AND " ) . " ( " ) : "" ) . ((count ($ v ) < 2 ) ? ("` " . $ this ->c ->escape ($ k ) . "` = " . $ this ->quote ($ v [0 ])) : ("(` " . $ this ->c ->escape ($ k ) . "` = " . $ this ->quote (array_shift ($ v )) . ") OR ( " . $ this ->c ->cond ()->eq ($ k , $ v ) . ") " )) . ($ append ? ") " : "" );
931
951
else
932
952
$ this ->cond = ($ append ? ("( {$ this ->cond }) " . ($ flags & SQ ::COND_OR ? "OR " : "AND " ) . " ( " ) : "" ) . ("` " . $ this ->c ->escape ($ k ) . "` = ` " . $ this ->c ->escape ($ v ) . "` " ) . ($ append ? ") " : "" );
933
953
return $ this ;
@@ -1017,7 +1037,7 @@ public function in(string $k, array $v, int $flags = 128) {
1017
1037
return implode (", " , array_map (function ($ n2 ) {
1018
1038
if (is_int ($ n2 ) || is_float ($ n2 ))
1019
1039
return strval ($ n2 );
1020
- return " ' " . $ this ->c -> escape ($ n2 ) . " ' " ;
1040
+ return $ this ->quote ($ n2 );
1021
1041
}, $ n ));
1022
1042
return "` " . $ this ->c ->escape ($ n ) . "` " ;
1023
1043
}, $ v );
@@ -1028,7 +1048,6 @@ public function begins(string $k, $v, int $flags = 128) {
1028
1048
$ append = !empty ($ this ->cond );
1029
1049
if (is_int ($ v ) || is_float ($ v )) {
1030
1050
$ v = [$ v ];
1031
- $ quotes = "" ;
1032
1051
};
1033
1052
if (is_array ($ v ) && count ($ v ) < 1 )
1034
1053
return false ;
0 commit comments