Skip to content

Commit c4a9241

Browse files
committed
Move application ID to WP_SQLite_DB class
1 parent 5e17388 commit c4a9241

6 files changed

Lines changed: 22 additions & 25 deletions

File tree

constants.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@
5252
}
5353
}
5454

55-
/**
56-
* The application ID identifying an SQLite database created by this driver.
57-
*
58-
* This value is stored in the SQLite database file header and can be used to
59-
* identify databases managed by this driver.
60-
*
61-
* See: https://www.sqlite.org/pragma.html#pragma_application_id
62-
*/
63-
define( 'SQLITE_DB_APPLICATION_ID', 3948349 );
64-
6555
// Allow enabling the SQLite AST driver via environment variable.
6656
if ( ! defined( 'WP_SQLITE_AST_DRIVER' ) && isset( $_ENV['WP_SQLITE_AST_DRIVER'] ) && 'true' === $_ENV['WP_SQLITE_AST_DRIVER'] ) {
6757
define( 'WP_SQLITE_AST_DRIVER', true );

tests/WP_SQLite_Driver_Tests.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ public function setUp(): void {
1515
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
1616

1717
$this->engine = new WP_SQLite_Driver(
18-
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
18+
new WP_SQLite_Connection(
19+
array(
20+
'pdo' => $this->sqlite,
21+
'application_id' => 42, // Test application ID.
22+
)
23+
),
1924
'wp'
2025
);
2126
$this->engine->query(
@@ -53,7 +58,7 @@ private function assertQueryError( $sql, $error_message ) {
5358

5459
public function testApplicationID() {
5560
$app_id = $this->sqlite->query( 'PRAGMA application_id' )->fetchColumn();
56-
$this->assertSame( SQLITE_DB_APPLICATION_ID, (int) $app_id );
61+
$this->assertSame( 42, (int) $app_id );
5762
}
5863

5964
public function testRegexp() {

tests/WP_SQLite_Translator_Tests.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ private function assertQuery( $sql, $error_substring = null ) {
5757
return $retval;
5858
}
5959

60-
public function testApplicationID() {
61-
$app_id = $this->sqlite->query( 'PRAGMA application_id' )->fetchColumn();
62-
$this->assertSame( SQLITE_DB_APPLICATION_ID, (int) $app_id );
63-
}
64-
6560
public function testRegexp() {
6661
$this->assertQuery(
6762
"INSERT INTO _options (option_name, option_value) VALUES ('rss_0123456789abcdef0123456789abcdef', '1');"

wp-includes/sqlite-ast/class-wp-sqlite-connection.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class WP_SQLite_Connection {
6363
* @type int|null $timeout Optional. SQLite timeout in seconds.
6464
* The time to wait for a writable lock.
6565
* @type string|null $journal_mode Optional. SQLite journal mode.
66+
* @type int|null $application_id Optional. SQLite application ID.
6667
* }
6768
*
6869
* @throws InvalidArgumentException When some connection options are invalid.
@@ -97,8 +98,9 @@ public function __construct( array $options ) {
9798
$this->query( 'PRAGMA journal_mode = ' . $journal_mode );
9899
}
99100

100-
// Set the application ID to identify this as a WordPress SQLite database.
101-
$this->query( 'PRAGMA application_id = ' . SQLITE_DB_APPLICATION_ID );
101+
if ( isset( $options['application_id'] ) ) {
102+
$this->query( 'PRAGMA application_id = ' . (int) $options['application_id'] );
103+
}
102104
}
103105

104106
/**

wp-includes/sqlite/class-wp-sqlite-db.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class WP_SQLite_DB extends wpdb {
3030
*/
3131
private $allow_unsafe_unquoted_parameters = true;
3232

33+
/**
34+
* The application ID for the SQLite database.
35+
*
36+
* @see https://www.sqlite.org/pragma.html#pragma_application_id
37+
*/
38+
const SQLITE_DB_APPLICATION_ID = 3948349;
39+
3340
/**
3441
* Connects to the SQLite database.
3542
*
@@ -343,9 +350,10 @@ public function db_connect( $allow_bail = true ) {
343350
try {
344351
$connection = new WP_SQLite_Connection(
345352
array(
346-
'pdo' => $pdo,
347-
'path' => FQDB,
348-
'journal_mode' => defined( 'SQLITE_JOURNAL_MODE' ) ? SQLITE_JOURNAL_MODE : null,
353+
'pdo' => $pdo,
354+
'path' => FQDB,
355+
'journal_mode' => defined( 'SQLITE_JOURNAL_MODE' ) ? SQLITE_JOURNAL_MODE : null,
356+
'application_id' => self::SQLITE_DB_APPLICATION_ID,
349357
)
350358
);
351359
$this->dbh = new WP_SQLite_Driver( $connection, $this->dbname );

wp-includes/sqlite/class-wp-sqlite-translator.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,6 @@ public function __construct( $pdo = null ) {
427427
if ( defined( 'SQLITE_JOURNAL_MODE' ) && in_array( SQLITE_JOURNAL_MODE, $valid_journal_modes, true ) ) {
428428
$this->pdo->query( 'PRAGMA journal_mode = ' . SQLITE_JOURNAL_MODE );
429429
}
430-
431-
// Set the application ID to identify this as a WordPress SQLite database.
432-
$this->pdo->query( 'PRAGMA application_id = ' . SQLITE_DB_APPLICATION_ID );
433430
}
434431

435432
/**

0 commit comments

Comments
 (0)