@@ -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 ] ) ) {
@@ -189,12 +185,7 @@ public function _real_escape( $data ) {
189185 * or real_escape next.
190186 */
191187 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 ;
188+ return parent ::esc_like ( $ text );
198189 }
199190
200191 /**
@@ -326,34 +317,28 @@ public function db_connect( $allow_bail = true ) {
326317 }
327318 }
328319
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- }
320+ if ( null === $ this ->dbname || '' === $ this ->dbname ) {
321+ $ this ->bail (
322+ 'The database name was not set. The SQLite driver requires a database name to be set to emulate MySQL information schema tables. ' ,
323+ 'db_connect_fail '
324+ );
325+ return false ;
326+ }
337327
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 ();
328+ $ this ->ensure_database_directory ( FQDB );
329+
330+ try {
331+ $ connection = new WP_SQLite_Connection (
332+ array (
333+ 'pdo ' => $ pdo ,
334+ 'path ' => FQDB ,
335+ 'journal_mode ' => defined ( 'SQLITE_JOURNAL_MODE ' ) ? SQLITE_JOURNAL_MODE : null ,
336+ )
337+ );
338+ $ this ->dbh = new WP_SQLite_Driver ( $ connection , $ this ->dbname );
339+ $ GLOBALS ['@pdo ' ] = $ this ->dbh ->get_connection ()->get_pdo ();
340+ } catch ( Throwable $ e ) {
341+ $ this ->last_error = $ this ->format_error_message ( $ e );
357342 }
358343 if ( $ this ->last_error ) {
359344 return false ;
@@ -467,11 +452,7 @@ public function query( $query ) {
467452 if ( preg_match ( '/^\s*(create|alter|truncate|drop)\s/i ' , $ query ) ) {
468453 $ return_val = true ;
469454 } 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- }
455+ $ this ->rows_affected = $ this ->dbh ->get_last_return_value ();
475456
476457 // Take note of the insert_id.
477458 if ( preg_match ( '/^\s*(insert|replace)\s/i ' , $ query ) ) {
@@ -516,11 +497,7 @@ public function query( $query ) {
516497 }
517498
518499 // 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- }
500+ $ this ->queries [ $ i ]['sqlite_queries ' ] = $ this ->dbh ->get_last_sqlite_queries ();
524501 }
525502 return $ return_val ;
526503 }
@@ -545,10 +522,6 @@ private function _do_query( $query ) {
545522 $ this ->last_error = $ this ->format_error_message ( $ e );
546523 }
547524
548- if ( $ this ->dbh instanceof WP_SQLite_Translator ) {
549- $ this ->last_error = $ this ->dbh ->get_error_message ();
550- }
551-
552525 ++$ this ->num_queries ;
553526
554527 if ( defined ( 'SAVEQUERIES ' ) && SAVEQUERIES ) {
@@ -573,27 +546,23 @@ protected function load_col_info() {
573546 if ( $ this ->col_info ) {
574547 return ;
575548 }
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 ();
549+ $ this ->col_info = array ();
550+ foreach ( $ this ->dbh ->get_last_column_meta () as $ column ) {
551+ $ this ->col_info [] = (object ) array (
552+ 'name ' => $ column ['name ' ],
553+ 'orgname ' => $ column ['mysqli:orgname ' ],
554+ 'table ' => $ column ['table ' ],
555+ 'orgtable ' => $ column ['mysqli:orgtable ' ],
556+ 'def ' => '' , // Unused, always ''.
557+ 'db ' => $ column ['mysqli:db ' ],
558+ 'catalog ' => 'def ' , // Unused, always 'def'.
559+ 'max_length ' => 0 , // As of PHP 8.1, this is always 0.
560+ 'length ' => $ column ['len ' ],
561+ 'charsetnr ' => $ column ['mysqli:charsetnr ' ],
562+ 'flags ' => $ column ['mysqli:flags ' ],
563+ 'type ' => $ column ['mysqli:type ' ],
564+ 'decimals ' => $ column ['precision ' ],
565+ );
597566 }
598567 }
599568
0 commit comments