Skip to content

Commit

Permalink
Handle system variables
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJakes committed Nov 21, 2024
1 parent b8b4500 commit 6be220d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/WP_SQLite_Driver_Translation_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,23 @@ public function testDataTypes(): void {
);
}

public function testSystemVariables(): void {
$this->assertQuery(
'SELECT NULL',
'SELECT @@sql_mode'
);

$this->assertQuery(
'SELECT NULL',
'SELECT @@SESSION.sql_mode'
);

$this->assertQuery(
'SELECT NULL',
'SELECT @@GLOBAL.sql_mode'
);
}

private function assertQuery( $expected, string $query ): void {
$driver = new WP_SQLite_Driver( new PDO( 'sqlite::memory:' ) );
$driver->query( $query );
Expand Down
7 changes: 7 additions & 0 deletions wp-includes/sqlite-ast/class-wp-sqlite-driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,13 @@ private function translate( $ast ) {
throw $this->not_supported_exception(
sprintf( 'data type: %s', $child->value )
);
case 'systemVariable':
// @TODO: Emulate some system variables, or use reasonable defaults.
// See: https://dev.mysql.com/doc/refman/8.4/en/server-system-variable-reference.html
// See: https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html

// When we have no value, it's reasonable to use NULL.
return 'NULL';
default:
return $this->translate_sequence( $ast->get_children() );
}
Expand Down

0 comments on commit 6be220d

Please sign in to comment.