Пример #1
0
function makedump($table_select, $what, $db, $crlf = "\n")
{
    global $dump_buffer, $tmp_buffer;
    $tables = mysql_list_tables($db);
    $num_tables = mysql_numrows($tables);
    $dump_buffer = '';
    $tmp_buffer = '';
    $i = 0;
    while ($i < $num_tables) {
        $table = mysql_tablename($tables, $i);
        if (!isset($table_select[$table])) {
            $i++;
            continue;
        }
        if ($what != 'dataonly') {
            $dump_buffer .= PMA_getTableDef($db, $table, $crlf) . ';' . $crlf . $crlf;
        }
        if ($what == 'data' || $what == 'dataonly') {
            $tmp_buffer = '';
            PMA_getTableContent($db, $table, 0, 0, 'PMA_myHandler', $crlf);
            $dump_buffer .= $tmp_buffer . $crlf;
        }
        $i++;
    }
    return $dump_buffer;
}
Пример #2
0
function backup_mysql_fn($shost, $suser, $spass, $sdb, $sdbfile)
{
    //echo $shost.' == '. $suser.' == '. $spass.' == '. $sdb.' == '. $sdbfile;
    $link = mysql_connect($shost, $suser, $spass);
    mysql_query('SET CHARACTER SET utf8');
    // Open and create a file handle for sql.
    $handle = fopen($sdbfile, 'w');
    $s_def = $alter_queries = $sresponse = '';
    $sql_alter = $tables = array();
    $ser_ver = PMA_sversion();
    $s_def = PMA_exportHeader($sdb, $ser_ver);
    fwrite($handle, $s_def);
    // List the tables
    $squery = mysql_query('SHOW TABLES FROM `' . $sdb . '`');
    while ($row = mysql_fetch_row($squery)) {
        $tables[] = $row[0];
    }
    // Sort the tables
    usort($tables, 'strnatcasecmp');
    foreach ($tables as $table => $v) {
        // Get the table structure(table definition)
        $stable_defn = PMA_getTableDef($sdb, $v, "\n");
        $s_def = $stable_defn['structure'] . "\n";
        fwrite($handle, $s_def);
        // Get the table data(table contents)
        // We have added $handle so that we can write the INSERT queries directly when we get it.
        // Basically To avoid MEMORY EXHAUST FOR  BIG INSERTS
        PMA_exportData($sdb, $v, "\n", $handle);
        // List of alter queries
        // We have changed this because the OLD method was putting the ALTER queries after CREATE table query which was causing issues.
        if (!empty($stable_defn['alter'])) {
            $alter_queries .= $stable_defn['alter'];
        }
    }
    fwrite($handle, $alter_queries);
    $sresponse = PMA_exportFooter();
    // Just to add the finishing lines
    fwrite($handle, $sresponse);
    fclose($handle);
    // Just check that file is created or not ??
    if (file_exists($sdbfile)) {
        return true;
    }
    return false;
}
Пример #3
0
 /**
  * Copies or renames table
  * @todo use RENAME for move operations
  *        - would work only if the databases are on the same filesystem,
  *          how can we check that? try the operation and
  *          catch an error?
  *        - for views, only if MYSQL > 50013
  *        - still have to handle pmadb synch.
  *
  * @author          Michal Cihar <*****@*****.**>
  */
 function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode)
 {
     global $err_url;
     // set export settings we need
     $GLOBALS['sql_backquotes'] = 1;
     $GLOBALS['asfile'] = 1;
     // Ensure the target is valid
     if (!$GLOBALS['PMA_List_Database']->exists($source_db, $target_db)) {
         /**
          * @todo exit really needed here? or just a return?
          */
         exit;
     }
     $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table);
     if (!isset($target_db) || !strlen($target_db)) {
         $target_db = $source_db;
     }
     // Doing a select_db could avoid some problems with replicated databases,
     // when moving table from replicated one to not replicated one
     PMA_DBI_select_db($target_db);
     $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
     // do not create the table if dataonly
     if ($what != 'dataonly') {
         require_once './libraries/export/sql.php';
         $no_constraints_comments = true;
         $GLOBALS['sql_constraints_query'] = '';
         $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
         unset($no_constraints_comments);
         $parsed_sql = PMA_SQP_parse($sql_structure);
         $analyzed_sql = PMA_SQP_analyze($parsed_sql);
         $i = 0;
         if (empty($analyzed_sql[0]['create_table_fields'])) {
             // this is not a CREATE TABLE, so find the first VIEW
             $target_for_view = PMA_backquote($target_db);
             while (true) {
                 if ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'VIEW') {
                     break;
                 }
                 $i++;
             }
         }
         unset($analyzed_sql);
         $server_sql_mode = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'sql_mode'", 0, 1);
         if ('ANSI_QUOTES' == $server_sql_mode) {
             $table_delimiter = 'quote_double';
         } else {
             $table_delimiter = 'quote_backtick';
         }
         unset($server_sql_mode);
         /* nijel: Find table name in query and replace it */
         while ($parsed_sql[$i]['type'] != $table_delimiter) {
             $i++;
         }
         /* no need to PMA_backquote() */
         if (isset($target_for_view)) {
             // this a view definition; we just found the first db name
             // that follows DEFINER VIEW
             // so change it for the new db name
             $parsed_sql[$i]['data'] = $target_for_view;
             // then we have to find all references to the source db
             // and change them to the target db, ensuring we stay into
             // the $parsed_sql limits
             $last = $parsed_sql['len'] - 1;
             $backquoted_source_db = PMA_backquote($source_db);
             for (++$i; $i <= $last; $i++) {
                 if ($parsed_sql[$i]['type'] == $table_delimiter && $parsed_sql[$i]['data'] == $backquoted_source_db) {
                     $parsed_sql[$i]['data'] = $target_for_view;
                 }
             }
             unset($last, $backquoted_source_db);
         } else {
             $parsed_sql[$i]['data'] = $target;
         }
         /* Generate query back */
         $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
         // If table exists, and 'add drop table' is selected: Drop it!
         $drop_query = '';
         if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') {
             if (PMA_Table::_isView($target_db, $target_table)) {
                 $drop_query = 'DROP VIEW';
             } else {
                 $drop_query = 'DROP TABLE';
             }
             $drop_query .= ' IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
             PMA_DBI_query($drop_query);
             $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
             // garvin: If an existing table gets deleted, maintain any
             // entries for the PMA_* tables
             $maintain_relations = true;
         }
         @PMA_DBI_query($sql_structure);
         $GLOBALS['sql_query'] .= "\n" . $sql_structure . ';';
         if (($move || isset($GLOBALS['add_constraints'])) && !empty($GLOBALS['sql_constraints_query'])) {
             $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints_query']);
             $i = 0;
             // find the first $table_delimiter, it must be the source table name
             while ($parsed_sql[$i]['type'] != $table_delimiter) {
                 $i++;
                 // maybe someday we should guard against going over limit
                 //if ($i == $parsed_sql['len']) {
                 //    break;
                 //}
             }
             // replace it by the target table name, no need to PMA_backquote()
             $parsed_sql[$i]['data'] = $target;
             // now we must remove all $table_delimiter that follow a CONSTRAINT
             // keyword, because a constraint name must be unique in a db
             $cnt = $parsed_sql['len'] - 1;
             for ($j = $i; $j < $cnt; $j++) {
                 if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') {
                     if ($parsed_sql[$j + 1]['type'] == $table_delimiter) {
                         $parsed_sql[$j + 1]['data'] = '';
                     }
                 }
             }
             // Generate query back
             $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
             if ($mode == 'one_table') {
                 PMA_DBI_query($GLOBALS['sql_constraints_query']);
             }
             $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query'];
             if ($mode == 'one_table') {
                 unset($GLOBALS['sql_constraints_query']);
             }
         }
     } else {
         $GLOBALS['sql_query'] = '';
     }
     // Copy the data unless this is a VIEW
     if (($what == 'data' || $what == 'dataonly') && !PMA_Table::_isView($target_db, $target_table)) {
         $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
         PMA_DBI_query($sql_insert_data);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';';
     }
     require_once './libraries/relation.lib.php';
     $GLOBALS['cfgRelation'] = 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
         PMA_DBI_select_db($source_db);
         if (PMA_Table::_isView($source_db, $source_table)) {
             $sql_drop_query = 'DROP VIEW';
         } else {
             $sql_drop_query = 'DROP TABLE';
         }
         $sql_drop_query .= ' ' . $source;
         PMA_DBI_query($sql_drop_query);
         // garvin: Move old entries from PMA-DBs to new table
         if ($GLOBALS['cfgRelation']['commwork']) {
             $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . '        db_name    = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($remove_query);
             unset($remove_query);
         }
         // garvin: updating bookmarks is not possible since only a single table is moved,
         // and not the whole DB.
         if ($GLOBALS['cfgRelation']['displaywork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . '         table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         if ($GLOBALS['cfgRelation']['relwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET     foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET     master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE master_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         /**
          * @todo garvin: Can't get moving 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?
          */
         if ($GLOBALS['cfgRelation']['pdfwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
             /*
             $pdf_query = 'SELECT pdf_page_number '
                        . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords'])
                        . ' WHERE db_name  = \'' . PMA_sqlAddslashes($target_db) . '\''
                        . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\'';
             $pdf_rs = PMA_query_as_cu($pdf_query);
             
             while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) {
                 $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['pdf_pages'])
                                 . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
                                 . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\''
                                 . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\'';
                 $tb_rs    = PMA_query_as_cu($table_query);
                 unset($table_query);
                 unset($tb_rs);
             }
             */
         }
         if ($GLOBALS['cfgRelation']['designerwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         $GLOBALS['sql_query'] .= "\n\n" . $sql_drop_query . ';';
         // end if ($move)
     } else {
         // we are copying
         // garvin: Create new entries as duplicates from old PMA DBs
         if ($what != 'dataonly' && !isset($maintain_relations)) {
             if ($GLOBALS['cfgRelation']['commwork']) {
                 // Get all comments and MIME-Types for current table
                 $comments_copy_query = 'SELECT
                                             column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                         FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
                                         WHERE
                                             db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND
                                             table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
                 $comments_copy_rs = PMA_query_as_cu($comments_copy_query);
                 // Write every comment as new copied entry. [MIME]
                 while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                     $new_comment_query = 'REPLACE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . ($GLOBALS['cfgRelation']['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                     PMA_query_as_cu($new_comment_query);
                 }
                 // end while
                 PMA_DBI_free_result($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);
             PMA_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);
             PMA_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);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('x', 'y', 'v', 'h');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('designerwork', 'designer_coords', $get_fields, $where_fields, $new_fields);
             /**
             * @todo garvin: 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 = PMA_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);
                PMA_Table::duplicateInfo('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields);
                             }
             */
         }
     }
 }
 /**
  * Outputs table's structure
  *
  * @param string  $db           database name
  * @param string  $table        table name
  * @param string  $crlf         the end of line sequence
  * @param string  $error_url    the url to go back in case of error
  * @param bool    $relation     whether to include relation comments
  * @param bool    $comments     whether to include the pmadb-style column comments
  *                                as comments in the structure; this is deprecated
  *                                but the parameter is left here because export.php
  *                                calls PMA_exportStructure() also for other export
  *                                types which use this parameter
  * @param bool    $mime         whether to include mime comments
  * @param bool    $dates        whether to include creation/update/check dates
  * @param string  $export_mode  'create_table', 'triggers', 'create_view', 'stand_in'
  * @param string  $export_type  'server', 'database', 'table'
  * @return  bool      Whether it succeeded
  *
  * @access  public
  */
 function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = false, $comments = false, $mime = false, $dates = false, $export_mode, $export_type)
 {
     $formatted_table_name = isset($GLOBALS['sql_backquotes']) ? PMA_backquote($table) : '\'' . $table . '\'';
     $dump = PMA_possibleCRLF() . PMA_exportComment(str_repeat('-', 56)) . PMA_possibleCRLF() . PMA_exportComment();
     switch ($export_mode) {
         case 'create_table':
             $dump .= PMA_exportComment(__('Table structure for table') . ' ' . $formatted_table_name);
             $dump .= PMA_exportComment();
             $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates);
             $dump .= PMA_getTableComments($db, $table, $crlf, $relation, $mime);
             break;
         case 'triggers':
             $dump = '';
             $triggers = PMA_DBI_get_triggers($db, $table);
             if ($triggers) {
                 $dump .= PMA_possibleCRLF() . PMA_exportComment() . PMA_exportComment(__('Triggers') . ' ' . $formatted_table_name) . PMA_exportComment();
                 $delimiter = '//';
                 foreach ($triggers as $trigger) {
                     $dump .= $trigger['drop'] . ';' . $crlf;
                     $dump .= 'DELIMITER ' . $delimiter . $crlf;
                     $dump .= $trigger['create'];
                     $dump .= 'DELIMITER ;' . $crlf;
                 }
             }
             break;
         case 'create_view':
             $dump .= PMA_exportComment(__('Structure for view') . ' ' . $formatted_table_name) . PMA_exportComment();
             // delete the stand-in table previously created (if any)
             if ($export_type != 'table') {
                 $dump .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table) . ';' . $crlf;
             }
             $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates, true, true);
             break;
         case 'stand_in':
             $dump .= PMA_exportComment(__('Stand-in structure for view') . ' ' . $formatted_table_name) . PMA_exportComment();
             // export a stand-in definition to resolve view dependencies
             $dump .= PMA_getTableDefStandIn($db, $table, $crlf);
     }
     // end switch
     // this one is built by PMA_getTableDef() to use in table copy/move
     // but not in the case of export
     unset($GLOBALS['sql_constraints_query']);
     return PMA_exportOutputHandler($dump);
 }
