From 72bc68b45bb668c8c3d217b90ecd18036f81282a Mon Sep 17 00:00:00 2001 From: kjmtsh Date: Mon, 9 Sep 2013 01:39:25 +0000 Subject: [PATCH] Fixed the manipulation of SHOW INDEX query. git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@768773 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- pdoengine.class.php | 15 +++++++++++++++ query.class.php | 24 ++++-------------------- readme-ja.txt | 3 +++ readme.txt | 3 +++ 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/pdoengine.class.php b/pdoengine.class.php index 2eeed63..a794ab0 100644 --- a/pdoengine.class.php +++ b/pdoengine.class.php @@ -773,6 +773,7 @@ class PDOEngine extends PDO { } /** * rewrites the result of SHOW INDEX to the Object compatible with MySQL + * added the WHERE clause manipulation (ver 1.3.1) */ private function convert_to_index_object() { $_results = array(); @@ -839,6 +840,20 @@ class PDOEngine extends PDO { $_columns['Comment'] = ''; $_results[] = new ObjectArray($_columns); } + if (stripos($this->queries[0], 'WHERE') !== false) { + preg_match('/WHERE\\s*(.*)$/im', $this->queries[0], $match); + list($key, $value) = explode('=', $match[1]); + $key = trim($key); + $value = preg_replace("/[\';]/", '', $value); + $value = trim($value); + foreach ($_results as $result) { + if (stripos($value, $result->$key) !== false) { + unset($_results); + $_results[] = $result; + break; + } + } + } } $this->results = $_results; } diff --git a/query.class.php b/query.class.php index 9521523..47d970b 100644 --- a/query.class.php +++ b/query.class.php @@ -347,28 +347,12 @@ class PDOSQLiteDriver { /** * method to execute SHOW INDEX query + * Moved the WHERE clause manipulation to pdoengin.class.php (ver 1.3.1) */ private function _handle_show_index() { - $_columns = array(// No, you'll get no meaningful information.. - 'Key_name' => 'name', - ); - $pattern_0 = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?\\s*WHERE\\s*(.*)$/im'; - $pattern_1 = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?/im'; - if (preg_match($pattern_0, $this->_query, $match_0)) { - $table_name = str_replace("'", '', $match_0[1]); - list($key, $value) = explode('=', $match_0[2]); - $key = trim($key); - $value = preg_replace("/[\';]/", '', $value); - $value = trim($value); - if (array_key_exists($key, $_columns)) { - $key = $_columns[$key]; - $where_clause = 'AND ' . $key . ' LIKE ' . "'" . $value . "%'"; - } else { - $where_clause = ''; - } - $this->_query = "SELECT * FROM sqlite_master WHERE tbl_name='$table_name' $where_clause"; - } elseif (preg_match($pattern_1, $this->_query, $match_1)) { - $table_name = preg_replace("/[\';]/", '', $match_1[1]); + $pattern = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?/im'; + if (preg_match($pattern, $this->_query, $match)) { + $table_name = preg_replace("/[\';]/", '', $match[1]); $table_name = trim($table_name); $this->_query = "SELECT * FROM sqlite_master WHERE tbl_name='$table_name'"; } diff --git a/readme-ja.txt b/readme-ja.txt index 8ca1886..7af2528 100644 --- a/readme-ja.txt +++ b/readme-ja.txt @@ -167,6 +167,9 @@ SQLite Integrationのアップグレードに失敗するようなら、FTPを == Changelog == += 1.3.1 () = +* SHOW INDEXクエリにWHERE句がある場合の処理を変更しました。 + = 1.3 (2013-09-04) = * データベースファイルのスナップショットをzipアーカイブとしてバックアップするユーティリティを追加しました。 * ダッシュボードのスタイルをMP6プラグインに合わせたものに変えました。 diff --git a/readme.txt b/readme.txt index c3411f5..324fcf6 100644 --- a/readme.txt +++ b/readme.txt @@ -158,6 +158,9 @@ When auto upgrading of SQLite Integration fails, please try manual upgrade via F == Changelog == += 1.3.1 () = +* Changed the manipulation of SHOW INDEX query with WHERE clause. + = 1.3 (2013-09-04) = * Added the backup utility that creates the zipped archive of the current snapshot of the database file. * Changed the dashboard style to match MP6 plugin.