Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 53eb81e

Browse files
committed
Use a unified prefix for internal objects
1 parent 677bca4 commit 53eb81e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,17 +1249,17 @@ public function testColumnWithOnUpdate() {
12491249
array(
12501250
(object) array(
12511251
'type' => 'trigger',
1252-
'name' => '___tmp_table_created_at_on_update__',
1252+
'name' => '_wp_sqlite__tmp_table_created_at_on_update',
12531253
'tbl_name' => '_tmp_table',
12541254
'rootpage' => '0',
1255-
'sql' => "CREATE TRIGGER \"___tmp_table_created_at_on_update__\"\n\t\t\tAFTER UPDATE ON \"_tmp_table\"\n\t\t\tFOR EACH ROW\n\t\t\tBEGIN\n\t\t\t UPDATE \"_tmp_table\" SET \"created_at\" = CURRENT_TIMESTAMP WHERE rowid = NEW.rowid;\n\t\t\tEND",
1255+
'sql' => "CREATE TRIGGER \"_wp_sqlite__tmp_table_created_at_on_update\"\n\t\t\tAFTER UPDATE ON \"_tmp_table\"\n\t\t\tFOR EACH ROW\n\t\t\tBEGIN\n\t\t\t UPDATE \"_tmp_table\" SET \"created_at\" = CURRENT_TIMESTAMP WHERE rowid = NEW.rowid;\n\t\t\tEND",
12561256
),
12571257
(object) array(
12581258
'type' => 'trigger',
1259-
'name' => '___tmp_table_updated_at_on_update__',
1259+
'name' => '_wp_sqlite__tmp_table_updated_at_on_update',
12601260
'tbl_name' => '_tmp_table',
12611261
'rootpage' => '0',
1262-
'sql' => "CREATE TRIGGER \"___tmp_table_updated_at_on_update__\"\n\t\t\tAFTER UPDATE ON \"_tmp_table\"\n\t\t\tFOR EACH ROW\n\t\t\tBEGIN\n\t\t\t UPDATE \"_tmp_table\" SET \"updated_at\" = CURRENT_TIMESTAMP WHERE rowid = NEW.rowid;\n\t\t\tEND",
1262+
'sql' => "CREATE TRIGGER \"_wp_sqlite__tmp_table_updated_at_on_update\"\n\t\t\tAFTER UPDATE ON \"_tmp_table\"\n\t\t\tFOR EACH ROW\n\t\t\tBEGIN\n\t\t\t UPDATE \"_tmp_table\" SET \"updated_at\" = CURRENT_TIMESTAMP WHERE rowid = NEW.rowid;\n\t\t\tEND",
12631263
),
12641264
),
12651265
$results

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ class WP_SQLite_Driver {
2121
const SQLITE_BUSY = 5;
2222
const SQLITE_LOCKED = 6;
2323

24+
/**
25+
* An identifier prefix for internal objects.
26+
*
27+
* @TODO: Do not allow accessing objects with this prefix.
28+
*/
29+
const RESERVED_PREFIX = '_wp_sqlite_';
30+
2431
/**
2532
* A map of MySQL tokens to SQLite data types.
2633
*
@@ -1244,7 +1251,7 @@ private function execute_alter_table_statement( WP_Parser_Node $node ): void {
12441251
$this->execute_sqlite_query( 'PRAGMA foreign_keys = OFF' );
12451252

12461253
// 2. Create a new table with the new schema.
1247-
$tmp_table_name = "_tmp__{$table_name}_" . uniqid();
1254+
$tmp_table_name = self::RESERVED_PREFIX . "tmp_{$table_name}_" . uniqid();
12481255
$quoted_table_name = $this->quote_sqlite_identifier( $table_name );
12491256
$quoted_tmp_table_name = $this->quote_sqlite_identifier( $tmp_table_name );
12501257
$queries = $this->get_sqlite_create_table_statement( $table_name, $tmp_table_name );
@@ -2277,7 +2284,7 @@ private function get_column_on_update_trigger_query( string $table, string $colu
22772284
// The trigger wouldn't work for virtual and "WITHOUT ROWID" tables,
22782285
// but currently that can't happen as we're not creating such tables.
22792286
// See: https://www.sqlite.org/rowidtable.html
2280-
$trigger_name = "__{$table}_{$column}_on_update__";
2287+
$trigger_name = self::RESERVED_PREFIX . "{$table}_{$column}_on_update";
22812288
return "
22822289
CREATE TRIGGER \"$trigger_name\"
22832290
AFTER UPDATE ON \"$table\"

0 commit comments

Comments
 (0)