bug fixes

git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@877068 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
kjmtsh 2014-03-18 10:06:36 +00:00
parent 71a1df03db
commit f0a5b97f3c
5 changed files with 62 additions and 20 deletions

View File

@ -278,6 +278,23 @@ class PDOEngine extends PDO {
/** /**
* Function to execute query(). * Function to execute query().
* *
* Divide the query types into seven different ones. That is to say:
*
* 1. SELECT SQL_CALC_FOUND_ROWS
* 2. INSERT
* 3. CREATE TABLE(INDEX)
* 4. ALTER TABLE
* 5. SHOW VARIABLES
* 6. DROP INDEX
* 7. THE OTHERS
*
* #1 is just a tricky play. See the private function handle_sql_count() in query.class.php.
* From #2 through #5 call different functions respectively.
* #6 call the ALTER TABLE query.
* #7 is a normal process: sequentially call prepare_query() and execute_query().
*
* #1 process has been changed since version 1.5.1.
*
* @param $query full SQL statement string * @param $query full SQL statement string
* @return mixed according to the query type * @return mixed according to the query type
* @see PDO::query() * @see PDO::query()
@ -287,7 +304,7 @@ class PDOEngine extends PDO {
$this->queries[] = "Raw query:\n$query"; $this->queries[] = "Raw query:\n$query";
$res = $this->determine_query_type($query); $res = $this->determine_query_type($query);
if (!$res) { if (!$res && defined(PDO_DEBUG) && PDO_DEBUG) {
$bailoutString = sprintf(__("<h1>Unknown query type</h1><p>Sorry, we cannot determine the type of query that is requested.</p><p>The query is %s</p>", 'sqlite-integration'), $query); $bailoutString = sprintf(__("<h1>Unknown query type</h1><p>Sorry, we cannot determine the type of query that is requested.</p><p>The query is %s</p>", 'sqlite-integration'), $query);
$this->set_error(__LINE__, __FUNCTION__, $bailoutString); $this->set_error(__LINE__, __FUNCTION__, $bailoutString);
} }
@ -296,10 +313,11 @@ class PDOEngine extends PDO {
$_column = array('FOUND_ROWS()' => ''); $_column = array('FOUND_ROWS()' => '');
$column = array(); $column = array();
if (!is_null($this->found_rows_result)) { if (!is_null($this->found_rows_result)) {
$this->num_rows = count($this->found_rows_result); $this->num_rows = $this->found_rows_result;
foreach ($this->found_rows_result[0] as $key => $value) { $_column['FOUND_ROWS()'] = $this->num_rows;
$_column['FOUND_ROWS()'] = $value; // foreach ($this->found_rows_result[0] as $key => $value) {
} // $_column['FOUND_ROWS()'] = $value;
// }
$column[] = new ObjectArray($_column); $column[] = new ObjectArray($_column);
$this->results = $column; $this->results = $column;
$this->found_rows_result = null; $this->found_rows_result = null;

View File

@ -176,14 +176,12 @@ class PDOSQLiteDriver {
* *
* This is a kind of tricky play. * This is a kind of tricky play.
* 1. remove SQL_CALC_FOUND_ROWS option, and give it to the pdo engine * 1. remove SQL_CALC_FOUND_ROWS option, and give it to the pdo engine
* 2. make another $wpdb instance, and execute SELECT COUNT(*) query * 2. make another $wpdb instance, and execute the rewritten query
* 3. give the returned value to the original instance variable without LIMIT * 3. give the returned value (integer: number of the rows) to the original instance variable without LIMIT
* *
* When SQL statement contains GROUP BY option, SELECT COUNT query doesn't * We no longer use SELECT COUNT query, because it returns the inexact values when used with WP_Meta_Query().
* go well. So we remove the GROUP BY, which means the returned value may
* be a approximate one.
* *
* This kind of statement is required for WordPress to calculate the paging. * This kind of statement is required for WordPress to calculate the paging information.
* see also WP_Query class in wp-includes/query.php * see also WP_Query class in wp-includes/query.php
* *
* @access private * @access private
@ -196,17 +194,18 @@ class PDOSQLiteDriver {
// we make the data for next SELECE FOUND_ROWS() statement // we make the data for next SELECE FOUND_ROWS() statement
$unlimited_query = preg_replace('/\\bLIMIT\\s*.*/imsx', '', $this->_query); $unlimited_query = preg_replace('/\\bLIMIT\\s*.*/imsx', '', $this->_query);
$unlimited_query = preg_replace('/\\bGROUP\\s*BY\\s*.*/imsx', '', $unlimited_query); $unlimited_query = preg_replace('/\\bGROUP\\s*BY\\s*.*/imsx', '', $unlimited_query);
$unlimited_query = $this->_transform_to_count($unlimited_query); // we no longer use SELECT COUNT query
// $unlimited_query = $this->_transform_to_count($unlimited_query);
$_wpdb = new PDODB(); $_wpdb = new PDODB();
$result = $_wpdb->query($unlimited_query); $result = $_wpdb->query($unlimited_query);
$wpdb->dbh->found_rows_result = $_wpdb->last_result; $wpdb->dbh->found_rows_result = $result;
$_wpdb = null; $_wpdb = null;
} }
} }
/** /**
* Call back method to change SELECT query to SELECT COUNT(). * Call back method to change SELECT query to SELECT COUNT().
* *
* revised for version 1.5.1 * obsolite since version 1.5.1
* *
* @param string $query the query to be transformed * @param string $query the query to be transformed
* @return string the transformed query * @return string the transformed query
@ -488,17 +487,39 @@ class PDOSQLiteDriver {
* Method to handle ON DUPLICATE KEY UPDATE statement. * Method to handle ON DUPLICATE KEY UPDATE statement.
* *
* First we use SELECT query and check if INSERT is allowed or not. * First we use SELECT query and check if INSERT is allowed or not.
* Rewriting procedure looks like a detour, but I've got no other way. * Rewriting procedure looks like a detour, but I've got no other ways.
*
* Added the literal check since the version 1.5.1.
* *
* @return void * @return void
* @access private * @access private
*/ */
private function execute_duplicate_key_update() { private function execute_duplicate_key_update() {
$rewrite_flag = true;
$update = false; $update = false;
$unique_keys_for_cond = array(); $unique_keys_for_cond = array();
$unique_keys_for_check = array(); $unique_keys_for_check = array();
$pattern = '/^\\s*INSERT\\s*INTO\\s*(\\w+)?\\s*(.*)\\s*ON\\s*DUPLICATE\\s*KEY\\s*UPDATE\\s*(.*)$/ims'; $pattern = '/^\\s*INSERT\\s*INTO\\s*(\\w+)?\\s*(.*)\\s*ON\\s*DUPLICATE\\s*KEY\\s*UPDATE\\s*(.*)$/ims';
if (preg_match($pattern, $this->_query, $match_0)) { if (preg_match($pattern, $this->_query, $match_0)) {
$tokens = preg_split("/(''|')/s", $this->_query, -1, PREG_SPLIT_DELIM_CAPTURE);
$literal = false;
foreach ($tokens as $token) {
if (strpos($token, "'") !== false) {
if ($literal) {
$literal = false;
} else {
$literal = true;
}
} else {
if ($literal === false && stripos($token, 'ON DUPLICATE KEY UPDATE') !== false) {
$rewrite_flag = true;
break;
} else {
$rewrite_flag = false;
}
}
}
if (!$rewrite_flag) return;
$table_name = trim($match_0[1]); $table_name = trim($match_0[1]);
$insert_data = trim($match_0[2]); $insert_data = trim($match_0[2]);
$update_data = trim($match_0[3]); $update_data = trim($match_0[3]);

View File

@ -160,7 +160,8 @@ query_posts() や WP_Query() を使うときに、オプションの一部が機
== Changelog == == Changelog ==
= 1.5.1 (2014-02-06) = = 1.5.1 (2014-02-06) =
* SQL_CALC_FOUND_ROW ステートメントのバグを修正しました。メインクエリと WP_Query のページング情報に関連したものです。 * 未対応のクエリに対するエラーメッセージのコントロールができていないのを修正しました。
* SQL_CALC_FOUND_ROW ステートメントのバグを修正しました。メインクエリと WP_Query、WP_Meta_Query などのページング情報に関連したものです。
* コメント本文からバッククォートが削除されるバグを修正しました。 * コメント本文からバッククォートが削除されるバグを修正しました。
* バックアップファイルをローカルにダウンロードできるようにしました。 * バックアップファイルをローカルにダウンロードできるようにしました。
* PHP documentor で使えるように、ソースコードのドキュメントを書き直しました。 * PHP documentor で使えるように、ソースコードのドキュメントを書き直しました。
@ -168,7 +169,7 @@ query_posts() や WP_Query() を使うときに、オプションの一部が機
* マイナーな変更、修正がいくつかありました。 * マイナーな変更、修正がいくつかありました。
* WordPress 3.8.1 と 3.9 alpha でインストールテストをしました。 * WordPress 3.8.1 と 3.9 alpha でインストールテストをしました。
* プラグイン互換リストを増補しました。 * プラグイン互換リストを増補しました。
* これまで使えなかった WordPress の関数が使えるようになりました。 * これまで使えなくしていた wp-db.php の関数を使えるようにしました。
* いくつかのユーザ定義関数を追加しました。 * いくつかのユーザ定義関数を追加しました。
= 1.5 (2013-12-17) = = 1.5 (2013-12-17) =

View File

@ -158,7 +158,8 @@ When query_posts() or WP_Query() is used, some options didn't work properly. Whe
== Changelog == == Changelog ==
= 1.5.1 (2014-02-06) = = 1.5.1 (2014-02-06) =
* Fixed the bug for 'SQL_CALC_FOUND_ROW' statement. This is for the main query and WP_Query concerning paging information. * Fixed the bug of error messaging control for the unknown query.
* Fixed the bug for 'SQL_CALC_FOUND_ROW' statement. This is for the main query, WP_Query class and WP_Meta_Query concerning paging information.
* Fixed the bug that the back quote in the comments was removed. * Fixed the bug that the back quote in the comments was removed.
* Added the feature to download a backup file to a local machine. * Added the feature to download a backup file to a local machine.
* Revised all the doc strings in the sourcse code for PHP documentor. * Revised all the doc strings in the sourcse code for PHP documentor.
@ -166,7 +167,7 @@ When query_posts() or WP_Query() is used, some options didn't work properly. Whe
* Fixed minor bugs and typos. * Fixed minor bugs and typos.
* Tested to install WordPress 3.8.1 and 3.9 beta. * Tested to install WordPress 3.8.1 and 3.9 beta.
* Augumented the plugin compatibility list. * Augumented the plugin compatibility list.
* Some functions in WordPress that can't be used are made to work. * Some functions in wp-db.php, which was disabled by the plugin, is enabled and can be used.
* Some more user defined functions are added. * Some more user defined functions are added.
= 1.5 (2013-12-17) = = 1.5 (2013-12-17) =

View File

@ -506,7 +506,8 @@ class SQLiteIntegrationUtils {
if (count($file_names) != 1) return 2; if (count($file_names) != 1) return 2;
$file_name = $file_names[0]; $file_name = $file_names[0];
$file_path = FQDBDIR . $file_name; $file_path = FQDBDIR . $file_name;
$download_file_name = get_bloginfo('name') . '_' . $file_name; $blog_name = str_replace(array(' ', ' ', ';'), array('_', '_', '_'), get_bloginfo('name'));
$download_file_name = $blog_name . '_' . $file_name;
header('Pragma: public'); header('Pragma: public');
header('Cache-Control: must-revalidate,post-check=0,pre-check=0'); header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
header('Content-Type: application/force-download'); header('Content-Type: application/force-download');