3 // vim: expandtab sw=4 ts=4 sts=4:
6 * Insert data from one table to another one
8 * @param string the original insert statement
10 * @global string the database name
11 * @global string the original table name
12 * @global string the target database and table names
13 * @global string the sql query used to copy the data
15 function PMA_myHandler($sql_insert = '')
17 global $db, $table, $target;
18 global $sql_insert_data;
20 $sql_insert = eregi_replace('INSERT INTO (`?)' . $table . '(`?)', 'INSERT INTO ' . $target, $sql_insert);
21 $result = PMA_mysql_query($sql_insert) or PMA_mysqlDie('', $sql_insert, '', $GLOBALS['err_url']);
23 $sql_insert_data .= $sql_insert . ';' . "\n";
24 } // end of the 'PMA_myHandler()' function
28 * Gets some core libraries
30 require('./libraries/grab_globals.lib.php3');
31 require('./libraries/common.lib.php3');
35 * Defines the url to return to in case of error in a sql statement
37 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
41 * Selects the database to work with
43 PMA_mysql_select_db($db);
47 * A target table name has been sent to this script -> do the work
49 if (isset($new_name) && trim($new_name) != '') {
53 if (get_magic_quotes_gpc()) {
54 if (!empty($target_db)) {
55 $target_db = stripslashes($target_db);
57 $target_db = stripslashes($db);
59 $new_name = stripslashes($new_name);
62 // Ensure the target is valid
63 if (count($dblist) > 0 &&
64 (PMA_isInto($db, $dblist) == -1 ||
PMA_isInto($target_db, $dblist) == -1)) {
67 if (PMA_MYSQL_INT_VERSION
< 32306) {
68 PMA_checkReservedWords($target_db, $err_url);
69 PMA_checkReservedWords($new_name, $err_url);
72 $source = PMA_backquote($db) . '.' . PMA_backquote($table);
73 $target = PMA_backquote($target_db) . '.' . PMA_backquote($new_name);
75 include('./libraries/build_dump.lib.php3');
77 $sql_structure = PMA_getTableDef($db, $table, "\n", $err_url);
78 $parsed_sql = PMA_SQP_parse($sql_structure);
79 // no need to PMA_backquote()
80 $parsed_sql[2]['data'] = $target;
81 $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
83 // do not create the table if dataonly
84 if ($what != 'dataonly') {
85 $result = @PMA_mysql_query
($sql_structure);
86 if (PMA_mysql_error()) {
87 include('./header.inc.php3');
88 PMA_mysqlDie('', $sql_structure, '', $err_url);
89 } else if (isset($sql_query)) {
90 $sql_query .= "\n" . $sql_structure . ';';
92 $sql_query = $sql_structure . ';';
99 if ($result != FALSE && ($what == 'data' ||
$what == 'dataonly')) {
100 // speedup copy table - staybyte - 22. Juni 2001
101 if (PMA_MYSQL_INT_VERSION
>= 32300) {
102 $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
103 $result = @PMA_mysql_query
($sql_insert_data);
104 if (PMA_mysql_error()) {
105 include('./header.inc.php3');
106 PMA_mysqlDie('', $sql_insert_data, '', $err_url);
108 } // end MySQL >= 3.23
110 $sql_insert_data = '';
111 PMA_getTableContent($db, $table, 0, 0, 'PMA_myHandler', $err_url,'');
112 } // end MySQL < 3.23
113 $sql_query .= "\n\n" . $sql_insert_data;
116 // Drops old table if the user has requested to move it
117 if (isset($submit_move)) {
118 $sql_drop_table = 'DROP TABLE ' . $source;
119 $result = @PMA_mysql_query
($sql_drop_table);
120 if (PMA_mysql_error()) {
121 include('./header.inc.php3');
122 PMA_mysqlDie('', $sql_drop_table, '', $err_url);
124 $sql_query .= "\n\n" . $sql_drop_table . ';';
129 $message = (isset($submit_move) ?
$strMoveTableOK : $strCopyTableOK);
130 $message = sprintf($message, $source, $target);
132 $js_to_run = 'functions.js';
133 include('./header.inc.php3');
134 } // end is target table name
138 * No new name for the table!
141 include('./header.inc.php3');
142 PMA_mysqlDie($strTableEmpty, '', '', $err_url);
147 * Back to the calling script
149 require('./tbl_properties.php3');