isView() public method

returns whether the table is actually a view
public isView ( ) : boolean
return boolean whether the given is a view
Example #1
0
 /**
  * Set the content that needs to be shown in message
  *
  * @param string  $sorted_column_message the message for sorted column
  * @param array   $analyzed_sql_results  the analyzed query
  * @param integer $total                 the total number of rows returned by
  *                                       the SQL query without any
  *                                       programmatically appended LIMIT clause
  * @param integer $pos_next              the offset for next page
  * @param string  $pre_count             the string renders before row count
  * @param string  $after_count           the string renders after row count
  *
  * @return Message $message an object of Message
  *
  * @access  private
  *
  * @see     getTable()
  */
 private function _setMessageInformation($sorted_column_message, $analyzed_sql_results, $total, $pos_next, $pre_count, $after_count)
 {
     $unlim_num_rows = $this->__get('unlim_num_rows');
     // To use in isset()
     if (!empty($analyzed_sql_results['statement']->limit)) {
         $first_shown_rec = $analyzed_sql_results['statement']->limit->offset;
         $row_count = $analyzed_sql_results['statement']->limit->rowCount;
         if ($row_count < $total) {
             $last_shown_rec = $first_shown_rec + $row_count - 1;
         } else {
             $last_shown_rec = $first_shown_rec + $total - 1;
         }
     } elseif ($_SESSION['tmpval']['max_rows'] == self::ALL_ROWS || $pos_next > $total) {
         $first_shown_rec = $_SESSION['tmpval']['pos'];
         $last_shown_rec = $total - 1;
     } else {
         $first_shown_rec = $_SESSION['tmpval']['pos'];
         $last_shown_rec = $pos_next - 1;
     }
     $table = new Table($this->__get('table'), $this->__get('db'));
     if ($table->isView() && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
         $message = Message::notice(__('This view has at least this number of rows. ' . 'Please refer to %sdocumentation%s.'));
         $message->addParam('[doc@cfg_MaxExactCount]');
         $message->addParam('[/doc]');
         $message_view_warning = Util::showHint($message);
     } else {
         $message_view_warning = false;
     }
     $message = Message::success(__('Showing rows %1s - %2s'));
     $message->addParam($first_shown_rec);
     if ($message_view_warning !== false) {
         $message->addParam('... ' . $message_view_warning, false);
     } else {
         $message->addParam($last_shown_rec);
     }
     $message->addMessage('(');
     if ($message_view_warning === false) {
         if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
             $message_total = Message::notice($pre_count . __('%1$d total, %2$d in query'));
             $message_total->addParam($total);
             $message_total->addParam($unlim_num_rows);
         } else {
             $message_total = Message::notice($pre_count . __('%d total'));
             $message_total->addParam($total);
         }
         if (!empty($after_count)) {
             $message_total->addMessage($after_count);
         }
         $message->addMessage($message_total, '');
         $message->addMessage(', ', '');
     }
     $message_qt = Message::notice(__('Query took %01.4f seconds.') . ')');
     $message_qt->addParam($this->__get('querytime'));
     $message->addMessage($message_qt, '');
     if (!is_null($sorted_column_message)) {
         $message->addMessage($sorted_column_message, '');
     }
     return $message;
 }
Example #2
0
 /**
  * Test for isView
  *
  * @return void
  */
 public function testIsView()
 {
     $table = new Table(null, null);
     $this->assertEquals(false, $table->isView());
     //validate that it is the same as DBI fetchResult
     $table = new Table('PMA_BookMark', 'PMA');
     $this->assertEquals(true, $table->isView());
     $table = new Table('PMA_BookMark_2', 'PMA');
     $this->assertEquals(false, $table->isView());
 }