Пример #5
0
     unset($original_db);
     // rebuild the database list because PMA_Table::moveCopy
     // checks in this list if the target db exists
     $GLOBALS['pma']->databases->build();
 }
 if (isset($GLOBALS['add_constraints']) || $move) {
     $GLOBALS['sql_constraints_query_full_db'] = array();
 }
 $tables_full = PMA_DBI_get_tables_full($db);
 $views = array();
 // remove all foreign key constraints, otherwise we can get errors
 require_once './libraries/export/sql.php';
 foreach ($tables_full as $each_table => $tmp) {
     $sql_constraints = '';
     $sql_drop_foreign_keys = '';
     $sql_structure = PMA_getTableDef($db, $each_table, "\n", '', false, false);
     if ($move && !empty($sql_drop_foreign_keys)) {
         PMA_DBI_query($sql_drop_foreign_keys);
     }
     // keep the constraint we just dropped
     if (!empty($sql_constraints)) {
         $GLOBALS['sql_constraints_query_full_db'][] = $sql_constraints;
     }
 }
 unset($sql_constraints, $sql_drop_foreign_keys, $sql_structure);
 foreach ($tables_full as $each_table => $tmp) {
     // to be able to rename a db containing views, we
     // first collect in $views all the views we find and we
     // will handle them after the tables
     /**
      * @todo support a view of a view
Пример #6
0
 if ($db == $target_db && $new_name == $table) {
     $message = isset($submit_move) ? $strMoveTableSameNames : $strCopyTableSameNames;
 } else {
     $source = PMA_backquote($db) . '.' . PMA_backquote($table);
     if (empty($target_db)) {
         $target_db = $db;
     }
     // This could avoid some problems with replicated databases, when
     // moving table from replicated one to not replicated one
     PMA_mysql_select_db($target_db);
     $target = PMA_backquote($target_db) . '.' . PMA_backquote($new_name);
     // do not create the table if dataonly
     if ($what != 'dataonly') {
         require './libraries/export/sql.php';
         $no_constraints_comments = true;
         $sql_structure = PMA_getTableDef($db, $table, "\n", $err_url);
         unset($no_constraints_comments);
         $parsed_sql = PMA_SQP_parse($sql_structure);
         /* nijel: Find table name in query and replace it */
         $i = 0;
         while ($parsed_sql[$i]['type'] != 'quote_backtick') {
             $i++;
         }
         /* no need to PMA_backquote() */
         $parsed_sql[$i]['data'] = $target;
         /* Generate query back */
         $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
         // If table exists, and 'add drop table' is selected: Drop it!
         $drop_query = '';
         if (isset($drop_if_exists) && $drop_if_exists == 'true') {
             $drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($new_name);
Пример #7
0
    /**
     * Creates tracking version of a table / view
     * (in other words: create a job to track future changes on the table).
     *
     * @param string $dbname       name of database
     * @param string $tablename    name of table
     * @param string $version      version
     * @param string $tracking_set set of tracking statements
     * @param bool   $is_view      if table is a view
     *
     * @static
     *
     * @return int result of version insertion
     */
    static public function createVersion($dbname, $tablename, $version, $tracking_set = '', $is_view = false)
    {
        global $sql_backquotes;

        if ($tracking_set == '') {
            $tracking_set = self::$default_tracking_set;
        }

        include_once './libraries/export/sql.php';

        $sql_backquotes = true;

        $date = date('Y-m-d H:i:s');

        // Get data definition snapshot of table

        $columns = PMA_DBI_get_columns($dbname, $tablename, null, true);
        // int indices to reduce size
        $columns = array_values($columns);
        // remove Privileges to reduce size
        for ($i = 0; $i < count($columns); $i++) {
            unset($columns[$i]['Privileges']);
        }

        $indexes = PMA_DBI_get_table_indexes($dbname, $tablename);

        $snapshot = array('COLUMNS' => $columns, 'INDEXES' => $indexes);
        $snapshot = serialize($snapshot);

        // Get DROP TABLE / DROP VIEW and CREATE TABLE SQL statements
        $sql_backquotes = true;

        $create_sql  = "";

        if (self::$add_drop_table == true && $is_view == false) {
            $create_sql .= self::getLogComment() .
                           'DROP TABLE IF EXISTS ' . PMA_backquote($tablename) . ";\n";

        }

        if (self::$add_drop_view == true && $is_view == true) {
            $create_sql .= self::getLogComment() .
                           'DROP VIEW IF EXISTS ' . PMA_backquote($tablename) . ";\n";
        }

        $create_sql .= self::getLogComment() .
                       PMA_getTableDef($dbname, $tablename, "\n", "");

        // Save version

        $sql_query = "/*NOTRACK*/\n" .
        "INSERT INTO" . self::$pma_table . " (" .
        "db_name, " .
        "table_name, " .
        "version, " .
        "date_created, " .
        "date_updated, " .
        "schema_snapshot, " .
        "schema_sql, " .
        "data_sql, " .
        "tracking " .
        ") " .
        "values (
        '" . PMA_sqlAddSlashes($dbname) . "',
        '" . PMA_sqlAddSlashes($tablename) . "',
        '" . PMA_sqlAddSlashes($version) . "',
        '" . PMA_sqlAddSlashes($date) . "',
        '" . PMA_sqlAddSlashes($date) . "',
        '" . PMA_sqlAddSlashes($snapshot) . "',
        '" . PMA_sqlAddSlashes($create_sql) . "',
        '" . PMA_sqlAddSlashes("\n") . "',
        '" . PMA_sqlAddSlashes(self::transformTrackingSet($tracking_set)) . "' )";

        $result = PMA_query_as_controluser($sql_query);

        if ($result) {
            // Deactivate previous version
            self::deactivateTracking($dbname, $tablename, ($version - 1));
        }

        return $result;
    }
Пример #8
0
 /**
  * Outputs table's structure
  *
  * @param   string   the database name
  * @param   string   the table name
  * @param   string   the end of line sequence
  * @param   string   the url to go back in case of error
  * @param   boolean  whether to include relation comments
  * @param   boolean  whether to include column comments
  * @param   boolean  whether to include mime comments
  * @param   string   'stand_in', 'create_table', 'create_view' 
  * @param   string   'server', 'database', 'table' 
  *
  * @return  bool     Whether it suceeded
  *
  * @access  public
  */
 function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE, $export_mode, $export_type)
 {
     $formatted_table_name = isset($GLOBALS['sql_backquotes']) ? PMA_backquote($table) : '\'' . $table . '\'';
     $dump = $crlf . $GLOBALS['comment_marker'] . '--------------------------------------------------------' . $crlf . $crlf . $GLOBALS['comment_marker'] . $crlf;
     switch ($export_mode) {
         case 'create_table':
             $dump .= $GLOBALS['comment_marker'] . $GLOBALS['strTableStructure'] . ' ' . $formatted_table_name . $crlf . $GLOBALS['comment_marker'] . $crlf;
             $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates) . ';' . $crlf;
             break;
         case 'create_view':
             $dump .= $GLOBALS['comment_marker'] . $GLOBALS['strStructureForView'] . ' ' . $formatted_table_name . $crlf . $GLOBALS['comment_marker'] . $crlf;
             // delete the stand-in table previously created (if any)
             if ($export_type != 'table') {
                 $dump .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table) . ';' . $crlf;
             }
             $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates) . ';' . $crlf;
             break;
         case 'stand_in':
             $dump .= $GLOBALS['comment_marker'] . $GLOBALS['strStandInStructureForView'] . ' ' . $formatted_table_name . $crlf . $GLOBALS['comment_marker'] . $crlf;
             // export a stand-in definition to resolve view dependencies
             $dump .= PMA_getTableDefStandIn($db, $table, $crlf);
     }
     // end switch
     $dump .= PMA_getTableComments($db, $table, $crlf, $relation, $comments, $mime);
     // this one is built by PMA_getTableDef() to use in table copy/move
     // but not in the case of export
     unset($GLOBALS['sql_constraints_query']);
     return PMA_exportOutputHandler($dump);
 }
