@@ -16,7 +16,7 @@ class WP_SQLite_DB extends wpdb {
1616 /**
1717 * Database Handle
1818 *
19- * @var WP_SQLite_Translator
19+ * @var WP_SQLite_Driver
2020 */
2121 protected $ dbh ;
2222
@@ -94,10 +94,6 @@ public function get_col_charset( $table, $column ) {
9494 * @param array $modes Optional. A list of SQL modes to set. Default empty array.
9595 */
9696 public function set_sql_mode ( $ modes = array () ) {
97- if ( ! $ this ->dbh instanceof WP_SQLite_Driver ) {
98- return ;
99- }
100-
10197 if ( empty ( $ modes ) ) {
10298 $ result = $ this ->dbh ->query ( 'SELECT @@SESSION.sql_mode ' );
10399 if ( ! isset ( $ result [0 ] ) ) {
@@ -175,28 +171,6 @@ public function _real_escape( $data ) {
175171 return $ this ->add_placeholder_escape ( $ escaped );
176172 }
177173
178- /**
179- * Method to dummy out wpdb::esc_like() function.
180- *
181- * WordPress 4.0.0 introduced esc_like() function that adds backslashes to %,
182- * underscore and backslash, which is not interpreted as escape character
183- * by SQLite. So we override it and dummy out this function.
184- *
185- * @param string $text The raw text to be escaped. The input typed by the user should have no
186- * extra or deleted slashes.
187- *
188- * @return string Text in the form of a LIKE phrase. The output is not SQL safe. Call $wpdb::prepare()
189- * or real_escape next.
190- */
191- public function esc_like ( $ text ) {
192- // The new driver adds "ESCAPE '\\'" to every LIKE expression by default.
193- // We only need to overload this function to a no-op for the old driver.
194- if ( $ this ->dbh instanceof WP_SQLite_Driver ) {
195- return parent ::esc_like ( $ text );
196- }
197- return $ text ;
198- }
199-
200174 /**
201175 * Prints SQL/DB error.
202176 *
@@ -326,34 +300,28 @@ public function db_connect( $allow_bail = true ) {
326300 }
327301 }
328302
329- if ( defined ( 'WP_SQLITE_AST_DRIVER ' ) && WP_SQLITE_AST_DRIVER ) {
330- if ( null === $ this ->dbname || '' === $ this ->dbname ) {
331- $ this ->bail (
332- 'The database name was not set. The SQLite driver requires a database name to be set to emulate MySQL information schema tables. ' ,
333- 'db_connect_fail '
334- );
335- return false ;
336- }
303+ if ( null === $ this ->dbname || '' === $ this ->dbname ) {
304+ $ this ->bail (
305+ 'The database name was not set. The SQLite driver requires a database name to be set to emulate MySQL information schema tables. ' ,
306+ 'db_connect_fail '
307+ );
308+ return false ;
309+ }
337310
338- $ this ->ensure_database_directory ( FQDB );
339-
340- try {
341- $ connection = new WP_SQLite_Connection (
342- array (
343- 'pdo ' => $ pdo ,
344- 'path ' => FQDB ,
345- 'journal_mode ' => defined ( 'SQLITE_JOURNAL_MODE ' ) ? SQLITE_JOURNAL_MODE : null ,
346- )
347- );
348- $ this ->dbh = new WP_SQLite_Driver ( $ connection , $ this ->dbname );
349- $ GLOBALS ['@pdo ' ] = $ this ->dbh ->get_connection ()->get_pdo ();
350- } catch ( Throwable $ e ) {
351- $ this ->last_error = $ this ->format_error_message ( $ e );
352- }
353- } else {
354- $ this ->dbh = new WP_SQLite_Translator ( $ pdo );
355- $ this ->last_error = $ this ->dbh ->get_error_message ();
356- $ GLOBALS ['@pdo ' ] = $ this ->dbh ->get_pdo ();
311+ $ this ->ensure_database_directory ( FQDB );
312+
313+ try {
314+ $ connection = new WP_SQLite_Connection (
315+ array (
316+ 'pdo ' => $ pdo ,
317+ 'path ' => FQDB ,
318+ 'journal_mode ' => defined ( 'SQLITE_JOURNAL_MODE ' ) ? SQLITE_JOURNAL_MODE : null ,
319+ )
320+ );
321+ $ this ->dbh = new WP_SQLite_Driver ( $ connection , $ this ->dbname );
322+ $ GLOBALS ['@pdo ' ] = $ this ->dbh ->get_connection ()->get_pdo ();
323+ } catch ( Throwable $ e ) {
324+ $ this ->last_error = $ this ->format_error_message ( $ e );
357325 }
358326 if ( $ this ->last_error ) {
359327 return false ;
@@ -467,11 +435,7 @@ public function query( $query ) {
467435 if ( preg_match ( '/^\s*(create|alter|truncate|drop)\s/i ' , $ query ) ) {
468436 $ return_val = true ;
469437 } elseif ( preg_match ( '/^\s*(insert|delete|update|replace)\s/i ' , $ query ) ) {
470- if ( $ this ->dbh instanceof WP_SQLite_Driver ) {
471- $ this ->rows_affected = $ this ->dbh ->get_last_return_value ();
472- } else {
473- $ this ->rows_affected = $ this ->dbh ->get_affected_rows ();
474- }
438+ $ this ->rows_affected = $ this ->dbh ->get_last_return_value ();
475439
476440 // Take note of the insert_id.
477441 if ( preg_match ( '/^\s*(insert|replace)\s/i ' , $ query ) ) {
@@ -516,11 +480,7 @@ public function query( $query ) {
516480 }
517481
518482 // Add SQLite query data.
519- if ( $ this ->dbh instanceof WP_SQLite_Driver ) {
520- $ this ->queries [ $ i ]['sqlite_queries ' ] = $ this ->dbh ->get_last_sqlite_queries ();
521- } else {
522- $ this ->queries [ $ i ]['sqlite_queries ' ] = $ this ->dbh ->executed_sqlite_queries ;
523- }
483+ $ this ->queries [ $ i ]['sqlite_queries ' ] = $ this ->dbh ->get_last_sqlite_queries ();
524484 }
525485 return $ return_val ;
526486 }
@@ -545,10 +505,6 @@ private function _do_query( $query ) {
545505 $ this ->last_error = $ this ->format_error_message ( $ e );
546506 }
547507
548- if ( $ this ->dbh instanceof WP_SQLite_Translator ) {
549- $ this ->last_error = $ this ->dbh ->get_error_message ();
550- }
551-
552508 ++$ this ->num_queries ;
553509
554510 if ( defined ( 'SAVEQUERIES ' ) && SAVEQUERIES ) {
@@ -573,27 +529,23 @@ protected function load_col_info() {
573529 if ( $ this ->col_info ) {
574530 return ;
575531 }
576- if ( $ this ->dbh instanceof WP_SQLite_Driver ) {
577- $ this ->col_info = array ();
578- foreach ( $ this ->dbh ->get_last_column_meta () as $ column ) {
579- $ this ->col_info [] = (object ) array (
580- 'name ' => $ column ['name ' ],
581- 'orgname ' => $ column ['mysqli:orgname ' ],
582- 'table ' => $ column ['table ' ],
583- 'orgtable ' => $ column ['mysqli:orgtable ' ],
584- 'def ' => '' , // Unused, always ''.
585- 'db ' => $ column ['mysqli:db ' ],
586- 'catalog ' => 'def ' , // Unused, always 'def'.
587- 'max_length ' => 0 , // As of PHP 8.1, this is always 0.
588- 'length ' => $ column ['len ' ],
589- 'charsetnr ' => $ column ['mysqli:charsetnr ' ],
590- 'flags ' => $ column ['mysqli:flags ' ],
591- 'type ' => $ column ['mysqli:type ' ],
592- 'decimals ' => $ column ['precision ' ],
593- );
594- }
595- } else {
596- $ this ->col_info = $ this ->dbh ->get_columns ();
532+ $ this ->col_info = array ();
533+ foreach ( $ this ->dbh ->get_last_column_meta () as $ column ) {
534+ $ this ->col_info [] = (object ) array (
535+ 'name ' => $ column ['name ' ],
536+ 'orgname ' => $ column ['mysqli:orgname ' ],
537+ 'table ' => $ column ['table ' ],
538+ 'orgtable ' => $ column ['mysqli:orgtable ' ],
539+ 'def ' => '' , // Unused, always ''.
540+ 'db ' => $ column ['mysqli:db ' ],
541+ 'catalog ' => 'def ' , // Unused, always 'def'.
542+ 'max_length ' => 0 , // As of PHP 8.1, this is always 0.
543+ 'length ' => $ column ['len ' ],
544+ 'charsetnr ' => $ column ['mysqli:charsetnr ' ],
545+ 'flags ' => $ column ['mysqli:flags ' ],
546+ 'type ' => $ column ['mysqli:type ' ],
547+ 'decimals ' => $ column ['precision ' ],
548+ );
597549 }
598550 }
599551
0 commit comments