Fixed the manipulation of SHOW INDEX query.

git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@768773 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
kjmtsh 2013-09-09 01:39:25 +00:00
parent 3ea3b0974d
commit 72bc68b45b
4 changed files with 25 additions and 20 deletions

View File

@ -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;
}

View File

@ -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'";
}

View File

@ -167,6 +167,9 @@ SQLite Integrationのアップグレードに失敗するようなら、FTPを
== Changelog ==
= 1.3.1 () =
* SHOW INDEXクエリにWHERE句がある場合の処理を変更しました。
= 1.3 (2013-09-04) =
* データベースファイルのスナップショットをzipアーカイブとしてバックアップするユーティリティを追加しました。
* ダッシュボードのスタイルをMP6プラグインに合わせたものに変えました。

View File

@ -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.