| @@ -305,37 +305,23 @@ | ||
| 305 | 305 | $pdo = null; |
| 306 | 306 | if ( isset( $GLOBALS['@pdo'] ) ) { |
| 307 | 307 | $pdo = $GLOBALS['@pdo']; |
| 308 | 308 | } |
| 309 | - | |
| 310 | - // Migrate the database file from a legacy path, if it exists. | |
| 311 | - if ( ! defined( 'DB_FILE' ) && ! file_exists( FQDB ) ) { | |
| 312 | - $old_db_path = FQDBDIR . '.ht.sqlite.php'; | |
| 313 | - | |
| 314 | - if ( file_exists( $old_db_path ) ) { | |
| 315 | - if ( ! rename( $old_db_path, FQDB ) ) { | |
| 316 | - wp_die( 'Failed to rename database file.', 'Error!' ); | |
| 317 | - } | |
| 318 | - | |
| 319 | - foreach ( array( '-wal', '-shm', '-journal' ) as $suffix ) { | |
| 320 | - if ( file_exists( $old_db_path . $suffix ) ) { | |
| 321 | - if ( ! rename( $old_db_path . $suffix, FQDB . $suffix ) ) { | |
| 322 | - wp_die( 'Failed to rename database file.', 'Error!' ); | |
| 323 | - } | |
| 324 | - } | |
| 325 | - } | |
| 326 | - } | |
| 327 | - } | |
| 328 | - | |
| 329 | 309 | 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 | - } | |
| 337 | - | |
| 310 | + require_once __DIR__ . '/../../wp-includes/parser/class-wp-parser-grammar.php'; | |
| 311 | + require_once __DIR__ . '/../../wp-includes/parser/class-wp-parser.php'; | |
| 312 | + require_once __DIR__ . '/../../wp-includes/parser/class-wp-parser-node.php'; | |
| 313 | + require_once __DIR__ . '/../../wp-includes/parser/class-wp-parser-token.php'; | |
| 314 | + require_once __DIR__ . '/../../wp-includes/mysql/class-wp-mysql-token.php'; | |
| 315 | + require_once __DIR__ . '/../../wp-includes/mysql/class-wp-mysql-lexer.php'; | |
| 316 | + require_once __DIR__ . '/../../wp-includes/mysql/class-wp-mysql-parser.php'; | |
| 317 | + require_once __DIR__ . '/../../wp-includes/sqlite-ast/class-wp-sqlite-connection.php'; | |
| 318 | + require_once __DIR__ . '/../../wp-includes/sqlite-ast/class-wp-sqlite-configurator.php'; | |
| 319 | + require_once __DIR__ . '/../../wp-includes/sqlite-ast/class-wp-sqlite-driver.php'; | |
| 320 | + require_once __DIR__ . '/../../wp-includes/sqlite-ast/class-wp-sqlite-driver-exception.php'; | |
| 321 | + require_once __DIR__ . '/../../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php'; | |
| 322 | + require_once __DIR__ . '/../../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-exception.php'; | |
| 323 | + require_once __DIR__ . '/../../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-reconstructor.php'; | |
| 338 | 324 | $this->ensure_database_directory( FQDB ); |
| 339 | 325 | |
| 340 | 326 | try { |
| 341 | 327 | $connection = new WP_SQLite_Connection( |
| @@ -413,14 +399,8 @@ | ||
| 413 | 399 | * @return int|bool Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows |
| 414 | 400 | * affected/selected for all other queries. Boolean false on error. |
| 415 | 401 | */ |
| 416 | 402 | public function query( $query ) { |
| 417 | - // Query Monitor integration: | |
| 418 | - $query_monitor_active = defined( 'SQLITE_QUERY_MONITOR_LOADED' ) && SQLITE_QUERY_MONITOR_LOADED; | |
| 419 | - if ( $query_monitor_active && $this->show_errors ) { | |
| 420 | - $this->hide_errors(); | |
| 421 | - } | |
| 422 | - | |
| 423 | 403 | if ( ! $this->ready ) { |
| 424 | 404 | return false; |
| 425 | 405 | } |
| 426 | 406 | |
| @@ -438,11 +418,8 @@ | ||
| 438 | 418 | |
| 439 | 419 | // Keep track of the last query for debug. |
| 440 | 420 | $this->last_query = $query; |
| 441 | 421 | |
| 442 | - // Save the query count before running another query. | |
| 443 | - $last_query_count = count( $this->queries ?? array() ); | |
| 444 | - | |
| 445 | 422 | /* |
| 446 | 423 | * @TODO: WPDB uses "$this->check_current_query" to check table/column |
| 447 | 424 | * charset and strip all invalid characters from the query. |
| 448 | 425 | * This is an involved process that we can bypass for SQLite, |
| @@ -492,37 +469,8 @@ | ||
| 492 | 469 | $this->num_rows = $num_rows; |
| 493 | 470 | $return_val = $num_rows; |
| 494 | 471 | } |
| 495 | 472 | |
| 496 | - // Query monitor integration: | |
| 497 | - if ( $query_monitor_active && class_exists( 'QM_Backtrace' ) ) { | |
| 498 | - if ( did_action( 'qm/cease' ) ) { | |
| 499 | - $this->queries = array(); | |
| 500 | - } | |
| 501 | - | |
| 502 | - $i = $last_query_count; | |
| 503 | - if ( ! isset( $this->queries[ $i ] ) ) { | |
| 504 | - return $return_val; | |
| 505 | - } | |
| 506 | - | |
| 507 | - $this->queries[ $i ]['trace'] = new QM_Backtrace(); | |
| 508 | - if ( ! isset( $this->queries[ $i ][3] ) ) { | |
| 509 | - $this->queries[ $i ][3] = $this->time_start; | |
| 510 | - } | |
| 511 | - | |
| 512 | - if ( $this->last_error && ! $this->suppress_errors ) { | |
| 513 | - $this->queries[ $i ]['result'] = new WP_Error( 'qmdb', $this->last_error ); | |
| 514 | - } else { | |
| 515 | - $this->queries[ $i ]['result'] = (int) $return_val; | |
| 516 | - } | |
| 517 | - | |
| 518 | - // 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 | - } | |
| 524 | - } | |
| 525 | 473 | return $return_val; |
| 526 | 474 | } |
| 527 | 475 | |
| 528 | 476 | /** |
| @@ -572,30 +520,9 @@ | ||
| 572 | 520 | protected function load_col_info() { |
| 573 | 521 | if ( $this->col_info ) { |
| 574 | 522 | return; |
| 575 | 523 | } |
| 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(); | |
| 597 | - } | |
| 524 | + $this->col_info = $this->dbh->get_columns(); | |
| 598 | 525 | } |
| 599 | 526 | |
| 600 | 527 | /** |
| 601 | 528 | * Method to return what the database can do. |