Пример #9
0
/**
 * Outputs table's structure
 *
 * @param   string   the database name
 * @param   string   the table name
 * @param   string   the end of line sequence
 * @param   string   the url to go back in case of error
 * @param   boolean  whether to include relation comments
 * @param   boolean  whether to include column comments
 * @param   boolean  whether to include mime comments
 *
 * @return  bool     Whether it suceeded
 *
 * @access  public
 */
function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE)
{
    $formatted_table_name = isset($GLOBALS['use_backquotes']) ? PMA_backquote($table) : '\'' . $table . '\'';
    $dump = $crlf . $GLOBALS['comment_marker'] . '--------------------------------------------------------' . $crlf . $crlf . $GLOBALS['comment_marker'] . $crlf . $GLOBALS['comment_marker'] . $GLOBALS['strTableStructure'] . ' ' . $formatted_table_name . $crlf . $GLOBALS['comment_marker'] . $crlf . PMA_getTableDef($db, $table, $crlf, $error_url, $dates) . ';' . $crlf . PMA_getTableComments($db, $table, $crlf, $relation, $comments, $mime);
    return PMA_exportOutputHandler($dump);
}
Пример #10
0
/**
 * Copies or renames table
 * FIXME: use RENAME
 *
 * @author          Michal Čihař <*****@*****.**>
 */
