Changeset 2350018
- Timestamp:
- 07/31/2020 06:36:23 PM (6 years ago)
- File:
-
- 1 edited
-
hyperdb/trunk/db.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
hyperdb/trunk/db.php
r2210508 r2350018 267 267 268 268 /** 269 * Find the first table name referenced in a query 269 * Find the table to be used for query routing. Falls back on 270 * core get_table_from_query after checking for special cases. 270 271 * @param string query 271 272 * @return string table … … 280 281 $q = preg_replace( '/\((?!\s*select)[^(]*?\)/is', '()', substr( $q, 0, 1500 ) ); 281 282 282 // Refer to the previous query 283 // wpdb doesn't implement last_table, so we run it first. 283 // SELECT FOUND_ROWS() refers to the previous SELECT query 284 284 if ( preg_match('/^\s*SELECT.*?\s+FOUND_ROWS\(\)/is', $q) ) 285 285 return $this->last_table; 286 286 287 if( method_exists( get_parent_class( $this ), 'get_table_from_query' ) ) { 288 // WPDB has added support for get_table_from_query, which should take precedence 289 return parent::get_table_from_query( $q ); 290 } 291 292 // Quickly match most common queries 293 if ( preg_match('/^\s*(?:' 294 . 'SELECT.*?\s+FROM' 295 . '|INSERT(?:\s+IGNORE)?(?:\s+INTO)?' 296 . '|REPLACE(?:\s+INTO)?' 297 . '|UPDATE(?:\s+IGNORE)?' 298 . '|DELETE(?:\s+IGNORE)?(?:\s+FROM)?' 299 . ')\s+`?([\w-]+)`?/is', $q, $maybe) ) 287 // SELECT FROM information_schema.* WHERE TABLE_NAME = 'wp_12345_foo' 288 if ( preg_match('/^\s*' 289 . 'SELECT.*?\s+FROM\s+`?information_schema`?\.' 290 . '.*\s+TABLE_NAME\s*=\s*["\']([\w-]+)["\']/is', $q, $maybe) ) 300 291 return $maybe[1]; 301 292 302 // SHOW TABLE STATUS and SHOW TABLES 303 if ( preg_match('/^\s*(?:' 304 . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' 305 . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' 306 . ')\W([\w-]+)\W/is', $q, $maybe) ) 293 // Transaction support, requires a table hint via comment: IN_TABLE=table_name 294 if ( preg_match('/^\s*' 295 . '(?:START\s+TRANSACTION|COMMIT|ROLLBACK)\s*\/[*]\s*IN_TABLE\s*=\s*' 296 . "'?([\w-]+)'?/is", $q, $maybe) ) { 307 297 return $maybe[1]; 308 309 // Big pattern for the rest of the table-related queries in MySQL 5.0 310 if ( preg_match('/^\s*(?:' 311 . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM' 312 . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?' 313 . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?' 314 . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?' 315 . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?' 316 . '|DESCRIBE|DESC|EXPLAIN|HANDLER' 317 . '|(?:LOCK|UNLOCK)\s+TABLE(?:S)?' 318 . '|(?:RENAME|OPTIMIZE|BACKUP|RESTORE|CHECK|CHECKSUM|ANALYZE|OPTIMIZE|REPAIR).*\s+TABLE' 319 . '|TRUNCATE(?:\s+TABLE)?' 320 . '|CREATE(?:\s+TEMPORARY)?\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?' 321 . '|ALTER(?:\s+IGNORE)?\s+TABLE' 322 . '|DROP\s+TABLE(?:\s+IF\s+EXISTS)?' 323 . '|CREATE(?:\s+\w+)?\s+INDEX.*\s+ON' 324 . '|DROP\s+INDEX.*\s+ON' 325 . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE' 326 . '|(?:GRANT|REVOKE).*ON\s+TABLE' 327 . '|SHOW\s+(?:.*FROM|.*TABLE)' 328 . ')\s+`?([\w-]+)`?/is', $q, $maybe) ) 329 return $maybe[1]; 298 } 299 300 return $this->last_table = parent::get_table_from_query( $q ); 330 301 } 331 302 … … 380 351 return false; 381 352 382 $this-> last_table = $this->table = $this->get_table_from_query($query);353 $this->table = $this->get_table_from_query($query); 383 354 384 355 if ( isset($this->hyper_tables[$this->table]) ) {
Note: See TracChangeset
for help on using the changeset viewer.