bug #3042665 [parser] Add workaround for MySQL way of handling backtick.

This commit is contained in:
Michal Čihař
2010-08-30 17:17:07 +02:00
parent 68e1ff3798
commit 4f487780a0
3 changed files with 46 additions and 5 deletions

View File

@@ -112,6 +112,7 @@ $Id$
+ [interface] Added charts to status tab, profiling page and query results + [interface] Added charts to status tab, profiling page and query results
+ [interface] AJAXification on various pages + [interface] AJAXification on various pages
- [core] Remove last remaining parts of profiling code which was removed in 2006. - [core] Remove last remaining parts of profiling code which was removed in 2006.
- bug #3042665 [parser] Add workaround for MySQL way of handling backtick.
3.3.7.0 (not yet released) 3.3.7.0 (not yet released)
- patch #3050492 [PDF scratchboard] Cannot drag table box to the edge after - patch #3050492 [PDF scratchboard] Cannot drag table box to the edge after

View File

@@ -168,8 +168,20 @@ while (!($GLOBALS['finished'] && $i >= $len) && !$error && !$timeout_passed) {
while (!$endq) { while (!$endq) {
// Find next quote // Find next quote
$pos = strpos($buffer, $quote, $i + 1); $pos = strpos($buffer, $quote, $i + 1);
/*
* Behave same as MySQL and accept end of query as end of backtick.
* I know this is sick, but MySQL behaves like this:
*
* SELECT * FROM `table
*
* is treated like
*
* SELECT * FROM `table`
*/
if ($pos === FALSE && $quote == '`' && $found_delimiter) {
$pos = $first_sql_delimiter - 1;
// No quote? Too short string // No quote? Too short string
if ($pos === FALSE) { } elseif ($pos === FALSE) {
// We hit end of string => unclosed quote, but we handle it as end of query // We hit end of string => unclosed quote, but we handle it as end of query
if ($GLOBALS['finished']) { if ($GLOBALS['finished']) {
$endq = TRUE; $endq = TRUE;

View File

@@ -341,11 +341,39 @@ if (! defined('PMA_MINIMUM_COMMON')) {
$pos = $GLOBALS['PMA_strpos'](' ' . $sql, $quotetype, $oldpos + 1) - 1; $pos = $GLOBALS['PMA_strpos'](' ' . $sql, $quotetype, $oldpos + 1) - 1;
// ($pos === FALSE) // ($pos === FALSE)
if ($pos < 0) { if ($pos < 0) {
if ($c == '`') {
/*
* Behave same as MySQL and accept end of query as end of backtick.
* I know this is sick, but MySQL behaves like this:
*
* SELECT * FROM `table
*
* is treated like
*
* SELECT * FROM `table`
*/
$pos_quote_separator = $GLOBALS['PMA_strpos'](' ' . $sql, $GLOBALS['sql_delimiter'], $oldpos + 1) - 1;
if ($pos_quote_separator < 0) {
$len += 1;
$sql .= '`';
$sql_array['raw'] .= '`';
$pos = $len;
} else {
$len += 1;
$sql = $GLOBALS['PMA_substr']($sql, 0, $pos_quote_separator) . '`' . $GLOBALS['PMA_substr']($sql, $pos_quote_separator);
$sql_array['raw'] = $sql;
$pos = $pos_quote_separator;
}
if (class_exists('PMA_Message')) {
PMA_Message::warning(__('Automatically appended backtick to the end of query!'))->display();
}
} else {
$debugstr = __('Unclosed quote') . ' @ ' . $startquotepos. "\n" $debugstr = __('Unclosed quote') . ' @ ' . $startquotepos. "\n"
. 'STR: ' . htmlspecialchars($quotetype); . 'STR: ' . htmlspecialchars($quotetype);
PMA_SQP_throwError($debugstr, $sql); PMA_SQP_throwError($debugstr, $sql);
return $sql_array; return $sql_array;
} }
}
// If the quote is the first character, it can't be // If the quote is the first character, it can't be
// escaped, so don't do the rest of the code // escaped, so don't do the rest of the code