bug fix: CREATE INDEX and DROP INDEX query didn't work well

git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@745344 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
kjmtsh 2013-07-24 02:31:01 +00:00
parent b8b7cfc9e5
commit 9322343898
2 changed files with 23 additions and 2 deletions

View File

@ -83,7 +83,7 @@ class PDOEngine extends PDO {
$locked = true; $locked = true;
} else { } else {
$message = __("Database connection error!<br />", 'sqlite-integration'); $message = __("Database connection error!<br />", 'sqlite-integration');
$message .= sprintf(__("Error message is: ", 'sqlite-integration'), $err->getMessage()); $message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err->getMessage());
$this->set_error(__LINE__, __FUNCTION__, $message); $this->set_error(__LINE__, __FUNCTION__, $message);
return false; return false;
} }
@ -183,6 +183,17 @@ class PDOEngine extends PDO {
case 'show_variables': case 'show_variables':
$result = $this->show_variables_workaround($query); $result = $this->show_variables_workaround($query);
break; break;
case 'drop_index':
$pattern = '/^\\s*(DROP\\s*INDEX\\s*.*?)\\s*ON\\s*(.*)/im';
if (preg_match($pattern, $query, $match)) {
$drop_query = 'ALTER TABLE ' . trim($match[2]) . ' ' . trim($match[1]);
$this->query_type = 'alter';
$result = $this->execute_alter_query($drop_query);
$this->return_value = $result;
} else {
$this->return_value = false;
}
break;
default: default:
$engine = $this->prepare_engine($this->query_type); $engine = $this->prepare_engine($this->query_type);
$this->rewritten_query = $engine->rewrite_query($query, $this->query_type); $this->rewritten_query = $engine->rewrite_query($query, $this->query_type);
@ -460,7 +471,7 @@ class PDOEngine extends PDO {
* @return boolean|string * @return boolean|string
*/ */
private function determine_query_type($query) { private function determine_query_type($query) {
$result = preg_match('/^\\s*(EXPLAIN|PRAGMA|SELECT\\s*FOUND_ROWS|SELECT|INSERT|UPDATE|REPLACE|DELETE|ALTER|CREATE|DROP|SHOW\\s*\\w+\\s*\\w+\\s*|DESCRIBE|DESC|TRUNCATE|OPTIMIZE)/i', $query, $match); $result = preg_match('/^\\s*(EXPLAIN|PRAGMA|SELECT\\s*FOUND_ROWS|SELECT|INSERT|UPDATE|REPLACE|DELETE|ALTER|CREATE|DROP\\s*INDEX|DROP|SHOW\\s*\\w+\\s*\\w+\\s*|DESCRIBE|DESC|TRUNCATE|OPTIMIZE)/i', $query, $match);
if (!$result) { if (!$result) {
return false; return false;
@ -482,6 +493,9 @@ class PDOEngine extends PDO {
return false; return false;
} }
} }
if (stripos($this->query_type, 'drop index') !== false) {
$this->query_type = 'drop_index';
}
return true; return true;
} }

View File

@ -25,6 +25,13 @@ class CreateQuery{
public function rewrite_query($query){ public function rewrite_query($query){
$this->_query = $query; $this->_query = $query;
$this->_errors [] = ''; $this->_errors [] = '';
if (preg_match('/^CREATE\\s*(UNIQUE|FULLTEXT|)\\s*INDEX/ims', $this->_query, $match)) {
if (isset($match[1]) && stripos($match[1], 'fulltext') !== false) {
return 'SELECT 1=1';
} else {
return $this->_query;
}
}
$this->strip_backticks(); $this->strip_backticks();
$this->get_table_name(); $this->get_table_name();
$this->rewrite_comments(); $this->rewrite_comments();