File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -489,6 +489,20 @@ public function get_insert_id() {
489
489
return $ last_insert_id ;
490
490
}
491
491
492
+ /**
493
+ * Quotes a string for use in a query.
494
+ *
495
+ * Places quotes around the input string (if required) and escapes special
496
+ * characters within the input string. See "PDO::quote()".
497
+ *
498
+ * @param string $value The string value to quote.
499
+ * @param int $type The type of the parameter. Default is PDO::PARAM_STR.
500
+ * @return string The quoted string.
501
+ */
502
+ public function quote ( string $ value , int $ type = PDO ::PARAM_STR ): string {
503
+ return $ this ->pdo ->quote ( $ value , $ type );
504
+ }
505
+
492
506
/**
493
507
* Translate and execute a MySQL query in SQLite.
494
508
*
Original file line number Diff line number Diff line change @@ -119,7 +119,13 @@ public function _real_escape( $data ) {
119
119
if ( ! is_scalar ( $ data ) ) {
120
120
return '' ;
121
121
}
122
- $ escaped = addslashes ( $ data );
122
+ if ( $ this ->dbh instanceof WP_SQLite_Driver ) {
123
+ // WP_SQLite_Driver::quote() wraps the escaped string with quotes,
124
+ // while WPDB expects the string to be escaped without them.
125
+ $ escaped = substr ( $ this ->dbh ->quote ( $ data ), 1 , -1 );
126
+ } else {
127
+ $ escaped = addslashes ( $ data );
128
+ }
123
129
return $ this ->add_placeholder_escape ( $ escaped );
124
130
}
125
131
You can’t perform that action at this time.
0 commit comments