@@ -59,13 +59,51 @@ public function get_col_charset( $table, $column ) {
59
59
}
60
60
61
61
/**
62
- * Method to dummy out wpdb::set_sql_mode()
62
+ * Changes the current SQL mode, and ensures its WordPress compatibility.
63
63
*
64
- * @see wpdb::set_sql_mode()
64
+ * If no modes are passed, it will ensure the current MySQL server modes are compatible.
65
65
*
66
- * @param array $modes Optional. A list of SQL modes to set.
66
+ * This overrides wpdb::set_sql_mode() while closely mirroring its implementation.
67
+ *
68
+ * @param array $modes Optional. A list of SQL modes to set. Default empty array.
67
69
*/
68
70
public function set_sql_mode ( $ modes = array () ) {
71
+ if ( ! $ this ->dbh instanceof WP_SQLite_Driver ) {
72
+ return ;
73
+ }
74
+
75
+ if ( empty ( $ modes ) ) {
76
+ $ result = $ this ->dbh ->query ( 'SELECT @@SESSION.sql_mode ' );
77
+ if ( ! isset ( $ result [0 ] ) ) {
78
+ return ;
79
+ }
80
+
81
+ $ modes_str = $ result [0 ]->{'@@SESSION.sql_mode ' };
82
+ if ( empty ( $ modes_str ) ) {
83
+ return ;
84
+ }
85
+ $ modes = explode ( ', ' , $ modes_str );
86
+ }
87
+
88
+ $ modes = array_change_key_case ( $ modes , CASE_UPPER );
89
+
90
+ /**
91
+ * Filters the list of incompatible SQL modes to exclude.
92
+ *
93
+ * @since 3.9.0
94
+ *
95
+ * @param array $incompatible_modes An array of incompatible modes.
96
+ */
97
+ $ incompatible_modes = (array ) apply_filters ( 'incompatible_sql_modes ' , $ this ->incompatible_modes );
98
+
99
+ foreach ( $ modes as $ i => $ mode ) {
100
+ if ( in_array ( $ mode , $ incompatible_modes , true ) ) {
101
+ unset( $ modes [ $ i ] );
102
+ }
103
+ }
104
+ $ modes_str = implode ( ', ' , $ modes );
105
+
106
+ $ this ->dbh ->query ( "SET SESSION sql_mode=' $ modes_str' " );
69
107
}
70
108
71
109
/**
@@ -276,6 +314,7 @@ public function db_connect( $allow_bail = true ) {
276
314
}
277
315
$ GLOBALS ['@pdo ' ] = $ this ->dbh ->get_pdo ();
278
316
$ this ->ready = true ;
317
+ $ this ->set_sql_mode ();
279
318
}
280
319
281
320
/**
0 commit comments