Skip to content

Commit

Permalink
Tolerate selecting MySQL system variables (#109)
Browse files Browse the repository at this point in the history
The purpose of this PR is to avoid errors when selecting MySQL system variables. Fixes #104.

Related to:
WordPress/wordpress-playground#1272 -
"UpdraftPlus plugins doesn't fully work in Playground."
  • Loading branch information
brandonpayton authored May 1, 2024
1 parent 23ed221 commit f237134
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
29 changes: 29 additions & 0 deletions tests/WP_SQLite_Translator_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2247,4 +2247,33 @@ public function testDefaultNullValue() {
$result
);
}

/**
* @dataProvider mysqlVariablesToTest
*/
public function testSelectVariable( $variable_name ) {
// Make sure the query does not error
$this->assertQuery( "SELECT $variable_name;" );
}

public static function mysqlVariablesToTest() {
return array(
// NOTE: This list was derived from the variables used by the UpdraftPlus plugin.
// We will start here and plan to expand supported variables over time.
array( '@@character_set_client' ),
array( '@@character_set_results' ),
array( '@@collation_connection' ),
array( '@@GLOBAL.gtid_purged' ),
array( '@@GLOBAL.log_bin' ),
array( '@@GLOBAL.log_bin_trust_function_creators' ),
array( '@@GLOBAL.sql_mode' ),
array( '@@SESSION.max_allowed_packet' ),
array( '@@SESSION.sql_mode' ),

// Intentionally mix letter casing to help demonstrate case-insensitivity
array( '@@cHarActer_Set_cLient' ),
array( '@@gLoBAL.gTiD_purGed' ),
array( '@@sEssIOn.sqL_moDe' ),
);
}
}
5 changes: 3 additions & 2 deletions wp-includes/sqlite/class-wp-sqlite-translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1453,8 +1453,9 @@ private function execute_select() {
$updated_query = $this->get_information_schema_query( $updated_query );
$params = array();
} elseif (
strpos( $updated_query, '@@SESSION.sql_mode' ) !== false
|| strpos( $updated_query, 'CONVERT( ' ) !== false
// Examples: @@SESSION.sql_mode, @@GLOBAL.max_allowed_packet, @@character_set_client
preg_match( '/@@((SESSION|GLOBAL)\s*\.\s*)?\w+\b/i', $updated_query ) === 1 ||
strpos( $updated_query, 'CONVERT( ' ) !== false
) {
/*
* If the query contains a function that is not supported by SQLite,
Expand Down

0 comments on commit f237134

Please sign in to comment.