Skip to content

Commit f237134

Browse files
Tolerate selecting MySQL system variables (#109)
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."
1 parent 23ed221 commit f237134

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

tests/WP_SQLite_Translator_Tests.php

+29
Original file line numberDiff line numberDiff line change
@@ -2247,4 +2247,33 @@ public function testDefaultNullValue() {
22472247
$result
22482248
);
22492249
}
2250+
2251+
/**
2252+
* @dataProvider mysqlVariablesToTest
2253+
*/
2254+
public function testSelectVariable( $variable_name ) {
2255+
// Make sure the query does not error
2256+
$this->assertQuery( "SELECT $variable_name;" );
2257+
}
2258+
2259+
public static function mysqlVariablesToTest() {
2260+
return array(
2261+
// NOTE: This list was derived from the variables used by the UpdraftPlus plugin.
2262+
// We will start here and plan to expand supported variables over time.
2263+
array( '@@character_set_client' ),
2264+
array( '@@character_set_results' ),
2265+
array( '@@collation_connection' ),
2266+
array( '@@GLOBAL.gtid_purged' ),
2267+
array( '@@GLOBAL.log_bin' ),
2268+
array( '@@GLOBAL.log_bin_trust_function_creators' ),
2269+
array( '@@GLOBAL.sql_mode' ),
2270+
array( '@@SESSION.max_allowed_packet' ),
2271+
array( '@@SESSION.sql_mode' ),
2272+
2273+
// Intentionally mix letter casing to help demonstrate case-insensitivity
2274+
array( '@@cHarActer_Set_cLient' ),
2275+
array( '@@gLoBAL.gTiD_purGed' ),
2276+
array( '@@sEssIOn.sqL_moDe' ),
2277+
);
2278+
}
22502279
}

wp-includes/sqlite/class-wp-sqlite-translator.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,9 @@ private function execute_select() {
14531453
$updated_query = $this->get_information_schema_query( $updated_query );
14541454
$params = array();
14551455
} elseif (
1456-
strpos( $updated_query, '@@SESSION.sql_mode' ) !== false
1457-
|| strpos( $updated_query, 'CONVERT( ' ) !== false
1456+
// Examples: @@SESSION.sql_mode, @@GLOBAL.max_allowed_packet, @@character_set_client
1457+
preg_match( '/@@((SESSION|GLOBAL)\s*\.\s*)?\w+\b/i', $updated_query ) === 1 ||
1458+
strpos( $updated_query, 'CONVERT( ' ) !== false
14581459
) {
14591460
/*
14601461
* If the query contains a function that is not supported by SQLite,

0 commit comments

Comments
 (0)