Skip to content

Commit 990a4e2

Browse files
authored
Implement DATABASE() function (#254)
Implements the `DATABASE()` function. This is needed for admin tools like Adminer, phpMyAdmin, and others.
1 parent 0700853 commit 990a4e2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3705,6 +3705,19 @@ public function testCurrentTimestamp() {
37053705
$this->assertQuery( 'DELETE FROM _dates WHERE option_value = CURRENT_TIMESTAMP()' );
37063706
}
37073707

3708+
public function testDatabaseFunction(): void {
3709+
$this->assertQuery( "SELECT DATABASE(), CONCAT('test-', (SELECT DATABASE()))" );
3710+
$this->assertEquals(
3711+
array(
3712+
(object) array(
3713+
'DATABASE()' => 'wp',
3714+
"CONCAT('test-', (SELECT DATABASE()))" => 'test-wp',
3715+
),
3716+
),
3717+
$this->engine->get_query_results()
3718+
);
3719+
}
3720+
37083721
public function testGroupByHaving() {
37093722
$this->assertQuery(
37103723
'CREATE TABLE _tmp_table (

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,8 @@ private function translate_runtime_function_call( WP_Parser_Node $node ): string
33543354
}
33553355

33563356
switch ( $child->id ) {
3357+
case WP_MySQL_Lexer::DATABASE_SYMBOL:
3358+
return $this->connection->quote( $this->db_name );
33573359
case WP_MySQL_Lexer::CURRENT_TIMESTAMP_SYMBOL:
33583360
case WP_MySQL_Lexer::NOW_SYMBOL:
33593361
/*

0 commit comments

Comments
 (0)