function PMA_table_move_copy($source_db, $source_table, $target_db, $target_table, $what, $move)
{
    global $cfgRelation, $dblist, $err_url, $sql_query;
    // set export settings we need
    $GLOBALS['use_backquotes'] = 1;
    $GLOBALS['asfile'] = 1;
    // Ensure the target is valid
    if (count($dblist) > 0 && (PMA_isInto($source_db, $dblist) == -1 || PMA_isInto($target_db, $dblist) == -1)) {
        exit;
    }
    $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table);
    if (empty($target_db)) {
        $target_db = $source_db;
    }
    // This could avoid some problems with replicated databases, when
    // moving table from replicated one to not replicated one
    PMA_DBI_select_db($target_db);
    $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
    // do not create the table if dataonly
    if ($what != 'dataonly') {
        require_once './libraries/export/sql.php';
        $no_constraints_comments = true;
        $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
        unset($no_constraints_comments);
        $parsed_sql = PMA_SQP_parse($sql_structure);
        /* nijel: Find table name in query and replace it */
        $i = 0;
        while ($parsed_sql[$i]['type'] != 'quote_backtick') {
            $i++;
        }
        /* no need to PMA_backquote() */
        $parsed_sql[$i]['data'] = $target;
        /* Generate query back */
        $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
        // If table exists, and 'add drop table' is selected: Drop it!
        $drop_query = '';
        if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') {
            $drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
            $result = PMA_DBI_query($drop_query);
            if (isset($sql_query)) {
                $sql_query .= "\n" . $drop_query . ';';
            } else {
                $sql_query = $drop_query . ';';
            }
            // garvin: If an existing table gets deleted, maintain any entries
            // for the PMA_* tables
            $maintain_relations = TRUE;
        }
        $result = @PMA_DBI_query($sql_structure);
        if (isset($sql_query)) {
            $sql_query .= "\n" . $sql_structure . ';';
        } else {
            $sql_query = $sql_structure . ';';
        }
        if (($move || isset($GLOBALS['constraints'])) && isset($GLOBALS['sql_constraints'])) {
            $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']);
            $i = 0;
            while ($parsed_sql[$i]['type'] != 'quote_backtick') {
                $i++;
            }
            /* no need to PMA_backquote() */
            $parsed_sql[$i]['data'] = $target;
            /* Generate query back */
            $GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
            $result = PMA_DBI_query($GLOBALS['sql_constraints']);
            if (isset($sql_query)) {
                $sql_query .= "\n" . $GLOBALS['sql_constraints'];
            } else {
                $sql_query = $GLOBALS['sql_constraints'];
            }
            unset($GLOBALS['sql_constraints']);
        }
    } else {
        $sql_query = '';
    }
    // Copy the data
    //if ($result != FALSE && ($what == 'data' || $what == 'dataonly')) {
    if ($what == 'data' || $what == 'dataonly') {
        $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
        PMA_DBI_query($sql_insert_data);
        $sql_query .= "\n\n" . $sql_insert_data . ';';
    }
    require_once './libraries/relation.lib.php';
    $cfgRelation = 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
        PMA_DBI_select_db($source_db);
        $sql_drop_table = 'DROP TABLE ' . $source;
        PMA_DBI_query($sql_drop_table);
        // garvin: Move old entries from PMA-DBs to new table
        if ($cfgRelation['commwork']) {
            $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . '        db_name    = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $rmv_rs = PMA_query_as_cu($remove_query);
            unset($rmv_query);
        }
        // garvin: updating bookmarks is not possible since only a single table is moved,
        // and not the whole DB.
        // if ($cfgRelation['bookmarkwork']) {
        //     $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['bookmark'])
        //                   . ' SET     dbase = \'' . PMA_sqlAddslashes($target_db) . '\''
        //                   . ' WHERE dbase  = \'' . PMA_sqlAddslashes($source_db) . '\'';
        //     $rmv_rs    = PMA_query_as_cu($remove_query);
        //     unset($rmv_query);
        // }
        if ($cfgRelation['displaywork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info']) . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . '         table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
        }
        if ($cfgRelation['relwork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE master_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
        }
        // garvin: [TODO] Can't get moving 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?
        if ($cfgRelation['pdfwork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
            /*
            $pdf_query = 'SELECT pdf_page_number '
                       . ' FROM ' . PMA_backquote($cfgRelation['table_coords'])
                       . ' WHERE db_name  = \'' . PMA_sqlAddslashes($target_db) . '\''
                       . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\'';
            $pdf_rs = PMA_query_as_cu($pdf_query);
            
            while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) {
                $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['pdf_pages'])
                                . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
                                . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\''
                                . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\'';
                $tb_rs    = PMA_query_as_cu($table_query);
                unset($table_query);
                unset($tb_rs);
            }
            */
        }
        $sql_query .= "\n\n" . $sql_drop_table . ';';
    } else {
        // garvin: Create new entries as duplicates from old PMA DBs
        if ($what != 'dataonly' && !isset($maintain_relations)) {
            if ($cfgRelation['commwork']) {
                // Get all comments and MIME-Types for current table
                $comments_copy_query = 'SELECT
                                            column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                        FROM ' . PMA_backquote($cfgRelation['column_info']) . '
                                        WHERE
                                            db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND
                                            table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
                $comments_copy_rs = PMA_query_as_cu($comments_copy_query);
                // Write every comment as new copied entry. [MIME]
                while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                    $new_comment_query = 'REPLACE INTO ' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . ($cfgRelation['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                    $new_comment_rs = PMA_query_as_cu($new_comment_query);
                }
                // end while
            }
            if ($source_db != $target_db) {
                $get_fields = array('user', 'label', 'query');
                $where_fields = array('dbase' => $source_db);
                $new_fields = array('dbase' => $target_db);
                PMA_duplicate_table_info('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields);
            }
            $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);
            PMA_duplicate_table_info('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
            $get_fields = array('master_field', 'foreign_db', 'foreign_table', 'foreign_field');
            $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
            $new_fields = array('master_db' => $target_db, 'master_table' => $target_table);
            PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields);
            $get_fields = array('foreign_field', 'master_db', 'master_table', 'master_field');
            $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
            $new_fields = array('foreign_db' => $target_db, 'foreign_table' => $target_table);
            PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields);
            // garvin: [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 = PMA_duplicate_table_info('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);
                PMA_duplicate_table_info('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields);
            }
            */
        }
    }
}
Пример #11
0
 /**
  * Outputs table's structure
  *
  * @param   string   the database name
  * @param   string   the table name
  * @param   string   the end of line sequence
  * @param   string   the url to go back in case of error
  * @param   boolean  whether to include relation comments
  * @param   boolean  whether to include column comments
  * @param   boolean  whether to include mime comments
  *
  * @return  bool     Whether it suceeded
  *
  * @access  public
  */
 function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE)
 {
     $formatted_table_name = isset($GLOBALS['sql_backquotes']) ? PMA_backquote($table) : '\'' . $table . '\'';
     $dump = $crlf . $GLOBALS['comment_marker'] . '--------------------------------------------------------' . $crlf . $crlf . $GLOBALS['comment_marker'] . $crlf . $GLOBALS['comment_marker'] . $GLOBALS['strTableStructure'] . ' ' . $formatted_table_name . $crlf . $GLOBALS['comment_marker'] . $crlf . PMA_getTableDef($db, $table, $crlf, $error_url, $dates) . ';' . $crlf . PMA_getTableComments($db, $table, $crlf, $relation, $comments, $mime);
     // this one is built by PMA_getTableDef() to use in table copy/move
     // but not in the case of export
     unset($GLOBALS['sql_constraints_query']);
     return PMA_exportOutputHandler($dump);
 }
