Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tolerate selecting MySQL system variables #109

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading