Skip to content

Commit

Permalink
bug #1812763 [Copy] Table copy when server is in ANSI_QUOTES sql_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lem9 committed Mar 21, 2008
1 parent 1f7c419 commit f207019
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -16,6 +16,8 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA
thanks to Jeroen Vrijkorte - jv_map
- bug #1906980 [Export] Import of VIEWs fails if temp table exists,
thanks to Falk Nisius - klaf
- bug #1812763 [Copy] Table copy when server is in ANSI_QUOTES sql_mode
thanks to Tony Marston - tonymarston

2.11.5.0 (2008-03-01)
- bug #1862661 [GUI] Warn about rename deleting database
Expand Down
19 changes: 13 additions & 6 deletions libraries/Table.class.php
Expand Up @@ -605,9 +605,16 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
}
}
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'] != 'quote_backtick') {
while ($parsed_sql[$i]['type'] != $table_delimiter) {
$i++;
}

Expand All @@ -623,7 +630,7 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
$last = $parsed_sql['len'] - 1;
$backquoted_source_db = PMA_backquote($source_db);
for (++$i; $i <= $last; $i++) {
if ($parsed_sql[$i]['type'] == 'quote_backtick' && $parsed_sql[$i]['data'] == $backquoted_source_db) {
if ($parsed_sql[$i]['type'] == $table_delimiter && $parsed_sql[$i]['data'] == $backquoted_source_db) {
$parsed_sql[$i]['data'] = $target_for_view;
}
}
Expand Down Expand Up @@ -663,8 +670,8 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
$parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints_query']);
$i = 0;

// find the first quote_backtick, it must be the source table name
while ($parsed_sql[$i]['type'] != 'quote_backtick') {
// 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']) {
Expand All @@ -675,15 +682,15 @@ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $
// replace it by the target table name, no need to PMA_backquote()
$parsed_sql[$i]['data'] = $target;

// now we must remove all quote_backtick that follow a CONSTRAINT
// 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'] == 'quote_backtick') {
if ($parsed_sql[$j+1]['type'] == $table_delimiter) {
$parsed_sql[$j+1]['data'] = '';
}
}
Expand Down

0 comments on commit f207019

Please sign in to comment.