/**
 * 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;
}
 /**
  * Test for PMA_getTableReferences
  *
  * @return void
  */
 function testPMAGetTableReferences()
 {
     $sql_query = 'UPDATE `table_1` AS t1, `table_2` t2, `table_3` AS t3 ' . 'SET `table_1`.`id` = `table_2`.`id` ' . 'WHERE 1';
     $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);
     $table_references = PMA_getTableReferences($analyzed_sql_results);
     $this->assertEquals(' `table_1` AS t1 , `table_2` t2 , `table_3` AS t3', $table_references);
 }