@@ -67,7 +67,7 @@ public static function run()
67
67
*
68
68
* @param null $db
69
69
*
70
- * @return object
70
+ * @return \PDO
71
71
*/
72
72
public static function getConnection ($ db = null )
73
73
{
@@ -307,7 +307,9 @@ public function setDatabase($db = null)
307
307
*
308
308
* @param string $db the database slug
309
309
*
310
- * @return object the PDO object
310
+ * @return \PDO
311
+ *
312
+ * @todo support port #s and test on each database
311
313
*/
312
314
public function &connect ($ db = null )
313
315
{
@@ -420,7 +422,7 @@ private function documentation($query, $db = null)
420
422
{
421
423
$ final_result = array ();
422
424
423
- $ key = md5 (json_encode ($ query ) . $ this ->getDatabase ($ db )->name . '_docs ' );
425
+ $ key = crc32 (json_encode ($ query ) . $ this ->getDatabase ($ db )->name . '_docs ' );
424
426
425
427
if ($ cache = $ this ->getCache ($ key )) {
426
428
return $ cache ;
@@ -520,7 +522,7 @@ private function documentation($query, $db = null)
520
522
*/
521
523
private function get ($ query , $ db = null )
522
524
{
523
- $ key = md5 (json_encode ($ query ) . $ this ->getDatabase ($ db )->name );
525
+ $ key = crc32 (json_encode ($ query ) . $ this ->getDatabase ($ db )->name );
524
526
525
527
if ($ cache = $ this ->getCache ($ key )) {
526
528
return $ cache ;
@@ -655,6 +657,7 @@ private function get($query, $db = null)
655
657
$ select_columns = implode (', ' , $ standard_columns );
656
658
}
657
659
}
660
+ // Prefix table before column
658
661
} elseif (!empty ($ query ['prefix ' ])) {
659
662
$ prefix_columns = array ();
660
663
foreach ($ select_tables as $ table ) {
@@ -678,7 +681,7 @@ private function get($query, $db = null)
678
681
$ sql = $ where ['sql ' ] . ' AND ' . $ restriction ;
679
682
$ where_values = $ where ['values ' ];
680
683
} elseif (!empty ($ restriction )) {
681
- $ sql .= ' WHERE ' . $ restriction . $ this ->hooks ->apply_filters ('get_where_ ' . strtolower ($ query ['table ' ]), '' );
684
+ $ sql .= ' WHERE ' . $ restriction . $ this ->hooks ->apply_filters ('get_where_ ' . strtolower ($ query ['table ' ]), '' , $ table );
682
685
}
683
686
684
687
// build ORDER query
@@ -796,7 +799,7 @@ private function get($query, $db = null)
796
799
foreach ($ where_values as $ key => $ value ) {
797
800
$ type = self ::detectPDOType ($ value );
798
801
$ key = ': ' . $ key ;
799
- $ sql_compiled = preg_replace ('/( ' . preg_quote ($ key ) . ")([,]|\s|$|\))/i " , "' " . $ value . "'$2 " , $ sql_compiled );
802
+ $ sql_compiled = preg_replace ('/( ' . preg_quote ($ key, ' / ' ) . ")([,]|\s|$|\))/i " , "' " . $ value . "'$2 " , $ sql_compiled );
800
803
$ sth ->bindValue ($ key , $ value , $ type );
801
804
}
802
805
}
@@ -806,7 +809,7 @@ private function get($query, $db = null)
806
809
foreach ($ join_values as $ key => $ value ) {
807
810
$ type = self ::detectPDOType ($ value );
808
811
$ key = ': ' . $ key ;
809
- $ sql_compiled = preg_replace ('/( ' . preg_quote ($ key ) . ")([,]|\s|$|\))/i " , "' " . $ value . "'$2 " , $ sql_compiled );
812
+ $ sql_compiled = preg_replace ('/( ' . preg_quote ($ key, ' / ' ) . ")([,]|\s|$|\))/i " , "' " . $ value . "'$2 " , $ sql_compiled );
810
813
$ sth ->bindValue ($ key , $ value , $ type );
811
814
}
812
815
}
@@ -849,7 +852,7 @@ private function post($query, $db = null)
849
852
$ dbh = &$ this ->connect ($ db );
850
853
851
854
// check values
852
- if (!empty ($ query ['insert ' ]) && !is_array ($ query ['insert ' ]) || count ($ query ['insert ' ]) < 1 ) {
855
+ if (( !empty ($ query ['insert ' ]) && !is_array ($ query ['insert ' ]) ) || count ($ query ['insert ' ]) < 1 ) {
853
856
Response::error ('Invalid insert values ' , 400 );
854
857
}
855
858
@@ -1050,6 +1053,9 @@ private function patch($query, $db = null)
1050
1053
if (is_array ($ value )) {
1051
1054
$ value = serialize ($ value );
1052
1055
}
1056
+ if (is_string ($ value ) && strtolower ($ value ) == 'null ' ) {
1057
+ $ value = null ;
1058
+ }
1053
1059
$ key = ': ' . $ key ;
1054
1060
$ sql_compiled = self ::debugCompileSQL ($ sql_compiled , $ key , $ value );
1055
1061
if (empty ($ value )) {
@@ -1162,6 +1168,9 @@ private function executeInsert($table, $columns, $dbh)
1162
1168
if (is_array ($ value )) {
1163
1169
$ value = serialize ($ value );
1164
1170
}
1171
+ if (is_string ($ value ) && strtolower ($ value ) == 'null ' ) {
1172
+ $ value = null ;
1173
+ }
1165
1174
$ column = ': ' . $ column ;
1166
1175
$ sth ->bindValue ($ column , $ value );
1167
1176
$ sql_compiled = self ::debugCompileSQL ($ sql_compiled , $ column , $ value );
@@ -1355,7 +1364,7 @@ public function tableExists($query_table, $db = null)
1355
1364
*/
1356
1365
public function getTables ($ db = null )
1357
1366
{
1358
- $ key = md5 ($ this ->getDatabase ($ db )->name . '_tables ' );
1367
+ $ key = crc32 ($ this ->getDatabase ($ db )->name . '_tables ' );
1359
1368
1360
1369
if ($ cache = $ this ->getCache ($ key )) {
1361
1370
return $ cache ;
@@ -1446,7 +1455,7 @@ public function getColumns($table, $db = null)
1446
1455
return false ;
1447
1456
}
1448
1457
1449
- $ key = md5 ($ this ->getDatabase ($ db )->name . '. ' . $ table . '_columns ' );
1458
+ $ key = crc32 ($ this ->getDatabase ($ db )->name . '. ' . $ table . '_columns ' );
1450
1459
1451
1460
if ($ cache = $ this ->getCache ($ key )) {
1452
1461
return $ cache ;
@@ -1593,7 +1602,19 @@ private function parseWhere($main_table, $where, $sql)
1593
1602
$ where_sql [] = "{$ table }. {$ column } NOT IN ( " . implode (', ' , $ where_not_in ) . ') ' ;
1594
1603
}
1595
1604
}
1596
- } elseif (!is_array ($ value_condition ) && is_int ($ condition ) || $ condition === '= ' ) { // Check equal array cases
1605
+ } elseif ($ condition === '= ' && is_array ($ value_condition )) { // Check equal array cases
1606
+ foreach ($ value_condition as $ value ) {
1607
+ $ _value_split = explode ('. ' , $ value , 2 );
1608
+ if (count ($ _value_split ) > 1 && $ this ->checkColumn (@$ _value_split [1 ], @$ _value_split [0 ])) {
1609
+ $ index_value = $ _value_split [0 ] . '. ' . $ _value_split [1 ];
1610
+ } else {
1611
+ $ index_key = self ::indexValue ($ prefix , $ column , $ where_values );
1612
+ $ index_value = ' : ' . $ index_key ;
1613
+ $ where_values [$ index_key ] = $ value ;
1614
+ }
1615
+ $ where_in [] = $ index_value ;
1616
+ }
1617
+ } elseif (!is_array ($ value_condition ) && is_int ($ condition )) { // Check equal array cases
1597
1618
$ _value_split = explode ('. ' , $ value_condition , 2 );
1598
1619
if (count ($ _value_split ) > 1 && $ this ->checkColumn (@$ _value_split [1 ], @$ _value_split [0 ])) {
1599
1620
$ index_value = $ _value_split [0 ] . '. ' . $ _value_split [1 ];
@@ -1756,7 +1777,7 @@ private static function detectPDOType($value)
1756
1777
*/
1757
1778
private static function debugCompileSQL ($ string , $ key , $ value )
1758
1779
{
1759
- $ string = preg_replace ('/ ' . $ key . "([,]|\s|$|\))/i " , "' " . $ value . "'$1 " , $ string );
1780
+ $ string = preg_replace ('/ ' . $ key . "([,]|\s|$|\))/i " , ( is_null ( $ value ) ? ' NULL$1 ' : "' " . $ value . "'$1 " ) , $ string );
1760
1781
1761
1782
return $ string ;
1762
1783
}
@@ -1801,7 +1822,8 @@ private function sanitizeResults($results)
1801
1822
foreach ($ results as $ key => $ result ) {
1802
1823
// Sanitize encoding
1803
1824
foreach ($ result as $ column => $ value ) {
1804
- $ results [$ key ]->$ column = utf8_encode ($ value );
1825
+ // Remind: change LBL_CHARSET in include/language/[iso_lang]_[iso_lang].lang.php
1826
+ $ results [$ key ]->$ column = (mb_detect_encoding ($ value ) == 'UTF-8 ' ) ? $ value : utf8_encode ($ value );
1805
1827
}
1806
1828
}
1807
1829
0 commit comments