Example #3
0
/**
 * Export at the table level
 *
 * @param string       $db              the database to export
 * @param string       $table           the table to export
 * @param string       $whatStrucOrData structure or data or both
 * @param ExportPlugin $export_plugin   the selected export plugin
 * @param string       $crlf            end of line character(s)
 * @param string       $err_url         the URL in case of error
 * @param string       $export_type     the export type
 * @param bool         $do_relation     whether to export relation info
 * @param bool         $do_comments     whether to add comments
 * @param bool         $do_mime         whether to add MIME info
 * @param bool         $do_dates        whether to add dates
 * @param string       $allrows         whether "dump all rows" was ticked
 * @param string       $limit_to        upper limit
 * @param string       $limit_from      starting limit
 * @param string       $sql_query       query for which exporting is requested
 * @param array        $aliases         Alias information for db/table/column
 *
 * @return void
 */
function PMA_exportTable($db, $table, $whatStrucOrData, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $allrows, $limit_to, $limit_from, $sql_query, $aliases)
{
    $db_alias = !empty($aliases[$db]['alias']) ? $aliases[$db]['alias'] : '';
    if (!$export_plugin->exportDBHeader($db, $db_alias)) {
        return;
    }
    if (isset($allrows) && $allrows == '0' && $limit_to > 0 && $limit_from >= 0) {
        $add_query = ' LIMIT ' . ($limit_from > 0 ? $limit_from . ', ' : '') . $limit_to;
    } else {
        $add_query = '';
    }
    $_table = new Table($table, $db);
    $is_view = $_table->isView();
    if ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data') {
        if ($is_view) {
            if (isset($GLOBALS['sql_create_view'])) {
                if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'create_view', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) {
                    return;
                }
            }
        } else {
            if (isset($GLOBALS['sql_create_table'])) {
                if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'create_table', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) {
                    return;
                }
            }
        }
    }
    // If this is an export of a single view, we have to export data;
    // for example, a PDF report
    // if it is a merge table, no data is exported
    if ($whatStrucOrData == 'data' || $whatStrucOrData == 'structure_and_data') {
        if (!empty($sql_query)) {
            // only preg_replace if needed
            if (!empty($add_query)) {
                // remove trailing semicolon before adding a LIMIT
                $sql_query = preg_replace('%;\\s*$%', '', $sql_query);
            }
            $local_query = $sql_query . $add_query;
            $GLOBALS['dbi']->selectDb($db);
        } else {
            // Data is exported only for Non-generated columns
            $tableObj = new PMA\libraries\Table($table, $db);
            $nonGeneratedCols = $tableObj->getNonGeneratedColumns(true);
            $local_query = 'SELECT ' . implode(', ', $nonGeneratedCols) . ' FROM ' . PMA\libraries\Util::backquote($db) . '.' . PMA\libraries\Util::backquote($table) . $add_query;
        }
        if (!$export_plugin->exportData($db, $table, $crlf, $err_url, $local_query, $aliases)) {
            return;
        }
    }
    // now export the triggers (needs to be done after the data because
    // triggers can modify already imported tables)
    if (isset($GLOBALS['sql_create_trigger']) && ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data')) {
        if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'triggers', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) {
            return;
        }
    }
    if (!$export_plugin->exportDBFooter($db)) {
        return;
    }
    if (isset($GLOBALS['sql_metadata'])) {
        // Types of metadata to export.
        // In the future these can be allowed to be selected by the user
        $metadataTypes = PMA_getMetadataTypesToExport();
        $export_plugin->exportMetadata($db, $table, $metadataTypes);
    }
}
Example #4
0
 /**
  * Copies or renames table
  *
  * @param string $source_db    source database
  * @param string $source_table source table
  * @param string $target_db    target database
  * @param string $target_table target table
  * @param string $what         what to be moved or copied (data, dataonly)
  * @param bool   $move         whether to move
  * @param string $mode         mode
  *
  * @return bool true if success, false otherwise
  */
 public static function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode)
 {
     global $err_url;
     // Try moving the tables directly, using native `RENAME` statement.
     if ($move && $what == 'data') {
         $tbl = new Table($source_table, $source_db);
         if ($tbl->rename($target_table, $target_db)) {
             $GLOBALS['message'] = $tbl->getLastMessage();
             return true;
         }
     }
     // Setting required export settings.
     $GLOBALS['sql_backquotes'] = 1;
     $GLOBALS['asfile'] = 1;
     // Ensuring the target database is valid.
     if (!$GLOBALS['pma']->databases->exists($source_db, $target_db)) {
         if (!$GLOBALS['pma']->databases->exists($source_db)) {
             $GLOBALS['message'] = Message::rawError(sprintf(__('Source database `%s` was not found!'), htmlspecialchars($source_db)));
         }
         if (!$GLOBALS['pma']->databases->exists($target_db)) {
             $GLOBALS['message'] = Message::rawError(sprintf(__('Target database `%s` was not found!'), htmlspecialchars($target_db)));
         }
         return false;
     }
     /**
      * The full name of source table, quoted.
      * @var string $source
      */
     $source = Util::backquote($source_db) . '.' . Util::backquote($source_table);
     // If the target database is not specified, the operation is taking
     // place in the same database.
     if (!isset($target_db) || !mb_strlen($target_db)) {
         $target_db = $source_db;
     }
     // Selecting the database could avoid some problems with replicated
     // databases, when moving table from replicated one to not replicated one.
     $GLOBALS['dbi']->selectDb($target_db);
     /**
      * The full name of target table, quoted.
      * @var string $target
      */
     $target = Util::backquote($target_db) . '.' . Util::backquote($target_table);
     // No table is created when this is a data-only operation.
     if ($what != 'dataonly') {
         include_once "libraries/plugin_interface.lib.php";
         /**
          * Instance used for exporting the current structure of the table.
          *
          * @var \PMA\libraries\plugins\export\ExportSql
          */
         $export_sql_plugin = PMA_getPlugin("export", "sql", 'libraries/plugins/export/', array('export_type' => 'table', 'single_table' => false));
         $no_constraints_comments = true;
         $GLOBALS['sql_constraints_query'] = '';
         // set the value of global sql_auto_increment variable
         if (isset($_POST['sql_auto_increment'])) {
             $GLOBALS['sql_auto_increment'] = $_POST['sql_auto_increment'];
         }
         /**
          * The old structure of the table..
          * @var string $sql_structure
          */
         $sql_structure = $export_sql_plugin->getTableDef($source_db, $source_table, "\n", $err_url, false, false);
         unset($no_constraints_comments);
         // -----------------------------------------------------------------
         // Phase 0: Preparing structures used.
         /**
          * The destination where the table is moved or copied to.
          * @var Expression
          */
         $destination = new Expression($target_db, $target_table, '');
         // Find server's SQL mode so the builder can generate correct
         // queries.
         // One of the options that alters the behaviour is `ANSI_QUOTES`.
         Context::setMode($GLOBALS['dbi']->fetchValue("SELECT @@sql_mode"));
         // -----------------------------------------------------------------
         // Phase 1: Dropping existent element of the same name (if exists
         // and required).
         if (isset($_REQUEST['drop_if_exists']) && $_REQUEST['drop_if_exists'] == 'true') {
             /**
              * Drop statement used for building the query.
              * @var DropStatement $statement
              */
             $statement = new DropStatement();
             $tbl = new Table($target_db, $target_table);
             $statement->options = new OptionsArray(array($tbl->isView() ? 'VIEW' : 'TABLE', 'IF EXISTS'));
             $statement->fields = array($destination);
             // Building the query.
             $drop_query = $statement->build() . ';';
             // Executing it.
             $GLOBALS['dbi']->query($drop_query);
             $GLOBALS['sql_query'] .= "\n" . $drop_query;
             // If an existing table gets deleted, maintain any entries for
             // the PMA_* tables.
             $maintain_relations = true;
         }
         // -----------------------------------------------------------------
         // Phase 2: Generating the new query of this structure.
         /**
          * The parser responsible for parsing the old queries.
          * @var Parser $parser
          */
         $parser = new Parser($sql_structure);
         if (!empty($parser->statements[0])) {
             /**
              * The CREATE statement of this structure.
              * @var \SqlParser\Statements\CreateStatement $statement
              */
             $statement = $parser->statements[0];
             // Changing the destination.
             $statement->name = $destination;
             // Building back the query.
             $sql_structure = $statement->build() . ';';
             // Executing it.
             $GLOBALS['dbi']->query($sql_structure);
             $GLOBALS['sql_query'] .= "\n" . $sql_structure;
         }
         // -----------------------------------------------------------------
         // Phase 3: Adding constraints.
         // All constraint names are removed because they must be unique.
         if (($move || isset($GLOBALS['add_constraints'])) && !empty($GLOBALS['sql_constraints_query'])) {
             $parser = new Parser($GLOBALS['sql_constraints_query']);
             /**
              * The ALTER statement that generates the constraints.
              * @var \SqlParser\Statements\AlterStatement $statement
              */
             $statement = $parser->statements[0];
             // Changing the altered table to the destination.
             $statement->table = $destination;
             // Removing the name of the constraints.
             foreach ($statement->altered as $idx => $altered) {
                 // All constraint names are removed because they must be unique.
                 if ($altered->options->has('CONSTRAINT')) {
                     $altered->field = null;
                 }
             }
             // Building back the query.
             $GLOBALS['sql_constraints_query'] = $statement->build() . ';';
             // Executing it.
             if ($mode == 'one_table') {
                 $GLOBALS['dbi']->query($GLOBALS['sql_constraints_query']);
             }
             $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query'];
             if ($mode == 'one_table') {
                 unset($GLOBALS['sql_constraints_query']);
             }
         }
         // -----------------------------------------------------------------
         // Phase 4: Adding indexes.
         // View phase 3.
         if (!empty($GLOBALS['sql_indexes'])) {
             $parser = new Parser($GLOBALS['sql_indexes']);
             /**
              * The ALTER statement that generates the indexes.
              * @var \SqlParser\Statements\AlterStatement $statement
              */
             $statement = $parser->statements[0];
             // Changing the altered table to the destination.
             $statement->table = $destination;
             // Removing the name of the constraints.
             foreach ($statement->altered as $idx => $altered) {
                 // All constraint names are removed because they must be unique.
                 if ($altered->options->has('CONSTRAINT')) {
                     $altered->field = null;
                 }
             }
             // Building back the query.
             $GLOBALS['sql_indexes'] = $statement->build() . ';';
             // Executing it.
             if ($mode == 'one_table' || $mode == 'db_copy') {
                 $GLOBALS['dbi']->query($GLOBALS['sql_indexes']);
             }
             $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_indexes'];
             if ($mode == 'one_table' || $mode == 'db_copy') {
                 unset($GLOBALS['sql_indexes']);
             }
         }
         // -----------------------------------------------------------------
         // Phase 5: Adding AUTO_INCREMENT.
         if (!empty($GLOBALS['sql_auto_increments'])) {
             if ($mode == 'one_table' || $mode == 'db_copy') {
                 $parser = new Parser($GLOBALS['sql_auto_increments']);
                 /**
                  * The ALTER statement that alters the AUTO_INCREMENT value.
                  * @var \SqlParser\Statements\AlterStatement $statement
                  */
                 $statement = $parser->statements[0];
                 // Changing the altered table to the destination.
                 $statement->table = $destination;
                 // Building back the query.
                 $GLOBALS['sql_auto_increments'] = $statement->build() . ';';
                 // Executing it.
                 $GLOBALS['dbi']->query($GLOBALS['sql_auto_increments']);
                 $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_auto_increments'];
                 unset($GLOBALS['sql_auto_increments']);
             }
         }
     } else {
         $GLOBALS['sql_query'] = '';
     }
     $_table = new Table($target_table, $target_db);
     // Copy the data unless this is a VIEW
     if (($what == 'data' || $what == 'dataonly') && !$_table->isView()) {
         $sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'";
         $GLOBALS['dbi']->query($sql_set_mode);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_set_mode . ';';
         $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
         $GLOBALS['dbi']->query($sql_insert_data);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';';
     }
     PMA_getRelationsParam();
     // Drops old table if the user has requested to move it
     if ($move) {
         // This could avoid some problems with replicated databases, when
         // moving table from replicated one to not replicated one
         $GLOBALS['dbi']->selectDb($source_db);
         $_source_table = new Table($source_table, $source_db);
         if ($_source_table->isView()) {
             $sql_drop_query = 'DROP VIEW';
         } else {
             $sql_drop_query = 'DROP TABLE';
         }
         $sql_drop_query .= ' ' . $source;
         $GLOBALS['dbi']->query($sql_drop_query);
         // Renable table in configuration storage
         PMA_REL_renameTable($source_db, $target_db, $source_table, $target_table);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_drop_query . ';';
         // end if ($move)
         return true;
     }
     // we are copying
     // Create new entries as duplicates from old PMA DBs
     if ($what == 'dataonly' || isset($maintain_relations)) {
         return true;
     }
     if ($GLOBALS['cfgRelation']['commwork']) {
         // Get all comments and MIME-Types for current table
         $comments_copy_rs = PMA_queryAsControlUser('SELECT column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ' FROM ' . Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . Util::backquote($GLOBALS['cfgRelation']['column_info']) . ' WHERE ' . ' db_name = \'' . Util::sqlAddSlashes($source_db) . '\'' . ' AND ' . ' table_name = \'' . Util::sqlAddSlashes($source_table) . '\'');
         // Write every comment as new copied entry. [MIME]
         while ($comments_copy_row = $GLOBALS['dbi']->fetchAssoc($comments_copy_rs)) {
             $new_comment_query = 'REPLACE INTO ' . Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . Util::backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . Util::sqlAddSlashes($target_db) . '\',\'' . Util::sqlAddSlashes($target_table) . '\',\'' . Util::sqlAddSlashes($comments_copy_row['column_name']) . '\'' . ($GLOBALS['cfgRelation']['mimework'] ? ',\'' . Util::sqlAddSlashes($comments_copy_row['comment']) . '\',' . '\'' . Util::sqlAddSlashes($comments_copy_row['mimetype']) . '\',' . '\'' . Util::sqlAddSlashes($comments_copy_row['transformation']) . '\',' . '\'' . Util::sqlAddSlashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
             PMA_queryAsControlUser($new_comment_query);
         }
         // end while
         $GLOBALS['dbi']->freeResult($comments_copy_rs);
         unset($comments_copy_rs);
     }
     // duplicating the bookmarks must not be done here, but
     // just once per db
     $get_fields = array('display_field');
     $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
     $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
     Table::duplicateInfo('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
     /**
      * @todo revise this code when we support cross-db relations
      */
     $get_fields = array('master_field', 'foreign_table', 'foreign_field');
     $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
     $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'master_table' => $target_table);
     Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
     $get_fields = array('foreign_field', 'master_table', 'master_field');
     $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
     $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'foreign_table' => $target_table);
     Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
     /**
     * @todo Can't get duplicating PDFs the right way. The
     * page numbers always get screwed up independently from
     * duplication because the numbers do not seem to be stored on a
     * per-database basis. Would the author of pdf support please
     * have a look at it?
     *
             $get_fields = array('page_descr');
             $where_fields = array('db_name' => $source_db);
             $new_fields = array('db_name' => $target_db);
             $last_id = Table::duplicateInfo(
        'pdfwork',
        'pdf_pages',
        $get_fields,
        $where_fields,
        $new_fields
             );
     
             if (isset($last_id) && $last_id >= 0) {
        $get_fields = array('x', 'y');
        $where_fields = array(
            'db_name' => $source_db,
            'table_name' => $source_table
        );
        $new_fields = array(
            'db_name' => $target_db,
            'table_name' => $target_table,
            'pdf_page_number' => $last_id
        );
        Table::duplicateInfo(
            'pdfwork',
            'table_coords',
            $get_fields,
            $where_fields,
            $new_fields
        );
             }
     */
     return true;
 }