Пример #12
0
 $i = 0;
 if (isset($table_select)) {
     $tmp_select = implode($table_select, '|');
     $tmp_select = '|' . $tmp_select . '|';
 }
 while ($i < $num_tables) {
     if (!isset($single)) {
         $table = mysql_tablename($tables, $i);
     }
     if (isset($tmp_select) && is_int(strpos($tmp_select, '|' . $table . '|')) == FALSE) {
         $i++;
     } else {
         $formatted_table_name = isset($use_backquotes) ? PMA_backquote($table) : '\'' . $table . '\'';
         // If only datas, no need to displays table name
         if ($what != 'dataonly') {
             $dump_buffer .= '# --------------------------------------------------------' . $crlf . $crlf . '#' . $crlf . '# ' . $strTableStructure . ' ' . $formatted_table_name . $crlf . '#' . $crlf . $crlf . PMA_getTableDef($db, $table, $crlf, $err_url) . ';' . $crlf;
         }
         // At least data
         if ($what == 'data' || $what == 'dataonly') {
             $dump_buffer .= $crlf . '#' . $crlf . '# ' . $strDumpingData . ' ' . $formatted_table_name . $crlf . '#' . $crlf . $crlf;
             $tmp_buffer = '';
             if (!isset($limit_from) || !isset($limit_to)) {
                 $limit_from = $limit_to = 0;
             }
             // loic1: display data if they aren't bufferized
             if (!isset($zip) && !isset($bzip) && !isset($gzip)) {
                 echo $dump_buffer;
                 $dump_buffer = '';
             }
             PMA_getTableContent($db, $table, $limit_from, $limit_to, 'PMA_myHandler', $err_url);
             $dump_buffer .= $tmp_buffer;
Пример #13
0
 /**
  * Creates tracking version of a table / view
  * (in other words: create a job to track future changes on the table).
  *
  * @static
  *
  * @param  string $dbname       name of database
  * @param  string $tablename    name of table
  * @param  string $version      version
  * @param  string $tracking_set set of tracking statements
  * @param  string $is_view      if table is a view
  *
  * @return int result of version insertion
  */
 public static function createVersion($dbname, $tablename, $version, $tracking_set = '', $is_view = false)
 {
     global $sql_backquotes;
     if ($tracking_set == '') {
         $tracking_set = self::$default_tracking_set;
     }
     require_once './libraries/export/sql.php';
     $sql_backquotes = true;
     $date = date('Y-m-d H:i:s');
     // Get data definition snapshot of table
     $sql_query = '
     SHOW FULL COLUMNS FROM ' . PMA_backquote($dbname) . '.' . PMA_backquote($tablename);
     $sql_result = PMA_DBI_query($sql_query);
     while ($row = PMA_DBI_fetch_array($sql_result)) {
         $columns[] = $row;
     }
     $sql_query = '
     SHOW INDEX FROM ' . PMA_backquote($dbname) . '.' . PMA_backquote($tablename);
     $sql_result = PMA_DBI_query($sql_query);
     $indexes = array();
     while ($row = PMA_DBI_fetch_array($sql_result)) {
         $indexes[] = $row;
     }
     $snapshot = array('COLUMNS' => $columns, 'INDEXES' => $indexes);
     $snapshot = serialize($snapshot);
     // Get DROP TABLE / DROP VIEW and CREATE TABLE SQL statements
     $sql_backquotes = true;
     $create_sql = "";
     if (self::$add_drop_table == true && $is_view == false) {
         $create_sql .= self::getLogComment() . self::getStatementDropTable(PMA_backquote($tablename)) . ";\n";
     }
     if (self::$add_drop_view == true && $is_view == true) {
         $create_sql .= self::getLogComment() . self::getStatementDropView(PMA_backquote($tablename)) . ";\n";
     }
     $create_sql .= self::getLogComment() . PMA_getTableDef($dbname, $tablename, "\n", "");
     // Save version
     $sql_query = "/*NOTRACK*/\n" . "INSERT INTO" . self::$pma_table . " (" . "db_name, " . "table_name, " . "version, " . "date_created, " . "date_updated, " . "schema_snapshot, " . "schema_sql, " . "data_sql, " . "tracking " . ") " . "values (\n        '" . PMA_sqlAddslashes($dbname) . "',\n        '" . PMA_sqlAddslashes($tablename) . "',\n        '" . PMA_sqlAddslashes($version) . "',\n        '" . PMA_sqlAddslashes($date) . "',\n        '" . PMA_sqlAddslashes($date) . "',\n        '" . PMA_sqlAddslashes($snapshot) . "',\n        '" . PMA_sqlAddslashes($create_sql) . "',\n        '" . PMA_sqlAddslashes("\n") . "',\n        '" . PMA_sqlAddslashes($tracking_set) . "' )";
     $result = PMA_query_as_controluser($sql_query);
     if ($result) {
         // Deactivate previous version
         self::deactivateTracking($dbname, $tablename, $version - 1);
     }
     return $result;
 }
Пример #14
0
 /**
  * Outputs table's structure
  *
  * @param string $db          database name
  * @param string $table       table name
  * @param string $crlf        the end of line sequence
  * @param string $error_url   the url to go back in case of error
  * @param string $export_mode 'create_table', 'triggers', 'create_view',
  *                            'stand_in'
  * @param string $export_type 'server', 'database', 'table'
  * @param bool   $do_relation whether to include relation comments
  * @param bool   $do_comments whether to include the pmadb-style column
  *                                comments as comments in the structure;
  *                                this is deprecated but the parameter is
  *                                left here because export.php calls
  *                                PMA_exportStructure() also for other
  *                                export types which use this parameter
  * @param bool   $do_mime     whether to include mime comments
  * @param bool   $dates       whether to include creation/update/check dates
  *
  * @return bool Whether it succeeded
  *
  * @access public
  */
 function PMA_exportStructure($db, $table, $crlf, $error_url, $export_mode, $export_type, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false)
 {
     $dump = '';
     switch ($export_mode) {
         case 'create_table':
             $dump .= '<h2>' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</h2>';
             $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates);
             break;
         case 'triggers':
             $dump = '';
             $triggers = PMA_DBI_get_triggers($db, $table);
             if ($triggers) {
                 $dump .= '<h2>' . __('Triggers') . ' ' . htmlspecialchars($table) . '</h2>';
                 $dump .= PMA_getTriggers($db, $table);
             }
             break;
         case 'create_view':
             $dump .= '<h2>' . __('Structure for view') . ' ' . htmlspecialchars($table) . '</h2>';
             $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true);
             break;
         case 'stand_in':
             $dump .= '<h2>' . __('Stand-in structure for view') . ' ' . htmlspecialchars($table) . '</h2>';
             // export a stand-in definition to resolve view dependencies
             $dump .= PMA_getTableDefStandIn($db, $table, $crlf);
     }
     // end switch
     return PMA_exportOutputHandler($dump);
 }
Пример #15
0
     $tmp_select = implode($table_select, "|");
     $tmp_select = "|" . $tmp_select . "|";
 }
 while ($i < $num_tables) {
     if (!isset($single)) {
         $table = mysql_tablename($tables, $i);
     } else {
         $table = $tables[$i];
     }
     if (isset($tmp_select) && is_int(strpos($tmp_select, "|" . $table . "|")) == FALSE) {
         $i++;
     } else {
         $formatted_table_name = isset($GLOBALS["_POST"]["use_backquotes"]) ? PMA_backquote($table) : "'" . $table . "'";
         // If only datas, no need to displays table name
         if ($GLOBALS["_POST"]["what"] != "dataonly") {
             $dump_buffer .= "# --------------------------------------------------------" . $crlf . $crlf . "#" . $crlf . "# " . $strTableStructure . " " . $formatted_table_name . $crlf . "#" . $crlf . $crlf . PMA_getTableDef($db, $table, $crlf) . ";" . $crlf;
         }
         // At least data
         if ($GLOBALS["_POST"]["what"] == "data" || $GLOBALS["_POST"]["what"] == "dataonly") {
             $tcmt = $crlf . "#" . $crlf . "# " . $strDumpingData . " " . $formatted_table_name . $crlf . "#" . $crlf . $crlf;
             $dump_buffer .= $tcmt;
             $tmp_buffer = "";
             /* swapfile */
             swapfile_putdata($dump_buffer);
             /* swapfile */
             PMA_getTableContentFast($db, $table, $add_query, "PMA_myHandler", $exptype);
             $dump_buffer .= $tmp_buffer;
         }
         // end if
         $i++;
     }
Пример #16
0
 /**
  * Outputs table's structure
  *
  * @param string $db          database name
  * @param string $table       table name
  * @param string $crlf        the end of line sequence
  * @param string $error_url   the url to go back in case of error
  * @param string $export_mode 'create_table', 'triggers', 'create_view',
  *                            'stand_in'
  * @param string $export_type 'server', 'database', 'table'
  * @param bool   $do_relation whether to include relation comments
  * @param bool   $do_comments whether to include the pmadb-style column
  *                                comments as comments in the structure;
  *                                this is deprecated but the parameter is
  *                                left here because export.php calls
  *                                PMA_exportStructure() also for other
  * @param bool   $do_mime     whether to include mime comments
  * @param bool   $dates       whether to include creation/update/check dates
  *
  * @return bool Whether it succeeded
  *
  * @access public
  */
 function PMA_exportStructure($db, $table, $crlf, $error_url, $export_mode, $export_type, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false)
 {
     switch ($export_mode) {
         case 'create_table':
             $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"' . ' text:is-list-header="true">' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</text:h>';
             PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates);
             break;
         case 'triggers':
             $triggers = PMA_DBI_get_triggers($db, $table);
             if ($triggers) {
                 $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"' . ' text:is-list-header="true">' . __('Triggers') . ' ' . htmlspecialchars($table) . '</text:h>';
                 PMA_getTriggers($db, $table);
             }
             break;
         case 'create_view':
             $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"' . ' text:is-list-header="true">' . __('Structure for view') . ' ' . htmlspecialchars($table) . '</text:h>';
             PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true);
             break;
         case 'stand_in':
             $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"' . ' text:is-list-header="true">' . __('Stand-in structure for view') . ' ' . htmlspecialchars($table) . '</text:h>';
             // export a stand-in definition to resolve view dependencies
             PMA_getTableDefStandIn($db, $table, $crlf);
     }
     // end switch
     return true;
 }