PluginProbe
SQLite Database Integration / 3.1.0
SQLite Database Integration v3.1.0
3.1.0 3.0.2 3.0.1 trunk 2.1.13 2.1.14 2.1.15 2.1.16 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.2.2 2.2.20 2.2.21 2.2.22 2.2.23 All 33 releases
← All changes | wp-includes/sqlite/db.php +72 -50 2.1.16 → 3.1.0 View file →
@@ -1,65 +1,87 @@
1 1 <?php
2 2 /**
3 3 * Main integration file.
4 - *
5 - * @package wp-sqlite-integration
6 - * @since 1.0.0
7 4 */
8 5
9 -// Require the constants file.
10 -require_once dirname( __DIR__, 2 ) . '/constants.php';
6 +/**
7 + * Load the "SQLITE_DRIVER_VERSION" constant.
8 + */
9 +require_once __DIR__ . '/../database/version.php';
11 10
12 -// Bail early if DB_ENGINE is not defined as sqlite.
13 -if ( ! defined( 'DB_ENGINE' ) || 'sqlite' !== DB_ENGINE ) {
14 - return;
11 +try {
12 + // Require the constants file.
13 + require_once __DIR__ . '/../../constants.php';
14 +
15 + // Bail early if DB_ENGINE is not defined as sqlite.
16 + if ( ! defined( 'DB_ENGINE' ) || 'sqlite' !== DB_ENGINE ) {
17 + return;
18 + }
19 +
20 + if ( ! extension_loaded( 'pdo' ) ) {
21 + wp_die(
22 + new WP_Error(
23 + 'pdo_not_loaded',
24 + sprintf(
25 + '<h1>%1$s</h1><p>%2$s</p>',
26 + 'PHP PDO Extension is not loaded',
27 + 'Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress and the type of database you have specified.'
28 + )
29 + ),
30 + 'PHP PDO Extension is not loaded.'
31 + );
32 + }
33 +
34 + if ( ! extension_loaded( 'pdo_sqlite' ) ) {
35 + wp_die(
36 + new WP_Error(
37 + 'pdo_driver_not_loaded',
38 + sprintf(
39 + '<h1>%1$s</h1><p>%2$s</p>',
40 + 'PDO Driver for SQLite is missing',
41 + 'Your PHP installation appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.'
42 + )
43 + ),
44 + 'PDO Driver for SQLite is missing.'
45 + );
46 + }
47 +
48 + require_once __DIR__ . '/class-wp-sqlite-storage.php';
49 +
50 + if ( defined( 'DB_PATH' ) ) {
51 + $database_storage = WP_SQLite_Storage::with_explicit_path( DB_PATH );
52 + } elseif ( defined( 'FQDB' ) ) {
53 + $database_storage = WP_SQLite_Storage::with_explicit_path( FQDB );
54 + } else {
55 + $database_storage = WP_SQLite_Storage::with_secret_path( FQDBDIR );
56 + }
57 + $database_path = $database_storage->initialize();
58 +} catch ( Throwable $exception ) {
59 + error_log( 'SQLite database error: ' . (string) $exception );
60 +
61 + // WP-CLI can load the drop-in before wp_die() dependencies are available.
62 + if ( defined( 'WP_CLI' ) && WP_CLI ) {
63 + WP_CLI::error( $exception->getMessage() );
64 + }
65 +
66 + // Use htmlspecialchars() with an explicit charset because esc_html() reads the
67 + // blog_charset option, but the database and object cache are not initialized yet.
68 + wp_die( htmlspecialchars( $exception->getMessage(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8' ), 'SQLite database error', array( 'response' => 503 ) );
15 69 }
16 70
17 -if ( ! extension_loaded( 'pdo' ) ) {
18 - wp_die(
19 - new WP_Error(
20 - 'pdo_not_loaded',
21 - sprintf(
22 - '<h1>%1$s</h1><p>%2$s</p>',
23 - 'PHP PDO Extension is not loaded',
24 - 'Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress and the type of database you have specified.'
25 - )
26 - ),
27 - 'PHP PDO Extension is not loaded.'
28 - );
71 +if ( ! defined( 'DB_PATH' ) ) {
72 + define( 'DB_PATH', $database_path );
29 73 }
30 74
31 -if ( ! extension_loaded( 'pdo_sqlite' ) ) {
32 - wp_die(
33 - new WP_Error(
34 - 'pdo_driver_not_loaded',
35 - sprintf(
36 - '<h1>%1$s</h1><p>%2$s</p>',
37 - 'PDO Driver for SQLite is missing',
38 - 'Your PHP installation appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.'
39 - )
40 - ),
41 - 'PDO Driver for SQLite is missing.'
42 - );
75 +if ( ! defined( 'FQDB' ) ) {
76 + define( 'FQDB', $database_path );
43 77 }
44 78
45 -require_once __DIR__ . '/class-wp-sqlite-lexer.php';
46 -require_once __DIR__ . '/class-wp-sqlite-query-rewriter.php';
47 -require_once __DIR__ . '/class-wp-sqlite-translator.php';
48 -require_once __DIR__ . '/class-wp-sqlite-token.php';
49 -require_once __DIR__ . '/class-wp-sqlite-pdo-user-defined-functions.php';
79 +require_once __DIR__ . '/../database/load.php';
50 80 require_once __DIR__ . '/class-wp-sqlite-db.php';
51 81 require_once __DIR__ . '/install-functions.php';
52 82
53 -/*
54 - * Debug: Cross-check with MySQL.
55 - * This is for debugging purpose only and requires files
56 - * that are present in the GitHub repository
57 - * but not the plugin published on WordPress.org.
58 - */
59 -$crosscheck_tests_file_path = dirname( __DIR__, 2 ) . '/tests/class-wp-sqlite-crosscheck-db.php';
60 -if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK && file_exists( $crosscheck_tests_file_path ) ) {
61 - require_once $crosscheck_tests_file_path;
62 - $GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB();
63 -} else {
64 - $GLOBALS['wpdb'] = new WP_SQLite_DB();
65 -}
83 +$db_name = defined( 'DB_NAME' ) ? DB_NAME : '';
84 +$GLOBALS['wpdb'] = new WP_SQLite_DB( $db_name );
85 +
86 +// Boot the Query Monitor plugin if it is active.
87 +require_once __DIR__ . '/../../integrations/query-monitor/boot.php';