@@ -227,6 +227,9 @@ public function __construct($tableName, ConnectionInterface &$db, array $options
227227
228228 $ this ->db = $ db ;
229229
230+ // turn off automatic escape flags
231+ $ this ->db ->setEscapeFlags (false );
232+
230233 $ this ->from ($ tableName );
231234
232235 if (! empty ($ options ))
@@ -664,7 +667,7 @@ protected function whereHaving($qb_key, $key, $value = null, $type = 'AND ', $es
664667 $ op = $ this ->getOperator ($ k );
665668 $ k = trim (str_replace ($ op , '' , $ k ));
666669
667- $ bind = $ this ->setBind ($ k , $ v );
670+ $ bind = $ this ->setBind ($ k , $ v, $ escape );
668671
669672 if (empty ($ op ))
670673 {
@@ -814,7 +817,7 @@ protected function _whereIn($key = null, $values = null, $not = false, $type = '
814817 $ not = ($ not ) ? ' NOT ' : '' ;
815818
816819 $ where_in = array_values ($ values );
817- $ ok = $ this ->setBind ($ ok , $ where_in );
820+ $ ok = $ this ->setBind ($ ok , $ where_in, $ escape );
818821
819822 $ prefix = empty ($ this ->QBWhere ) ? $ this ->groupGetType ('' ) : $ this ->groupGetType ($ type );
820823
@@ -955,19 +958,19 @@ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $n
955958
956959 if ($ side === 'none ' )
957960 {
958- $ bind = $ this ->setBind ($ k , $ v );
961+ $ bind = $ this ->setBind ($ k , $ v, $ escape );
959962 }
960963 elseif ($ side === 'before ' )
961964 {
962- $ bind = $ this ->setBind ($ k , "% $ v " );
965+ $ bind = $ this ->setBind ($ k , "% $ v " , $ escape );
963966 }
964967 elseif ($ side === 'after ' )
965968 {
966- $ bind = $ this ->setBind ($ k , "$ v% " );
969+ $ bind = $ this ->setBind ($ k , "$ v% " , $ escape );
967970 }
968971 else
969972 {
970- $ bind = $ this ->setBind ($ k , "% $ v% " );
973+ $ bind = $ this ->setBind ($ k , "% $ v% " , $ escape );
971974 }
972975
973976 $ like_statement = $ this ->_like_statement ($ prefix , $ k , $ not , $ bind , $ insensitiveSearch );
@@ -1345,7 +1348,7 @@ public function set($key, $value = '', $escape = null)
13451348 {
13461349 if ($ escape )
13471350 {
1348- $ bind = $ this ->setBind ($ k , $ v );
1351+ $ bind = $ this ->setBind ($ k , $ v, $ escape );
13491352 $ this ->QBSet [$ this ->db ->protectIdentifiers ($ k , false , $ escape )] = ": $ bind: " ;
13501353 }
13511354 else
@@ -1415,7 +1418,7 @@ public function getCompiledSelect($reset = true)
14151418 protected function compileFinalQuery (string $ sql ): string
14161419 {
14171420 $ query = new Query ($ this ->db );
1418- $ query ->setQuery ($ sql , $ this ->binds );
1421+ $ query ->setQuery ($ sql , $ this ->binds , false );
14191422
14201423 if (! empty ($ this ->db ->swapPre ) && ! empty ($ this ->db ->DBPrefix ))
14211424 {
@@ -1718,7 +1721,7 @@ public function setInsertBatch($key, $value = '', $escape = null)
17181721 $ clean = [];
17191722 foreach ($ row as $ k => $ value )
17201723 {
1721- $ clean [] = ': ' . $ this ->setBind ($ k , $ value ) . ': ' ;
1724+ $ clean [] = ': ' . $ this ->setBind ($ k , $ value, $ escape ) . ': ' ;
17221725 }
17231726
17241727 $ row = $ clean ;
@@ -2225,7 +2228,7 @@ public function setUpdateBatch($key, $index = '', $escape = null)
22252228 $ index_set = true ;
22262229 }
22272230
2228- $ bind = $ this ->setBind ($ k2 , $ v2 );
2231+ $ bind = $ this ->setBind ($ k2 , $ v2, $ escape );
22292232
22302233 $ clean [$ this ->db ->protectIdentifiers ($ k2 , false , $ escape )] = ": $ bind: " ;
22312234 }
@@ -2940,17 +2943,24 @@ protected function getOperator($str)
29402943
29412944 /**
29422945 * Stores a bind value after ensuring that it's unique.
2946+ * While it might be nicer to have named keys for our binds array
2947+ * with PHP 7+ we get a huge memory/performance gain with indexed
2948+ * arrays instead, so lets take advantage of that here.
29432949 *
2944- * @param string $key
2945- * @param null $value
2950+ * @param string $key
2951+ * @param null $value
2952+ * @param boolean $escape
29462953 *
29472954 * @return string
29482955 */
2949- protected function setBind (string $ key , $ value = null )
2956+ protected function setBind (string $ key , $ value = null , bool $ escape = true )
29502957 {
29512958 if (! array_key_exists ($ key , $ this ->binds ))
29522959 {
2953- $ this ->binds [$ key ] = $ value ;
2960+ $ this ->binds [$ key ] = [
2961+ $ value ,
2962+ $ escape ,
2963+ ];
29542964
29552965 return $ key ;
29562966 }
@@ -2962,7 +2972,10 @@ protected function setBind(string $key, $value = null)
29622972 ++$ count ;
29632973 }
29642974
2965- $ this ->binds [$ key . $ count ] = $ value ;
2975+ $ this ->binds [$ key . $ count ] = [
2976+ $ value ,
2977+ $ escape ,
2978+ ];
29662979
29672980 return $ key . $ count ;
29682981 }
0 commit comments