VaultPress::get_table_from_query PHP Method

get_table_from_query() public method

Emulate hyperdb::get_table_from_query()
public get_table_from_query ( $q )
    function get_table_from_query($q)
    {
        global $wpdb, $vaultpress_last_table;
        if (is_object($wpdb) && method_exists($wpdb, "get_table_from_query")) {
            return $wpdb->get_table_from_query($q);
        }
        // Remove characters that can legally trail the table name
        $q = rtrim($q, ';/-#');
        // allow ( select... ) union [...] style queries. Use the first queries table name.
        $q = ltrim($q, "\t (");
        // Quickly match most common queries
        if (preg_match('/^\\s*(?:' . 'SELECT.*?\\s+FROM' . '|INSERT(?:\\s+IGNORE)?(?:\\s+INTO)?' . '|REPLACE(?:\\s+INTO)?' . '|UPDATE(?:\\s+IGNORE)?' . '|DELETE(?:\\s+IGNORE)?(?:\\s+FROM)?' . ')\\s+`?(\\w+)`?/is', $q, $maybe)) {
            return $this->record_table($maybe[1]);
        }
        // Refer to the previous query
        if (preg_match('/^\\s*SELECT.*?\\s+FOUND_ROWS\\(\\)/is', $q)) {
            return $this->get_last_table();
        }
        // Big pattern for the rest of the table-related queries in MySQL 5.0
        if (preg_match('/^\\s*(?:' . '(?:EXPLAIN\\s+(?:EXTENDED\\s+)?)?SELECT.*?\\s+FROM' . '|INSERT(?:\\s+LOW_PRIORITY|\\s+DELAYED|\\s+HIGH_PRIORITY)?(?:\\s+IGNORE)?(?:\\s+INTO)?' . '|REPLACE(?:\\s+LOW_PRIORITY|\\s+DELAYED)?(?:\\s+INTO)?' . '|UPDATE(?:\\s+LOW_PRIORITY)?(?:\\s+IGNORE)?' . '|DELETE(?:\\s+LOW_PRIORITY|\\s+QUICK|\\s+IGNORE)*(?:\\s+FROM)?' . '|DESCRIBE|DESC|EXPLAIN|HANDLER' . '|(?:LOCK|UNLOCK)\\s+TABLE(?:S)?' . '|(?:RENAME|OPTIMIZE|BACKUP|RESTORE|CHECK|CHECKSUM|ANALYZE|OPTIMIZE|REPAIR).*\\s+TABLE' . '|TRUNCATE(?:\\s+TABLE)?' . '|CREATE(?:\\s+TEMPORARY)?\\s+TABLE(?:\\s+IF\\s+NOT\\s+EXISTS)?' . '|ALTER(?:\\s+IGNORE)?\\s+TABLE' . '|DROP\\s+TABLE(?:\\s+IF\\s+EXISTS)?' . '|CREATE(?:\\s+\\w+)?\\s+INDEX.*\\s+ON' . '|DROP\\s+INDEX.*\\s+ON' . '|LOAD\\s+DATA.*INFILE.*INTO\\s+TABLE' . '|(?:GRANT|REVOKE).*ON\\s+TABLE' . '|SHOW\\s+(?:.*FROM|.*TABLE)' . ')\\s+`?(\\w+)`?/is', $q, $maybe)) {
            return $this->record_table($maybe[1]);
        }
        // All unmatched queries automatically fall to the global master
        return $this->record_table('');
    }
VaultPress