WPDB: get_table_from_query()
didn't find table names with hyphens in them.
Props dustinbolton for the fix. Fixes #33470. git-svn-id: https://develop.svn.wordpress.org/trunk@33718 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
83476bb77f
commit
bf3d36e0b6
@ -2870,7 +2870,7 @@ class wpdb {
|
||||
. '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
|
||||
. '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
|
||||
. '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
|
||||
. ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
|
||||
. ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
|
||||
return str_replace( '`', '', $maybe[1] );
|
||||
}
|
||||
|
||||
@ -2878,7 +2878,7 @@ class wpdb {
|
||||
if ( preg_match( '/^\s*(?:'
|
||||
. 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
|
||||
. '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
|
||||
. ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
|
||||
. ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
|
||||
return str_replace( '`', '', $maybe[1] );
|
||||
}
|
||||
|
||||
@ -2897,7 +2897,7 @@ class wpdb {
|
||||
. '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE'
|
||||
. '|(?:GRANT|REVOKE).*ON\s+TABLE'
|
||||
. '|SHOW\s+(?:.*FROM|.*TABLE)'
|
||||
. ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
|
||||
. ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
|
||||
return str_replace( '`', '', $maybe[1] );
|
||||
}
|
||||
|
||||
|
@ -526,7 +526,11 @@ class Tests_DB extends WP_UnitTestCase {
|
||||
*/
|
||||
function data_get_table_from_query() {
|
||||
$table = 'a_test_table_name';
|
||||
$db_table = '`a_test_db`.`another_test_table`';
|
||||
$more_tables = array(
|
||||
// table_name => expected_value
|
||||
'`a_test_db`.`another_test_table`' => 'a_test_db.another_test_table',
|
||||
'a-test-with-dashes' => 'a-test-with-dashes',
|
||||
);
|
||||
|
||||
$queries = array(
|
||||
// Basic
|
||||
@ -636,11 +640,12 @@ class Tests_DB extends WP_UnitTestCase {
|
||||
|
||||
$querycount = count( $queries );
|
||||
for ( $ii = 0; $ii < $querycount; $ii++ ) {
|
||||
$db_query = str_replace( $table, $db_table, $queries[ $ii ] );
|
||||
$expected_db_table = str_replace( '`', '', $db_table );
|
||||
foreach ( $more_tables as $name => $expected_name ) {
|
||||
$new_query = str_replace( $table, $name, $queries[ $ii ] );
|
||||
$queries[] = array( $new_query, $expected_name );
|
||||
}
|
||||
|
||||
$queries[ $ii ] = array( $queries[ $ii ], $table );
|
||||
$queries[] = array( $db_query, $expected_db_table );
|
||||
}
|
||||
return $queries;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user