コード例 #1
0
/**
 * Checks if ROLLBACK is possible for a SQL query or not.
 *
 * @param string $sql_query SQL query
 *
 * @return bool
 */
function PMA_checkIfRollbackPossible($sql_query)
{
    // Supported queries.
    $supported_queries = array('INSERT', 'UPDATE', 'DELETE', 'REPLACE');
    // Parse and Analyze the query.
    $parsed_sql = PMA_SQP_parse($sql_query);
    $analyzed_sql = PMA_SQP_analyze($parsed_sql);
    $analyzed_sql_results = array('parsed_sql' => $parsed_sql, 'analyzed_sql' => $analyzed_sql);
    // Get the query type.
    $query_type = isset($analyzed_sql_results['analyzed_sql'][0]['querytype']) ? $analyzed_sql_results['analyzed_sql'][0]['querytype'] : '';
    // Check if query is supported.
    if (!in_array($query_type, $supported_queries)) {
        return false;
    }
    // Get table_references from the query.
    $table_references = PMA_getTableReferences($analyzed_sql_results);
    $table_references = $table_references ? $table_references : '';
    // Get table names from table_references.
    $tables = PMA_getTableNamesFromTableReferences($table_references);
    // Check if each table is 'InnoDB'.
    foreach ($tables as $table) {
        if (!PMA_isTableTransactional($table)) {
            return false;
        }
    }
    return true;
}
コード例 #2
0
/**
 * Checks if ROLLBACK is possible for a SQL query or not.
 *
 * @param string $sql_query SQL query
 *
 * @return bool
 */
function PMA_checkIfRollbackPossible($sql_query)
{
    $parser = new SqlParser\Parser($sql_query);
    if (empty($parser->statements[0])) {
        return false;
    }
    $statement = $parser->statements[0];
    // Check if query is supported.
    if (!($statement instanceof SqlParser\Statements\InsertStatement || $statement instanceof SqlParser\Statements\UpdateStatement || $statement instanceof SqlParser\Statements\DeleteStatement || $statement instanceof SqlParser\Statements\ReplaceStatement)) {
        return false;
    }
    // Get table_references from the query.
    $tables = SqlParser\Utils\Query::getTables($statement);
    // Check if each table is 'InnoDB'.
    foreach ($tables as $table) {
        if (!PMA_isTableTransactional($table)) {
            return false;
        }
    }
    return true;
}