Removed the rewriting code of the BETWEEN function. Changed some documentation.

git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@778174 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
kjmtsh 2013-09-25 07:40:16 +00:00
parent d7f68d81a6
commit cfc1d0b2ef
8 changed files with 94 additions and 74 deletions

Binary file not shown.

View File

@ -1364,3 +1364,18 @@ msgstr "%sのカラム"
msgid "Columns Info" msgid "Columns Info"
msgstr "カラム情報" msgstr "カラム情報"
msgid "Table Name: "
msgstr "テーブル名"
msgid "Column"
msgstr "カラム"
msgid "Type"
msgstr "タイプ"
msgid "Null"
msgstr "ヌル"
msgid "Default"
msgstr "デフォルト"

View File

@ -34,7 +34,7 @@ class PDOEngine extends PDO {
/** /**
* Constructor * Constructor
* @param array $DatabaseParams * @param
*/ */
function __construct() { function __construct() {
$this->init(); $this->init();
@ -79,8 +79,8 @@ class PDOEngine extends PDO {
if ($status == 5 || $status == 6) { if ($status == 5 || $status == 6) {
$locked = true; $locked = true;
} else { } else {
$message = __("Database connection error!<br />", 'sqlite-integration'); $message = 'Database connection error!<br />';
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err->getMessage()); $message .= sprintf("Error message is: %s", $err->getMessage());
$this->set_error(__LINE__, __FUNCTION__, $message); $this->set_error(__LINE__, __FUNCTION__, $message);
return false; return false;
} }
@ -95,8 +95,8 @@ class PDOEngine extends PDO {
try { try {
$this->pdo = new PDO($dsn, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $this->pdo = new PDO($dsn, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch (PDOException $err) { } catch (PDOException $err) {
$message = __("Database connection error!<br />", 'sqlite-integration'); $message = 'Database initialization error!<br />';
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err->getMessage()); $message .= sprintf("Error message is: %s", $err->getMessage());
$this->set_error(__LINE__, __FUNCTION__, $message); $this->set_error(__LINE__, __FUNCTION__, $message);
return false; return false;
} }
@ -133,7 +133,7 @@ class PDOEngine extends PDO {
echo $message; echo $message;
return false; return false;
} }
fwrite($fh, "DENY FROM ALL"); fwrite($fh, 'DENY FROM ALL');
fclose($fh); fclose($fh);
} }
umask($u); umask($u);
@ -144,7 +144,7 @@ class PDOEngine extends PDO {
* executed once while installation process * executed once while installation process
*/ */
private function make_sqlite_tables() { private function make_sqlite_tables() {
require_once PDODIR . "install.php"; require_once PDODIR . 'install.php';
} }
public function query($query) { public function query($query) {
@ -252,7 +252,7 @@ class PDOEngine extends PDO {
ob_start(); ob_start();
debug_print_backtrace(); debug_print_backtrace();
$output .= "<pre>" . ob_get_contents() . "</pre>"; $output .= '<pre>' . ob_get_contents() . '</pre>';
ob_end_clean(); ob_end_clean();
return $output; return $output;
@ -298,7 +298,7 @@ class PDOEngine extends PDO {
} }
private function prepare_query(){ private function prepare_query(){
$this->queries[] = "Prepare:\t". $this->prepared_query; $this->queries[] = 'Prepare: ' . $this->prepared_query;
$reason = 0; $reason = 0;
$message = ''; $message = '';
$statement = null; $statement = null;
@ -312,7 +312,7 @@ class PDOEngine extends PDO {
} while (5 == $reason || 6 == $reason); } while (5 == $reason || 6 == $reason);
if ($reason > 0){ if ($reason > 0){
$err_message = sprintf(__("Problem preparing the PDO SQL Statement. Error was: %s", 'sqlite-integration'), $message); $err_message = sprintf("Problem preparing the PDO SQL Statement. Error was: %s", $message);
$this->set_error(__LINE__, __FUNCTION__, $err_message); $this->set_error(__LINE__, __FUNCTION__, $err_message);
} }
return $statement; return $statement;
@ -324,7 +324,7 @@ class PDOEngine extends PDO {
if (!is_object($statement)) if (!is_object($statement))
return; return;
if (count($this->extracted_variables) > 0) { if (count($this->extracted_variables) > 0) {
$this->queries[] = "Executing: ". var_export($this->extracted_variables, true); $this->queries[] = 'Executing: ' . var_export($this->extracted_variables, true);
do { do {
if ($this->query_type == 'update' || $this->query_type == 'replace') { if ($this->query_type == 'update' || $this->query_type == 'replace') {
try { try {
@ -346,7 +346,7 @@ class PDOEngine extends PDO {
} }
} while (5 == $reason || 6 == $reason); } while (5 == $reason || 6 == $reason);
} else { } else {
$this->queries[] = "Executing: (no parameters)\t "; $this->queries[] = 'Executing: (no parameters)';
do{ do{
if ($this->query_type == 'update' || $this->query_type == 'replace') { if ($this->query_type == 'update' || $this->query_type == 'replace') {
try { try {
@ -369,7 +369,7 @@ class PDOEngine extends PDO {
} while (5 == $reason || 6 == $reason); } while (5 == $reason || 6 == $reason);
} }
if ($reason > 0) { if ($reason > 0) {
$err_message = sprintf(__("Error while executing query! Error message was: %s", 'sqlite-integration'), $message); $err_message = sprintf("Error while executing query! Error message was: %s", $message);
$this->set_error(__LINE__, __FUNCTION__, $err_message); $this->set_error(__LINE__, __FUNCTION__, $err_message);
return false; return false;
} else { } else {
@ -377,32 +377,32 @@ class PDOEngine extends PDO {
} }
//generate the results that $wpdb will want to see //generate the results that $wpdb will want to see
switch ($this->query_type) { switch ($this->query_type) {
case "insert": case 'insert':
case "update": case 'update':
case "replace": case 'replace':
$this->last_insert_id = $this->pdo->lastInsertId(); $this->last_insert_id = $this->pdo->lastInsertId();
$this->affected_rows = $statement->rowCount(); $this->affected_rows = $statement->rowCount();
$this->return_value = $this->affected_rows; $this->return_value = $this->affected_rows;
break; break;
case "select": case 'select':
case "show": case 'show':
case "showcolumns": case 'showcolumns':
case "showindex": case 'showindex':
case "describe": case 'describe':
case "desc": case 'desc':
// case "foundrows": // case "foundrows":
$this->num_rows = count($this->_results); $this->num_rows = count($this->_results);
$this->return_value = $this->num_rows; $this->return_value = $this->num_rows;
break; break;
case "delete": case 'delete':
$this->affected_rows = $statement->rowCount(); $this->affected_rows = $statement->rowCount();
$this->return_value = $this->affected_rows; $this->return_value = $this->affected_rows;
break; break;
case "alter": case 'alter':
case "drop": case 'drop':
case "create": case 'create':
case "optimize": case 'optimize':
case "truncate": case 'truncate':
if ($this->is_error) { if ($this->is_error) {
$this->return_value = false; $this->return_value = false;
} else { } else {
@ -423,7 +423,7 @@ class PDOEngine extends PDO {
$_limit = $limit = ini_get('pcre.backtrack_limit'); $_limit = $limit = ini_get('pcre.backtrack_limit');
do { do {
if ($limit > 10000000) { if ($limit > 10000000) {
$message = __("The query is too big to parse properly", 'sqlite-integration'); $message = 'The query is too big to parse properly';
$this->set_error(__LINE__, __FUNCTION__, $message); $this->set_error(__LINE__, __FUNCTION__, $message);
break; //no point in continuing execution, would get into a loop break; //no point in continuing execution, would get into a loop
} else { } else {
@ -435,7 +435,7 @@ class PDOEngine extends PDO {
//reset the pcre.backtrack_limist //reset the pcre.backtrack_limist
ini_set('pcre.backtrack_limit', $_limit); ini_set('pcre.backtrack_limit', $_limit);
$this->queries[]= "With Placeholders: $query "; $this->queries[]= 'With Placeholders: ' . $query;
$this->prepared_query = $query; $this->prepared_query = $query;
} }
@ -504,7 +504,7 @@ class PDOEngine extends PDO {
private function execute_insert_query_new($query) { private function execute_insert_query_new($query) {
$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);
$this->queries[] = "Rewritten: $this->rewritten_query"; $this->queries[] = 'Rewritten: ' . $this->rewritten_query;
$this->extract_variables(); $this->extract_variables();
$statement = $this->prepare_query(); $statement = $this->prepare_query();
$this->execute_query($statement); $this->execute_query($statement);
@ -543,7 +543,7 @@ class PDOEngine extends PDO {
} }
$query_string = $query_prefix . ' ' . $value . $suffix; $query_string = $query_prefix . ' ' . $value . $suffix;
$this->rewritten_query = $engine->rewrite_query($query_string, $this->query_type); $this->rewritten_query = $engine->rewrite_query($query_string, $this->query_type);
$this->queries[] = "Rewritten: $this->rewritten_query"; $this->queries[] = 'Rewritten: ' . $this->rewritten_query;
$this->extracted_variables = array(); $this->extracted_variables = array();
$this->extract_variables(); $this->extract_variables();
if ($first) { if ($first) {
@ -556,7 +556,7 @@ class PDOEngine extends PDO {
} }
} else { } else {
$this->rewritten_query = $engine->rewrite_query($query, $this->query_type); $this->rewritten_query = $engine->rewrite_query($query, $this->query_type);
$this->queries[] = "Rewritten: $this->rewritten_query"; $this->queries[] = 'Rewritten: ' . $this->rewritten_query;
$this->extract_variables(); $this->extract_variables();
$statement = $this->prepare_query(); $statement = $this->prepare_query();
$this->execute_query($statement); $this->execute_query($statement);
@ -632,7 +632,7 @@ class PDOEngine extends PDO {
} }
} }
if ($reason > 0) { if ($reason > 0) {
$err_message = sprintf(__("Problem in creating table or index. Error was: %s", 'sqlite-integration'), $message); $err_message = sprintf("Problem in creating table or index. Error was: %s", $message);
$this->set_error(__LINE__, __FUNCTION__, $err_message); $this->set_error(__LINE__, __FUNCTION__, $err_message);
return false; return false;
} }
@ -683,7 +683,7 @@ class PDOEngine extends PDO {
$this->query($re_query); $this->query($re_query);
} }
if ($reason > 0) { if ($reason > 0) {
$err_message = sprintf(__("Problem in executing alter query. Error was: %s", 'sqlite-integration'), $message); $err_message = sprintf("Problem in executing alter query. Error was: %s", $message);
$this->set_error(__LINE__, __FUNCTION__, $err_message); $this->set_error(__LINE__, __FUNCTION__, $err_message);
return false; return false;
} }

View File

@ -54,7 +54,7 @@ class PDOSQLiteDriver {
$this->_rewrite_regexp(); $this->_rewrite_regexp();
$this->_rewrite_boolean(); $this->_rewrite_boolean();
$this->_fix_date_quoting(); $this->_fix_date_quoting();
$this->_rewrite_between(); // $this->_rewrite_between();
break; break;
case 'insert': case 'insert':
$this->_strip_backticks(); $this->_strip_backticks();
@ -70,7 +70,7 @@ class PDOSQLiteDriver {
$this->_rewrite_limit_usage(); $this->_rewrite_limit_usage();
$this->_rewrite_order_by_usage(); $this->_rewrite_order_by_usage();
$this->_rewrite_regexp(); $this->_rewrite_regexp();
$this->_rewrite_between(); // $this->_rewrite_between();
break; break;
case 'delete': case 'delete':
$this->_strip_backticks(); $this->_strip_backticks();
@ -488,13 +488,13 @@ class PDOSQLiteDriver {
$this->_query = $update_query; $this->_query = $update_query;
} }
} }
} else {
// wordaround...
$pattern = '/ ON DUPLICATE KEY UPDATE.*$/im';
$replace_query = preg_replace($pattern, '', $this->_query);
$replace_query = str_ireplace('INSERT ', 'INSERT OR REPLACE ', $replace_query);
$this->_query = $replace_query;
} }
// else {
// $pattern = '/ ON DUPLICATE KEY UPDATE.*$/im';
// $replace_query = preg_replace($pattern, '', $this->_query);
// $replace_query = str_ireplace('INSERT ', 'INSERT OR REPLACE ', $replace_query);
// $this->_query = $replace_query;
// }
} }
private function _rewrite_between() { private function _rewrite_between() {

View File

@ -6,7 +6,7 @@ Tags: database, SQLite, PDO
Author: Kojima Toshiyasu Author: Kojima Toshiyasu
Author URI: http://dogwood.skr.jp/ Author URI: http://dogwood.skr.jp/
Requires at least: 3.3 Requires at least: 3.3
Tested up to: 3.6 Tested up to: 3.6.1
Stable tag: 1.4 Stable tag: 1.4
License: GPLv2 License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -50,7 +50,8 @@ SQLite Integrationは普通の「プラグイン」ではありません。WordP
下の方法でコンタクトを取ってください。 下の方法でコンタクトを取ってください。
[Support Forum](http://wordpress.org/support/plugin/sqlite-integration)にポストする。 1. [Support Forum](http://wordpress.org/support/plugin/sqlite-integration)にポストする。
2. [SQLite Integration(ja)のページ](http://dogwood.skr.jp/wordpress/sqlite-integration-ja/)でメッセージを残す。
注意: WordPress.orgはMySQL以外のデータベースを正式にサポートしていません。だから、WordPress.orgからのサポートは得られません。フォーラムに投稿しても、回答を得ることはまずないでしょう。また、パッチをあてたプラグインを使う場合は、そのプラグインの作者からのサポートはないものと思ってください。自分でリスクを負う必要があります。 注意: WordPress.orgはMySQL以外のデータベースを正式にサポートしていません。だから、WordPress.orgからのサポートは得られません。フォーラムに投稿しても、回答を得ることはまずないでしょう。また、パッチをあてたプラグインを使う場合は、そのプラグインの作者からのサポートはないものと思ってください。自分でリスクを負う必要があります。

View File

@ -6,7 +6,7 @@ Tags: database, SQLite, PDO
Author: Kojima Toshiyasu Author: Kojima Toshiyasu
Author URI: http://dogwood.skr.jp/ Author URI: http://dogwood.skr.jp/
Requires at least: 3.3 Requires at least: 3.3
Tested up to: 3.6 Tested up to: 3.6.1
Stable tag: 1.4 Stable tag: 1.4
License: GPLv2 License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -38,7 +38,7 @@ When you installed WordPress 3.6 with this plugin or your WordPress is 3.5.x, yo
= Features = = Features =
SQLite Integration is not an ordinary 'plugin'. It is used to install WordPress itself. You need to do some preparations. Please read the install section. And see more detailed instruction in the [SQLite Integration Page](http://dogwood.skr.jp/wordpress/sqlite-integration). SQLite Integration is not an ordinary 'plugin'. It is used to install WordPress itself. You need to do some preparations. Please read the install section. And see more detailed instruction in the [SQLite Integration Page](http://dogwood.skr.jp/wordpress/sqlite-integration/).
Once you succeeded in installing WordPress, you can use it just like the others using MySQL. Optionally, you can activate this plugin in the installed plugins panel of the adimn dashboard, and you can see the useful information and instructions. It is not required but I recommend it. Once you succeeded in installing WordPress, you can use it just like the others using MySQL. Optionally, you can activate this plugin in the installed plugins panel of the adimn dashboard, and you can see the useful information and instructions. It is not required but I recommend it.
@ -50,7 +50,8 @@ If you are using [PDO for WordPress](http://wordpress.org/extend/plugins/pdo-for
Please contact us with the methods below: Please contact us with the methods below:
Post to [Support Forum](http://wordpress.org/support/plugin/sqlite-integration/). 1. Post to [Support Forum](http://wordpress.org/support/plugin/sqlite-integration/).
2. Visti the [SQLite Integration Page](http://dogwood.skr.jp/wordpress/sqlite-integration/) or [SQLite Integration(ja) Page](http://dogwood.skr.jp/wordpress/sqlite-integration-ja/) and leave a message.
Notes: WordPress.org doesn't officially support using any other database than MySQL. So there will be no supports from WordPress.org. Even if you post to the general Forum, you have few chances to get the answer. And if you use patched plugins, you will have no support from the plugin authors, eithter. Notes: WordPress.org doesn't officially support using any other database than MySQL. So there will be no supports from WordPress.org. Even if you post to the general Forum, you have few chances to get the answer. And if you use patched plugins, you will have no support from the plugin authors, eithter.

View File

@ -304,14 +304,13 @@ class DatabaseMaintenance {
) )
); );
if (version_compare($wp_version, '3.6', '<')) return false; if (version_compare($wp_version, '3.6', '<')) return false;
$results = $this->sanity_check();
$return_val = array(); $return_val = array();
$queries = array(); $queries = array();
$results = $this->sanity_check();
if ($results !== true) { if ($results !== true) {
if (!$this->maintenance_backup()) { if (!$this->maintenance_backup()) {
$message = __('Can\'t create backup file.', $domain); $message = __('Can\'t create backup file.', $domain);
echo $message; return $message;
return false;
} }
$tables = array_keys($results); $tables = array_keys($results);
foreach ($tables as $table) { foreach ($tables as $table) {
@ -334,10 +333,12 @@ class DatabaseMaintenance {
} }
} }
} else { } else {
return true; $message = __('Your database is OK. You don\'t have to restore it.', $domain);
return $message;
} }
if (empty($return_val)) { if (empty($return_val)) {
return true; $message = __('Your database restoration is successfully finished!', $domain);
return $message;
} else { } else {
return $return_val; return $return_val;
} }
@ -398,8 +399,6 @@ class DatabaseMaintenance {
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain)); die(__('You are not allowed to access this page!', $domain));
} }
if (isset($_GET['page']) && $_GET['page'] == 'maintenance') : ?> if (isset($_GET['page']) && $_GET['page'] == 'maintenance') : ?>
<div class="navigation"> <div class="navigation">
<ul class="navi-menu"> <ul class="navi-menu">
@ -449,7 +448,7 @@ class DatabaseMaintenance {
wp_nonce_field('sqliteintegration-database-manip-stats'); wp_nonce_field('sqliteintegration-database-manip-stats');
} }
?> ?>
<label for="table"/>Table Name: </label> <label for="table"/><?php _e('Table Name: ', $domain);?></label>
<select name="table" id="table"> <select name="table" id="table">
<?php foreach ($wp_tables as $table) :?> <?php foreach ($wp_tables as $table) :?>
<option value="<?php echo $table;?>"><?php echo $table;?></option> <option value="<?php echo $table;?>"><?php echo $table;?></option>
@ -468,7 +467,7 @@ class DatabaseMaintenance {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} }
$fix_results = $this->do_fix_database(); $fix_results = $this->do_fix_database();
if ($fix_results !== true) { if (is_array($fix_results)) {
$title = '<h3>'. __('Results', $domain) . '</h3>'; $title = '<h3>'. __('Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">'; echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title; echo $title;
@ -480,10 +479,9 @@ class DatabaseMaintenance {
echo '</div>'; echo '</div>';
} else { } else {
$title = '<h3>'. __('Results', $domain) . '</h3>'; $title = '<h3>'. __('Results', $domain) . '</h3>';
$message = __('Your database restoration is successfully finished!', $domain);
echo '<div class="wrap" id="sqlite-admin-side-wrap">'; echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title; echo $title;
echo '<p>'.$message.'</p>'; echo '<p>'.$fix_results.'</p>';
echo '</div>'; echo '</div>';
} }
} }
@ -525,26 +523,31 @@ class DatabaseMaintenance {
$results = $this->show_columns(); $results = $this->show_columns();
if (is_array($results)) { if (is_array($results)) {
$title = '<h3>'. sprintf(__('Columns In %s', $domain), $_POST['table']) . '</h3>'; $title = '<h3>'. sprintf(__('Columns In %s', $domain), $_POST['table']) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">'; $column_header = __('Column', $domain);
$type_header = __('Type', $domain);
$null_header = __('Null', $domain);
$default_header = __('Default', $domain);
echo '<div class="wrap" id="sqlite-admin-side-wrap" style="clear: both;">';
echo $title; echo $title;
echo '<table><thead><tr><th>Column</th><th>Type</th><th>Null</th><th>Default</th></tr></thead>'; echo '<table class="widefat page fixed"><thead><tr><th>'. $column_header . '</th><th>'. $type_header . '</th><th>' . $null_header . '</th><th>' . $default_header . '</th></tr></thead>';
echo '<tbody>'; echo '<tbody>';
$counter = 0;
foreach ($results as $column) { foreach ($results as $column) {
echo '<tr>'; echo (($counter % 2) == 1) ? '<tr class="alt">' : '<tr>';
echo '<td>' . $column->Field . '</td>'; echo '<td>' . $column->Field . '</td>';
echo '<td>' . $column->Type . '</td>'; echo '<td>' . $column->Type . '</td>';
echo '<td>' . $column->Null . '</td>'; echo '<td>' . $column->Null . '</td>';
echo '<td>' . $column->Default . '</td>'; echo '<td>' . $column->Default . '</td>';
echo '</tr>'; echo '</tr>';
$counter++;
} }
echo '</tbody></table></div>'; echo '</tbody></table></div>';
} else { } else {
$title = '<h3>'. __('Columns Info', $domain) . '</h3>'; $title = '<h3>'. __('Columns Info', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">'; echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title; echo $title;
echo '<ul>'; echo '<p>' . $results;
echo $results; echo '</p></div>';
echo '</ul></div>';
} }
} }
} }