Skip to content

Commit 6be220d

Browse files
committed
Handle system variables
1 parent b8b4500 commit 6be220d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tests/WP_SQLite_Driver_Translation_Tests.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,23 @@ public function testDataTypes(): void {
294294
);
295295
}
296296

297+
public function testSystemVariables(): void {
298+
$this->assertQuery(
299+
'SELECT NULL',
300+
'SELECT @@sql_mode'
301+
);
302+
303+
$this->assertQuery(
304+
'SELECT NULL',
305+
'SELECT @@SESSION.sql_mode'
306+
);
307+
308+
$this->assertQuery(
309+
'SELECT NULL',
310+
'SELECT @@GLOBAL.sql_mode'
311+
);
312+
}
313+
297314
private function assertQuery( $expected, string $query ): void {
298315
$driver = new WP_SQLite_Driver( new PDO( 'sqlite::memory:' ) );
299316
$driver->query( $query );

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,13 @@ private function translate( $ast ) {
862862
throw $this->not_supported_exception(
863863
sprintf( 'data type: %s', $child->value )
864864
);
865+
case 'systemVariable':
866+
// @TODO: Emulate some system variables, or use reasonable defaults.
867+
// See: https://dev.mysql.com/doc/refman/8.4/en/server-system-variable-reference.html
868+
// See: https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html
869+
870+
// When we have no value, it's reasonable to use NULL.
871+
return 'NULL';
865872
default:
866873
return $this->translate_sequence( $ast->get_children() );
867874
}

0 commit comments

Comments
 (0)