minor fixes and improvements, formating, documentation

This commit is contained in:
Sebastian Mendel
2006-02-21 13:17:40 +00:00
parent f341c72fbe
commit b5a19a0b83
2 changed files with 168 additions and 132 deletions

View File

@@ -20,6 +20,8 @@ $Source$
* db_operations.php, tbl_move_copy.php, tbl_properties_operations.php, * db_operations.php, tbl_move_copy.php, tbl_properties_operations.php,
libraries\Table.class.php, libraries\tbl_move_copy.php: libraries\Table.class.php, libraries\tbl_move_copy.php:
merged libraries\tbl_move_copy.php in class PMA_Table merged libraries\tbl_move_copy.php in class PMA_Table
* libraries/Table.class.php:
minor fixes and improvements, formating, documentation
2006-02-20 Marc Delisle <lem9@users.sourceforge.net> 2006-02-20 Marc Delisle <lem9@users.sourceforge.net>

View File

@@ -221,19 +221,38 @@ class PMA_Table {
} }
/** /**
* @TODO add documentation * generates column/field specification for ALTER or CREATE TABLE syntax
* *
* @todo move into class PMA_Column
* @static * @static
* @param string $name name
* @param string $type type ('INT', 'VARCHAR', 'BIT', ...)
* @param string $length length ('2', '5,2', '', ...)
* @param string $attribute
* @param string $collation
* @param string $null with 'NULL' or 'NOT NULL'
* @param string $default default value
* @param boolean $default_current_timestamp whether default value is
* CURRENT_TIMESTAMP or not
* this overrides $default value
* @param string $extra 'AUTO_INCREMENT'
* @param string $comment field comment
* @param array &$field_primary list of fields for PRIMARY KEY
* @param string $index
* @param string $default_orig
* @return string field specification
*/ */
function generateFieldSpec($name, $type, $length, $attribute, function generateFieldSpec($name, $type, $length = '', $attribute = '',
$collation, $null, $default, $default_current_timestamp, $extra, $collation = '', $null = false, $default = '',
$comment='', &$field_primary, $index, $default_orig = false) $default_current_timestamp = false, $extra = '', $comment = '',
&$field_primary, $index, $default_orig = false)
{ {
// $default_current_timestamp has priority over $default // $default_current_timestamp has priority over $default
// TODO: on the interface, some js to clear the default value // TODO: on the interface, some js to clear the default value
// when the default current_timestamp is checked // when the default current_timestamp is checked
// TODO: include db-name
$query = PMA_backquote($name) . ' ' . $type; $query = PMA_backquote($name) . ' ' . $type;
if ($length != '' if ($length != ''
@@ -251,7 +270,7 @@ class PMA_Table {
$query .= PMA_generateCharsetQueryPart($collation); $query .= PMA_generateCharsetQueryPart($collation);
} }
if (!($null === false)) { if ($null !== false) {
if (!empty($null)) { if (!empty($null)) {
$query .= ' NOT NULL'; $query .= ' NOT NULL';
} else { } else {
@@ -259,11 +278,12 @@ class PMA_Table {
} }
} }
if ($default_current_timestamp && strpos(' ' . strtoupper($type), 'TIMESTAMP') == 1) { if ($default_current_timestamp
&& strpos(' ' . strtoupper($type), 'TIMESTAMP') == 1) {
$query .= ' DEFAULT CURRENT_TIMESTAMP'; $query .= ' DEFAULT CURRENT_TIMESTAMP';
// 0 is empty in PHP // auto_increment field cannot have a default value
// auto_increment field cannot have a default value } elseif ($extra !== 'AUTO_INCREMENT'
} elseif ($extra !== 'AUTO_INCREMENT' && (!empty($default) || $default == '0' || $default != $default_orig)) { && (strlen($default) || $default != $default_orig)) {
if (strtoupper($default) == 'NULL') { if (strtoupper($default) == 'NULL') {
$query .= ' DEFAULT NULL'; $query .= ' DEFAULT NULL';
} else { } else {
@@ -308,42 +328,49 @@ class PMA_Table {
*/ */
function countRecords($db, $table, $ret = false, $force_exact = false) function countRecords($db, $table, $ret = false, $force_exact = false)
{ {
global $err_url, $cfg; $row_count = false;
if (!$force_exact) {
$result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, true) . '\';'); if (! $force_exact) {
$showtable = PMA_DBI_fetch_assoc($result); $row_count = PMA_DBI_fetch_value(
$num = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \''
if ($num < $cfg['MaxExactCount']) { . PMA_sqlAddslashes($table, true) . '\';',
unset($num); 0, 'Rows');
}
PMA_DBI_free_result($result);
} }
$tbl_is_view = PMA_Table::isView($db, $table); $tbl_is_view = PMA_Table::isView($db, $table);
if (!isset($num)) { if (false === $row_count || $row_count < $GLOBALS['cfg']['MaxExactCount']) {
if (! $tbl_is_view) { if (! $tbl_is_view) {
$num = PMA_DBI_fetch_value('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); $row_count = PMA_DBI_fetch_value(
// necessary? 'SELECT COUNT(*) FROM ' . PMA_backquote($db) . '.'
if (! $num) { . PMA_backquote($table));
$num = 0;
}
// since counting all rows of a view could be too long // since counting all rows of a view could be too long
} else { } else {
$result = PMA_DBI_query('SELECT 1 FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT ' . $cfg['MaxExactCount'], null, PMA_DBI_QUERY_STORE); $result = PMA_DBI_query(
$num = PMA_DBI_num_rows($result); 'SELECT 1 FROM ' . PMA_backquote($db) . '.'
. PMA_backquote($table) . ' LIMIT '
. $GLOBALS['cfg']['MaxExactCount'],
null, PMA_DBI_QUERY_STORE);
$row_count = PMA_DBI_num_rows($result);
PMA_DBI_free_result($result);
} }
} }
if ($ret) { if ($ret) {
return $num; return $row_count;
} else { }
// Note: as of PMA 2.8.0, we no longer seem to be using
// PMA_Table::countRecords() in display mode. /**
echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']); * @deprecated at the moment nowhere is $return = false used
if ($tbl_is_view) { */
echo '&nbsp;' . sprintf($GLOBALS['strViewMaxExactCount'], $cfg['MaxExactCount'], '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]'); // Note: as of PMA 2.8.0, we no longer seem to be using
} // PMA_Table::countRecords() in display mode.
return true; echo PMA_formatNumber($row_count, 0);
if ($tbl_is_view) {
echo '&nbsp;'
. sprintf($GLOBALS['strViewMaxExactCount'],
$GLOBALS['cfg']['MaxExactCount'],
'[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]');
} }
} // end of the 'PMA_Table::countRecords()' function } // end of the 'PMA_Table::countRecords()' function
@@ -356,7 +383,7 @@ class PMA_Table {
{ {
$empty_a = array(); $empty_a = array();
return PMA_backquote($oldcol) . ' ' return PMA_backquote($oldcol) . ' '
. PMA_generateFieldSpec($newcol, $type, $length, $attribute, . PMA_Table::generateFieldSpec($newcol, $type, $length, $attribute,
$collation, $null, $default, $default_current_timestamp, $extra, $collation, $null, $default, $default_current_timestamp, $extra,
$comment, $empty_a, -1, $default_orig); $comment, $empty_a, -1, $default_orig);
} // end function } // end function
@@ -379,56 +406,65 @@ class PMA_Table {
* *
* @author Garvin Hicking <me@supergarv.de> * @author Garvin Hicking <me@supergarv.de>
*/ */
function duplicateInfo($work, $pma_table, $get_fields, $where_fields, $new_fields) { function duplicateInfo($work, $pma_table, $get_fields, $where_fields,
global $cfgRelation; $new_fields) {
$last_id = -1; $last_id = -1;
if ($cfgRelation[$work]) { if ($GLOBALS['cfgRelation'][$work]) {
$select_parts = array(); $select_parts = array();
$row_fields = array(); $row_fields = array();
foreach ($get_fields AS $nr => $get_field) { foreach ($get_fields as $get_field) {
$select_parts[] = PMA_backquote($get_field); $select_parts[] = PMA_backquote($get_field);
$row_fields[$get_field] = 'cc'; $row_fields[$get_field] = 'cc';
} }
$where_parts = array(); $where_parts = array();
foreach ($where_fields AS $_where => $_value) { foreach ($where_fields as $_where => $_value) {
$where_parts[] = PMA_backquote($_where) . ' = \'' . PMA_sqlAddslashes($_value) . '\''; $where_parts[] = PMA_backquote($_where) . ' = \''
. PMA_sqlAddslashes($_value) . '\'';
} }
$new_parts = array(); $new_parts = array();
$new_value_parts = array(); $new_value_parts = array();
foreach ($new_fields AS $_where => $_value) { foreach ($new_fields as $_where => $_value) {
$new_parts[] = PMA_backquote($_where); $new_parts[] = PMA_backquote($_where);
$new_value_parts[] = PMA_sqlAddslashes($_value); $new_value_parts[] = PMA_sqlAddslashes($_value);
} }
$table_copy_query = 'SELECT ' . implode(', ', $select_parts) $table_copy_query = '
. ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation[$pma_table]) SELECT ' . implode(', ', $select_parts) . '
. ' WHERE ' . implode(' AND ', $where_parts); FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
. PMA_backquote($GLOBALS['cfgRelation'][$pma_table]) . '
WHERE ' . implode(' AND ', $where_parts);
// must use PMA_DBI_QUERY_STORE here, since we execute another // must use PMA_DBI_QUERY_STORE here, since we execute another
// query inside the loop // query inside the loop
$table_copy_rs = PMA_query_as_cu($table_copy_query, true, PMA_DBI_QUERY_STORE); $table_copy_rs = PMA_query_as_cu($table_copy_query, true,
PMA_DBI_QUERY_STORE);
while ($table_copy_row = @PMA_DBI_fetch_assoc($table_copy_rs)) { while ($table_copy_row = @PMA_DBI_fetch_assoc($table_copy_rs)) {
$value_parts = array(); $value_parts = array();
foreach ($table_copy_row AS $_key => $_val) { foreach ($table_copy_row as $_key => $_val) {
if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') { if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') {
$value_parts[] = PMA_sqlAddslashes($_val); $value_parts[] = PMA_sqlAddslashes($_val);
} }
} }
$new_table_query = 'INSERT IGNORE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation[$pma_table]) $new_table_query = '
. ' (' . implode(', ', $select_parts) . ', ' . implode(', ', $new_parts) . ')' INSERT IGNORE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db'])
. ' VALUES ' . '.' . PMA_backquote($GLOBALS['cfgRelation'][$pma_table]) . '
. ' (\'' . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')'; (' . implode(', ', $select_parts) . ',
' . implode(', ', $new_parts) . ')
VALUES
(\'' . implode('\', \'', $value_parts) . '\',
\'' . implode('\', \'', $new_value_parts) . '\')';
$new_table_rs = PMA_query_as_cu($new_table_query); PMA_query_as_cu($new_table_query);
$last_id = PMA_DBI_insert_id(); $last_id = PMA_DBI_insert_id();
} // end while } // end while
PMA_DBI_free_result($table_copy_rs);
return $last_id; return $last_id;
} }
@@ -440,10 +476,14 @@ class PMA_Table {
* Copies or renames table * Copies or renames table
* FIXME: use RENAME * FIXME: use RENAME
* *
* @author Michal Čihař <michal@cihar.com> * @author Michal Cihar <michal@cihar.com>
*/ */
function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move) { function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move) {
global $cfgRelation, $dblist, $err_url, $sql_query; global $dblist, $err_url;
if (! isset($GLOBALS['sql_query'])) {
$GLOBALS['sql_query'] = '';
}
// set export settings we need // set export settings we need
$GLOBALS['use_backquotes'] = 1; $GLOBALS['use_backquotes'] = 1;
@@ -452,7 +492,8 @@ class PMA_Table {
// Ensure the target is valid // Ensure the target is valid
if (count($dblist) > 0 && if (count($dblist) > 0 &&
(! in_array($source_db, $dblist) || ! in_array($target_db, $dblist))) { (! in_array($source_db, $dblist) || ! in_array($target_db, $dblist))) {
exit(); // TODO exit really needed here? or just a return?
exit;
} }
$source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table); $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table);
@@ -468,7 +509,7 @@ class PMA_Table {
// do not create the table if dataonly // do not create the table if dataonly
if ($what != 'dataonly') { if ($what != 'dataonly') {
require_once('./libraries/export/sql.php'); require_once './libraries/export/sql.php';
$no_constraints_comments = true; $no_constraints_comments = true;
$sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url); $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
@@ -478,7 +519,9 @@ class PMA_Table {
/* nijel: Find table name in query and replace it */ /* nijel: Find table name in query and replace it */
$i = 0; $i = 0;
while ($parsed_sql[$i]['type'] != 'quote_backtick') $i++; while ($parsed_sql[$i]['type'] != 'quote_backtick') {
$i++;
}
/* no need to PMA_backquote() */ /* no need to PMA_backquote() */
$parsed_sql[$i]['data'] = $target; $parsed_sql[$i]['data'] = $target;
@@ -487,29 +530,25 @@ class PMA_Table {
$sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only'); $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
// If table exists, and 'add drop table' is selected: Drop it! // If table exists, and 'add drop table' is selected: Drop it!
$drop_query = ''; $drop_query = '';
if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') { if (isset($GLOBALS['drop_if_exists'])
$drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table); && $GLOBALS['drop_if_exists'] == 'true') {
$result = PMA_DBI_query($drop_query); $drop_query = 'DROP TABLE IF EXISTS '
. PMA_backquote($target_db) . '.'
. PMA_backquote($target_table);
PMA_DBI_query($drop_query);
if (isset($sql_query)) { $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
$sql_query .= "\n" . $drop_query . ';';
} else {
$sql_query = $drop_query . ';';
}
// garvin: If an existing table gets deleted, maintain any entries // garvin: If an existing table gets deleted, maintain any
// for the PMA_* tables // entries for the PMA_* tables
$maintain_relations = true; $maintain_relations = true;
} }
$result = @PMA_DBI_query($sql_structure); @PMA_DBI_query($sql_structure);
if (isset($sql_query)) { $GLOBALS['sql_query'] .= "\n" . $sql_structure . ';';
$sql_query .= "\n" . $sql_structure . ';';
} else {
$sql_query = $sql_structure . ';';
}
if (($move || isset($GLOBALS['constraints'])) && isset($GLOBALS['sql_constraints'])) { if (($move || isset($GLOBALS['constraints']))
&& isset($GLOBALS['sql_constraints'])) {
$parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']); $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']);
$i = 0; $i = 0;
@@ -537,31 +576,28 @@ class PMA_Table {
// Generate query back // Generate query back
$GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql, 'query_only'); $GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql,
$result = PMA_DBI_query($GLOBALS['sql_constraints']); 'query_only');
if (isset($sql_query)) { PMA_DBI_query($GLOBALS['sql_constraints']);
$sql_query .= "\n" . $GLOBALS['sql_constraints']; $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints'];
} else {
$sql_query = $GLOBALS['sql_constraints'];
}
unset($GLOBALS['sql_constraints']); unset($GLOBALS['sql_constraints']);
} }
} else { } else {
$sql_query=''; $GLOBALS['sql_query'] = '';
} }
// Copy the data // Copy the data
//if ($result != false && ($what == 'data' || $what == 'dataonly')) { //if ($result != false && ($what == 'data' || $what == 'dataonly')) {
if ($what == 'data' || $what == 'dataonly') { if ($what == 'data' || $what == 'dataonly') {
$sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source; $sql_insert_data =
'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
PMA_DBI_query($sql_insert_data); PMA_DBI_query($sql_insert_data);
$sql_query .= "\n\n" . $sql_insert_data . ';'; $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';';
} }
require_once('./libraries/relation.lib.php'); require_once './libraries/relation.lib.php';
$cfgRelation = PMA_getRelationsParam(); $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
// Drops old table if the user has requested to move it // Drops old table if the user has requested to move it
if ($move) { if ($move) {
@@ -574,55 +610,52 @@ class PMA_Table {
PMA_DBI_query($sql_drop_table); PMA_DBI_query($sql_drop_table);
// garvin: Move old entries from PMA-DBs to new table // garvin: Move old entries from PMA-DBs to new table
if ($cfgRelation['commwork']) { if ($GLOBALS['cfgRelation']['commwork']) {
$remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info'])
. ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\', '
. ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
. ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
$rmv_rs = PMA_query_as_cu($remove_query); PMA_query_as_cu($remove_query);
unset($remove_query); unset($remove_query);
} }
// garvin: updating bookmarks is not possible since only a single table is moved, // garvin: updating bookmarks is not possible since only a single table is moved,
// and not the whole DB. // and not the whole DB.
// if ($cfgRelation['bookmarkwork']) { // if ($GLOBALS['cfgRelation']['bookmarkwork']) {
// $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['bookmark']) // $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['bookmark'])
// . ' SET dbase = \'' . PMA_sqlAddslashes($target_db) . '\'' // . ' SET dbase = \'' . PMA_sqlAddslashes($target_db) . '\''
// . ' WHERE dbase = \'' . PMA_sqlAddslashes($source_db) . '\''; // . ' WHERE dbase = \'' . PMA_sqlAddslashes($source_db) . '\'';
// $rmv_rs = PMA_query_as_cu($remove_query); // $rmv_rs = PMA_query_as_cu($remove_query);
// unset($rmv_query); // unset($rmv_query);
// } // }
if ($cfgRelation['displaywork']) { if ($GLOBALS['cfgRelation']['displaywork']) {
$table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info'])
. ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\', '
. ' table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' table_name = \'' . PMA_sqlAddslashes($target_table) . '\''
. ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
$tb_rs = PMA_query_as_cu($table_query); PMA_query_as_cu($table_query);
unset($table_query); unset($table_query);
unset($tb_rs);
} }
if ($cfgRelation['relwork']) { if ($GLOBALS['cfgRelation']['relwork']) {
$table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation'])
. ' SET foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . ' SET foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\','
. ' foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\''
. ' WHERE foreign_db = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($source_db) . '\''
. ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\''; . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
$tb_rs = PMA_query_as_cu($table_query); PMA_query_as_cu($table_query);
unset($table_query); unset($table_query);
unset($tb_rs);
$table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation'])
. ' SET master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . ' SET master_table = \'' . PMA_sqlAddslashes($target_table) . '\','
. ' master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' master_db = \'' . PMA_sqlAddslashes($target_db) . '\''
. ' WHERE master_db = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' WHERE master_db = \'' . PMA_sqlAddslashes($source_db) . '\''
. ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\''; . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
$tb_rs = PMA_query_as_cu($table_query); PMA_query_as_cu($table_query);
unset($table_query); unset($table_query);
unset($tb_rs);
} }
// garvin: [TODO] Can't get moving PDFs the right way. The page numbers always // garvin: [TODO] Can't get moving PDFs the right way. The page numbers always
@@ -630,24 +663,23 @@ class PMA_Table {
// seem to be stored on a per-database basis. Would the author of pdf support // seem to be stored on a per-database basis. Would the author of pdf support
// please have a look at it? // please have a look at it?
if ($cfgRelation['pdfwork']) { if ($GLOBALS['cfgRelation']['pdfwork']) {
$table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords'])
. ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\','
. ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
. ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
$tb_rs = PMA_query_as_cu($table_query); PMA_query_as_cu($table_query);
unset($table_query); unset($table_query);
unset($tb_rs);
/* /*
$pdf_query = 'SELECT pdf_page_number ' $pdf_query = 'SELECT pdf_page_number '
. ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\''; . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\'';
$pdf_rs = PMA_query_as_cu($pdf_query); $pdf_rs = PMA_query_as_cu($pdf_query);
while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) { while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) {
$table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['pdf_pages'])
. ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
. ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\''
. ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\''; . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\'';
@@ -658,15 +690,15 @@ class PMA_Table {
*/ */
} }
$sql_query .= "\n\n" . $sql_drop_table . ';'; $GLOBALS['sql_query'] .= "\n\n" . $sql_drop_table . ';';
} else { } else {
// garvin: Create new entries as duplicates from old PMA DBs // garvin: Create new entries as duplicates from old PMA DBs
if ($what != 'dataonly' && !isset($maintain_relations)) { if ($what != 'dataonly' && !isset($maintain_relations)) {
if ($cfgRelation['commwork']) { if ($GLOBALS['cfgRelation']['commwork']) {
// Get all comments and MIME-Types for current table // Get all comments and MIME-Types for current table
$comments_copy_query = 'SELECT $comments_copy_query = 'SELECT
column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ' column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
WHERE WHERE
db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND
table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
@@ -674,19 +706,21 @@ class PMA_Table {
// Write every comment as new copied entry. [MIME] // Write every comment as new copied entry. [MIME]
while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) { while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
$new_comment_query = 'REPLACE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) $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') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') '
. ' VALUES(' . ' VALUES('
. '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_db) . '\','
. '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\','
. '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\''
. ($cfgRelation['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . ($GLOBALS['cfgRelation']['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\','
. '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\','
. '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\','
. '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '')
. ')'; . ')';
$new_comment_rs = PMA_query_as_cu($new_comment_query); PMA_query_as_cu($new_comment_query);
} // end while } // end while
PMA_DBI_free_result($comments_copy_rs);
unset($comments_copy_rs);
} }
// duplicating the bookmarks must not be done here, but // duplicating the bookmarks must not be done here, but
@@ -746,19 +780,19 @@ class PMA_Table {
PMA_DBI_select_db($GLOBALS['db']); PMA_DBI_select_db($GLOBALS['db']);
$sql_query = ' $GLOBALS['sql_query'] = '
ALTER TABLE ' . PMA_backquote($old_name) . ' ALTER TABLE ' . PMA_backquote($old_name) . '
RENAME ' . PMA_backquote($new_name) . ';'; RENAME ' . PMA_backquote($new_name) . ';';
if (! PMA_DBI_query($sql_query)) { if (! PMA_DBI_query($GLOBALS['sql_query'])) {
return false; return false;
} }
// garvin: Move old entries from comments to new table // garvin: Move old entries from comments to new table
require_once('./libraries/relation.lib.php'); require_once './libraries/relation.lib.php';
$cfgRelation = PMA_getRelationsParam(); $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
if ($cfgRelation['commwork']) { if ($GLOBALS['cfgRelation']['commwork']) {
$remove_query = ' $remove_query = '
UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\' SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\'
WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
@@ -766,9 +800,9 @@ class PMA_Table {
unset($remove_query); unset($remove_query);
} }
if ($cfgRelation['displaywork']) { if ($GLOBALS['cfgRelation']['displaywork']) {
$table_query = ' $table_query = '
UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . '
SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\' SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\'
WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
@@ -776,16 +810,16 @@ class PMA_Table {
unset($table_query); unset($table_query);
} }
if ($cfgRelation['relwork']) { if ($GLOBALS['cfgRelation']['relwork']) {
$table_query = ' $table_query = '
UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
SET foreign_table = \'' . PMA_sqlAddslashes($new_name) . '\' SET foreign_table = \'' . PMA_sqlAddslashes($new_name) . '\'
WHERE foreign_db = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' WHERE foreign_db = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
AND foreign_table = \'' . PMA_sqlAddslashes($old_name) . '\''; AND foreign_table = \'' . PMA_sqlAddslashes($old_name) . '\'';
PMA_query_as_cu($table_query); PMA_query_as_cu($table_query);
$table_query = ' $table_query = '
UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
SET master_table = \'' . PMA_sqlAddslashes($new_name) . '\' SET master_table = \'' . PMA_sqlAddslashes($new_name) . '\'
WHERE master_db = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' WHERE master_db = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
AND master_table = \'' . PMA_sqlAddslashes($old_name) . '\''; AND master_table = \'' . PMA_sqlAddslashes($old_name) . '\'';
@@ -793,9 +827,9 @@ class PMA_Table {
unset($table_query); unset($table_query);
} }
if ($cfgRelation['pdfwork']) { if ($GLOBALS['cfgRelation']['pdfwork']) {
$table_query = ' $table_query = '
UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . '
SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\' SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\'
WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';