Example #5
0
/**
 * Builds and executes SQL statements to create the database and tables
 * as necessary, as well as insert all the data.
 *
 * @param string $db_name         Name of the database
 * @param array  &$tables         Array of tables for the specified database
 * @param array  &$analyses       Analyses of the tables
 * @param array  &$additional_sql Additional SQL statements to be executed
 * @param array  $options         Associative array of options
 *
 * @return void
 * @access  public
 *
 * @link http://wiki.phpmyadmin.net/pma/Import
 */
function PMA_buildSQL($db_name, &$tables, &$analyses = null, &$additional_sql = null, $options = null)
{
    /* Take care of the options */
    if (isset($options['db_collation']) && !is_null($options['db_collation'])) {
        $collation = $options['db_collation'];
    } else {
        $collation = "utf8_general_ci";
    }
    if (isset($options['db_charset']) && !is_null($options['db_charset'])) {
        $charset = $options['db_charset'];
    } else {
        $charset = "utf8";
    }
    if (isset($options['create_db'])) {
        $create_db = $options['create_db'];
    } else {
        $create_db = true;
    }
    /* Create SQL code to handle the database */
    $sql = array();
    if ($create_db) {
        $sql[] = "CREATE DATABASE IF NOT EXISTS " . Util::backquote($db_name) . " DEFAULT CHARACTER SET " . $charset . " COLLATE " . $collation . ";";
    }
    /**
     * The calling plug-in should include this statement,
     * if necessary, in the $additional_sql parameter
     *
     * $sql[] = "USE " . backquote($db_name);
     */
    /* Execute the SQL statements create above */
    $sql_len = count($sql);
    for ($i = 0; $i < $sql_len; ++$i) {
        PMA_importRunQuery($sql[$i], $sql[$i]);
    }
    /* No longer needed */
    unset($sql);
    /* Run the $additional_sql statements supplied by the caller plug-in */
    if ($additional_sql != null) {
        /* Clean the SQL first */
        $additional_sql_len = count($additional_sql);
        /**
         * Only match tables for now, because CREATE IF NOT EXISTS
         * syntax is lacking or nonexisting for views, triggers,
         * functions, and procedures.
         *
         * See: http://bugs.mysql.com/bug.php?id=15287
         *
         * To the best of my knowledge this is still an issue.
         *
         * $pattern = 'CREATE (TABLE|VIEW|TRIGGER|FUNCTION|PROCEDURE)';
         */
        $pattern = '/CREATE [^`]*(TABLE)/';
        $replacement = 'CREATE \\1 IF NOT EXISTS';
        /* Change CREATE statements to CREATE IF NOT EXISTS to support
         * inserting into existing structures
         */
        for ($i = 0; $i < $additional_sql_len; ++$i) {
            $additional_sql[$i] = preg_replace($pattern, $replacement, $additional_sql[$i]);
            /* Execute the resulting statements */
            PMA_importRunQuery($additional_sql[$i], $additional_sql[$i]);
        }
    }
    if ($analyses != null) {
        $type_array = array(NONE => "NULL", VARCHAR => "varchar", INT => "int", DECIMAL => "decimal", BIGINT => "bigint", GEOMETRY => 'geometry');
        /* TODO: Do more checking here to make sure they really are matched */
        if (count($tables) != count($analyses)) {
            exit;
        }
        /* Create SQL code to create the tables */
        $num_tables = count($tables);
        for ($i = 0; $i < $num_tables; ++$i) {
            $num_cols = count($tables[$i][COL_NAMES]);
            $tempSQLStr = "CREATE TABLE IF NOT EXISTS " . PMA\libraries\Util::backquote($db_name) . '.' . PMA\libraries\Util::backquote($tables[$i][TBL_NAME]) . " (";
            for ($j = 0; $j < $num_cols; ++$j) {
                $size = $analyses[$i][SIZES][$j];
                if ((int) $size == 0) {
                    $size = 10;
                }
                $tempSQLStr .= PMA\libraries\Util::backquote($tables[$i][COL_NAMES][$j]) . " " . $type_array[$analyses[$i][TYPES][$j]];
                if ($analyses[$i][TYPES][$j] != GEOMETRY) {
                    $tempSQLStr .= "(" . $size . ")";
                }
                if ($j != count($tables[$i][COL_NAMES]) - 1) {
                    $tempSQLStr .= ", ";
                }
            }
            $tempSQLStr .= ") DEFAULT CHARACTER SET " . $charset . " COLLATE " . $collation . ";";
            /**
             * Each SQL statement is executed immediately
             * after it is formed so that we don't have
             * to store them in a (possibly large) buffer
             */
            PMA_importRunQuery($tempSQLStr, $tempSQLStr);
        }
    }
    /**
     * Create the SQL statements to insert all the data
     *
     * Only one insert query is formed for each table
     */
    $tempSQLStr = "";
    $col_count = 0;
    $num_tables = count($tables);
    for ($i = 0; $i < $num_tables; ++$i) {
        $num_cols = count($tables[$i][COL_NAMES]);
        $num_rows = count($tables[$i][ROWS]);
        $tempSQLStr = "INSERT INTO " . PMA\libraries\Util::backquote($db_name) . '.' . PMA\libraries\Util::backquote($tables[$i][TBL_NAME]) . " (";
        for ($m = 0; $m < $num_cols; ++$m) {
            $tempSQLStr .= PMA\libraries\Util::backquote($tables[$i][COL_NAMES][$m]);
            if ($m != $num_cols - 1) {
                $tempSQLStr .= ", ";
            }
        }
        $tempSQLStr .= ") VALUES ";
        for ($j = 0; $j < $num_rows; ++$j) {
            $tempSQLStr .= "(";
            for ($k = 0; $k < $num_cols; ++$k) {
                // If fully formatted SQL, no need to enclose
                // with apostrophes, add slashes etc.
                if ($analyses != null && isset($analyses[$i][FORMATTEDSQL][$col_count]) && $analyses[$i][FORMATTEDSQL][$col_count] == true) {
                    $tempSQLStr .= (string) $tables[$i][ROWS][$j][$k];
                } else {
                    if ($analyses != null) {
                        $is_varchar = $analyses[$i][TYPES][$col_count] === VARCHAR;
                    } else {
                        $is_varchar = !is_numeric($tables[$i][ROWS][$j][$k]);
                    }
                    /* Don't put quotes around NULL fields */
                    if (!strcmp($tables[$i][ROWS][$j][$k], 'NULL')) {
                        $is_varchar = false;
                    }
                    $tempSQLStr .= $is_varchar ? "'" : "";
                    $tempSQLStr .= PMA\libraries\Util::sqlAddSlashes((string) $tables[$i][ROWS][$j][$k]);
                    $tempSQLStr .= $is_varchar ? "'" : "";
                }
                if ($k != $num_cols - 1) {
                    $tempSQLStr .= ", ";
                }
                if ($col_count == $num_cols - 1) {
                    $col_count = 0;
                } else {
                    $col_count++;
                }
                /* Delete the cell after we are done with it */
                unset($tables[$i][ROWS][$j][$k]);
            }
            $tempSQLStr .= ")";
            if ($j != $num_rows - 1) {
                $tempSQLStr .= ",\n ";
            }
            $col_count = 0;
            /* Delete the row after we are done with it */
            unset($tables[$i][ROWS][$j]);
        }
        $tempSQLStr .= ";";
        /**
         * Each SQL statement is executed immediately
         * after it is formed so that we don't have
         * to store them in a (possibly large) buffer
         */
        PMA_importRunQuery($tempSQLStr, $tempSQLStr);
    }
    /* No longer needed */
    unset($tempSQLStr);
    /**
     * A work in progress
     */
    /* Add the viewable structures from $additional_sql
     * to $tables so they are also displayed
     */
    $view_pattern = '@VIEW `[^`]+`\\.`([^`]+)@';
    $table_pattern = '@CREATE TABLE IF NOT EXISTS `([^`]+)`@';
    /* Check a third pattern to make sure its not a "USE `db_name`;" statement */
    $regs = array();
    $inTables = false;
    $additional_sql_len = count($additional_sql);
    for ($i = 0; $i < $additional_sql_len; ++$i) {
        preg_match($view_pattern, $additional_sql[$i], $regs);
        if (count($regs) == 0) {
            preg_match($table_pattern, $additional_sql[$i], $regs);
        }
        if (count($regs)) {
            for ($n = 0; $n < $num_tables; ++$n) {
                if (!strcmp($regs[1], $tables[$n][TBL_NAME])) {
                    $inTables = true;
                    break;
                }
            }
            if (!$inTables) {
                $tables[] = array(TBL_NAME => $regs[1]);
            }
        }
        /* Reset the array */
        $regs = array();
        $inTables = false;
    }
    $params = array('db' => (string) $db_name);
    $db_url = 'db_structure.php' . PMA_URL_getCommon($params);
    $db_ops_url = 'db_operations.php' . PMA_URL_getCommon($params);
    $message = '<br /><br />';
    $message .= '<strong>' . __('The following structures have either been created or altered. Here you can:') . '</strong><br />';
    $message .= '<ul><li>' . __("View a structure's contents by clicking on its name.") . '</li>';
    $message .= '<li>' . __('Change any of its settings by clicking the corresponding "Options" link.') . '</li>';
    $message .= '<li>' . __('Edit structure by following the "Structure" link.') . '</li>';
    $message .= sprintf('<br /><li><a href="%s" title="%s">%s</a> (<a href="%s" title="%s">' . __('Options') . '</a>)</li>', $db_url, sprintf(__('Go to database: %s'), htmlspecialchars(PMA\libraries\Util::backquote($db_name))), htmlspecialchars($db_name), $db_ops_url, sprintf(__('Edit settings for %s'), htmlspecialchars(PMA\libraries\Util::backquote($db_name))));
    $message .= '<ul>';
    unset($params);
    $num_tables = count($tables);
    for ($i = 0; $i < $num_tables; ++$i) {
        $params = array('db' => (string) $db_name, 'table' => (string) $tables[$i][TBL_NAME]);
        $tbl_url = 'sql.php' . PMA_URL_getCommon($params);
        $tbl_struct_url = 'tbl_structure.php' . PMA_URL_getCommon($params);
        $tbl_ops_url = 'tbl_operations.php' . PMA_URL_getCommon($params);
        unset($params);
        $_table = new Table($tables[$i][TBL_NAME], $db_name);
        if (!$_table->isView()) {
            $message .= sprintf('<li><a href="%s" title="%s">%s</a> (<a href="%s" title="%s">' . __('Structure') . '</a>) (<a href="%s" title="%s">' . __('Options') . '</a>)</li>', $tbl_url, sprintf(__('Go to table: %s'), htmlspecialchars(PMA\libraries\Util::backquote($tables[$i][TBL_NAME]))), htmlspecialchars($tables[$i][TBL_NAME]), $tbl_struct_url, sprintf(__('Structure of %s'), htmlspecialchars(PMA\libraries\Util::backquote($tables[$i][TBL_NAME]))), $tbl_ops_url, sprintf(__('Edit settings for %s'), htmlspecialchars(PMA\libraries\Util::backquote($tables[$i][TBL_NAME]))));
        } else {
            $message .= sprintf('<li><a href="%s" title="%s">%s</a></li>', $tbl_url, sprintf(__('Go to view: %s'), htmlspecialchars(PMA\libraries\Util::backquote($tables[$i][TBL_NAME]))), htmlspecialchars($tables[$i][TBL_NAME]));
        }
    }
    $message .= '</ul></ul>';
    global $import_notice;
    $import_notice = $message;
    unset($tables);
}