Skip to content

Commit 5464bee

Browse files
committed
Report version through SHOW VARIABLES
1 parent 0aa38eb commit 5464bee

2 files changed

Lines changed: 42 additions & 26 deletions

File tree

‎packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php‎

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,31 +3273,7 @@ private function execute_show_statement( WP_Parser_Node $node ): void {
32733273
$this->execute_show_tables_statement( $node );
32743274
return;
32753275
case WP_MySQL_Lexer::VARIABLES_SYMBOL:
3276-
$this->last_column_meta = array(
3277-
array(
3278-
'native_type' => 'STRING',
3279-
'pdo_type' => PDO::PARAM_STR,
3280-
'flags' => array( 'not_null' ),
3281-
'table' => 'session_variables',
3282-
'name' => 'Variable_name',
3283-
'len' => 256,
3284-
'precision' => 0,
3285-
),
3286-
array(
3287-
'native_type' => 'STRING',
3288-
'pdo_type' => PDO::PARAM_STR,
3289-
'flags' => array(),
3290-
'table' => 'session_variables',
3291-
'name' => 'Value',
3292-
'len' => 4096,
3293-
'precision' => 0,
3294-
),
3295-
);
3296-
$this->last_result_statement = $this->create_result_statement_from_data(
3297-
array_column( $this->last_column_meta, 'name' ),
3298-
array()
3299-
);
3300-
$this->found_rows = 0;
3276+
$this->execute_show_variables_statement( $node );
33013277
return;
33023278
}
33033279

@@ -3310,6 +3286,39 @@ private function execute_show_statement( WP_Parser_Node $node ): void {
33103286
);
33113287
}
33123288

3289+
/**
3290+
* Translate and execute a MySQL SHOW VARIABLES statement in SQLite.
3291+
*
3292+
* @param WP_Parser_Node $node The "showStatement" AST node.
3293+
*/
3294+
private function execute_show_variables_statement( WP_Parser_Node $node ): void {
3295+
$like_or_where = $node->get_first_child_node( 'likeOrWhere' );
3296+
if ( null !== $like_or_where ) {
3297+
$condition = $this->translate_show_like_or_where_condition( $like_or_where, 'Variable_name' );
3298+
}
3299+
3300+
$query = sprintf(
3301+
"SELECT column1 AS `Variable_name`, column2 AS `Value`
3302+
FROM (
3303+
VALUES
3304+
('version', ?),
3305+
('version_comment', ?)
3306+
)
3307+
WHERE TRUE %s
3308+
ORDER BY column1",
3309+
$condition ?? ''
3310+
);
3311+
$params = array(
3312+
$this->get_mysql_server_version_string(),
3313+
$this->get_mysql_server_version_comment(),
3314+
);
3315+
3316+
$stmt = $this->execute_sqlite_query( $query, $params );
3317+
$this->store_last_column_meta_from_statement( $stmt );
3318+
$this->last_result_statement = $stmt;
3319+
$this->found_rows = array( $query, $params );
3320+
}
3321+
33133322
/**
33143323
* Translate and execute a MySQL SHOW COLLATION statement in SQLite.
33153324
*

‎packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3895,7 +3895,14 @@ public function testShowIndex() {
38953895
public function testShowVarianles(): void {
38963896
$this->assertQuery( 'SHOW VARIABLES' );
38973897
$this->assertQuery( "SHOW VARIABLES LIKE 'version'" );
3898+
$this->assertSame( 'version', $this->last_result[0]->Variable_name );
3899+
$this->assertSame( '8.0.38-mysql-on-sqlite-' . SQLITE_DRIVER_VERSION, $this->last_result[0]->Value );
3900+
$this->assertQuery( "SHOW VARIABLES LIKE 'version_comment'" );
3901+
$this->assertSame( 'version_comment', $this->last_result[0]->Variable_name );
3902+
$this->assertSame( 'MySQL on SQLite', $this->last_result[0]->Value );
38983903
$this->assertQuery( "SHOW VARIABLES WHERE Variable_name = 'version'" );
3904+
$this->assertSame( 'version', $this->last_result[0]->Variable_name );
3905+
$this->assertSame( '8.0.38-mysql-on-sqlite-' . SQLITE_DRIVER_VERSION, $this->last_result[0]->Value );
38993906
$this->assertQuery( 'SHOW GLOBAL VARIABLES' );
39003907
$this->assertQuery( 'SHOW SESSION VARIABLES' );
39013908
}
@@ -4058,7 +4065,7 @@ public function testFoundRowsWithoutSqlCalcFoundRows(): void {
40584065
// SHOW VARIABLES
40594066
$this->assertQuery( 'SHOW VARIABLES' );
40604067
$result = $this->assertQuery( 'SELECT FOUND_ROWS()' );
4061-
$this->assertSame( '0', $result[0]->{'FOUND_ROWS()'} );
4068+
$this->assertSame( '2', $result[0]->{'FOUND_ROWS()'} );
40624069
}
40634070

40644071
public function testComplexSelectBasedOnDates() {

0 commit comments

Comments
 (0)