From 6401a9b0ec3b214acc913b2eee5484150cbe80ba Mon Sep 17 00:00:00 2001 From: kjmtsh Date: Tue, 13 Aug 2013 00:34:40 +0000 Subject: [PATCH] changed the handling of the error messages. Fixed the manipulation of ALTER TABLE CHANGE COLUMN query. Added the support for BETWEEN function. git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@755392 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- db.php | 8 ++++---- install.php | 2 +- pdodb.class.php | 2 +- pdoengine.class.php | 6 +++--- query.class.php | 10 ++++++++++ query_alter.class.php | 45 +++++++++++++++++++++--------------------- query_create.class.php | 12 ++++++++--- readme-ja.txt | 8 +++++++- readme.txt | 8 +++++++- schema.php | 8 ++++---- 10 files changed, 68 insertions(+), 41 deletions(-) diff --git a/db.php b/db.php index d2d92a5..30df2a8 100644 --- a/db.php +++ b/db.php @@ -9,7 +9,7 @@ * */ -function pdo_log_erro($message, $data = null) { +function pdo_log_error($message, $data = null) { if (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin') !== false) { $admin_dir = ''; @@ -37,15 +37,15 @@ HTML } if (version_compare( PHP_VERSION, '5.2.4', '<')) { - pdo_log_erro(__('PHP version on this server is too old.'), sprinf(__("Your server is running PHP version %d but this version of WordPress requires at least 5.2.4"), phpversion())); + pdo_log_error('PHP version on this server is too old.', sprinf("Your server is running PHP version %d but this version of WordPress requires at least 5.2.4", phpversion())); } if (!extension_loaded('pdo')) { - pdo_log_erro(__('PHP PDO Extension is not loaded.'), __('Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress.')); + pdo_log_error('PHP PDO Extension is not loaded.', 'Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress.'); } if (!extension_loaded('pdo_sqlite')) { - pdo_log_erro(__('PDO Driver for SQLite is missing.'), __('Your PHP installtion appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.')); + pdo_log_error('PDO Driver for SQLite is missing.', 'Your PHP installtion appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.'); } /** diff --git a/install.php b/install.php index 86293b5..4c27b88 100644 --- a/install.php +++ b/install.php @@ -6,7 +6,7 @@ */ /** - * This function overrides wp_install() in wp-admin/upgrade.php + * This function overrides wp_install() in wp-admin/includes/upgrade.php */ function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') { if (!empty($deprecated)) diff --git a/pdodb.class.php b/pdodb.class.php index db927a9..2585dd7 100644 --- a/pdodb.class.php +++ b/pdodb.class.php @@ -83,7 +83,7 @@ class PDODB extends wpdb { if (!$str) { $err = $this->dbh->get_error_message() ? $this->dbh->get_error_message() : ''; - $str = $err[2]; + if (!empty($err)) $str = $err[2]; else $str = ''; } $EZSQL_ERROR[] = array('query' => $this->last_query, 'error_str' => $str); diff --git a/pdoengine.class.php b/pdoengine.class.php index 03f7183..2eeed63 100644 --- a/pdoengine.class.php +++ b/pdoengine.class.php @@ -114,14 +114,14 @@ class PDOEngine extends PDO { if (!is_dir(FQDBDIR)) { if (!@mkdir(FQDBDIR, 0777, true)) { umask($u); - $message = __('Unable to create the required directory! Please check your server settings.', 'sqlite-integration'); + $message = 'Unable to create the required directory! Please check your server settings.'; echo $message; return false; } } if (!is_writable(FQDBDIR)) { umask($u); - $message = __('Unable to create a file in the directory! Please check your server settings.', 'sqlite-integration'); + $message = 'Unable to create a file in the directory! Please check your server settings.'; echo $message; return false; } @@ -129,7 +129,7 @@ class PDOEngine extends PDO { $fh = fopen(FQDBDIR . '.htaccess', "w"); if (!$fh) { umask($u); - $message = __('Unable to create a file in the directory! Please check your server settings.', 'sqlite-integration'); + $message = 'Unable to create a file in the directory! Please check your server settings.'; echo $message; return false; } diff --git a/query.class.php b/query.class.php index b3b1d39..c9ac292 100644 --- a/query.class.php +++ b/query.class.php @@ -54,6 +54,7 @@ class PDOSQLiteDriver { $this->_rewrite_regexp(); $this->_rewrite_boolean(); $this->_fix_date_quoting(); + $this->_rewrite_between(); break; case 'insert': $this->_strip_backticks(); @@ -511,6 +512,15 @@ class PDOSQLiteDriver { } } + private function _rewrite_between() { + $pattern = '/\\s*(\\w+)?\\s*BETWEEN\\s*([^\\s]*)?\\s*AND\\s*([^\\s]*)?\\s*/ims'; + if (preg_match($pattern, $this->_query, $match)) { + $column_name = trim($match[1]); + $min_value = trim($match[2]); + $max_value = trim($match[3]); + $this->_query = str_ireplace($match[0], " $column_name >= $min_value AND $column_name <= $max_value ", $this->_query); + } + } /** * workaround function to avoid DELETE with JOIN * wp-admin/includes/upgrade.php contains 'DELETE ... JOIN' statement. diff --git a/query_alter.class.php b/query_alter.class.php index 1321c5c..4964619 100644 --- a/query_alter.class.php +++ b/query_alter.class.php @@ -136,9 +136,8 @@ class AlterQuery { if ($match_2 == 'column') { $tokens['command'] = $match_1.' '.$match_2; $tokens['old_column'] = $match_3; - list($new_col) = preg_split('/\s/s', trim($the_rest), -1, PREG_SPLIT_DELIM_CAPTURE); + list($new_col, $col_def) = explode(' ', trim($the_rest), 2); $tokens['new_column'] = $new_col; - $col_def = str_ireplace($new_col, '', $the_rest); $tokens['column_def'] = trim($col_def); } else { $tokens['command'] = $match_1.' column'; @@ -348,16 +347,16 @@ class AlterQuery { $create_query = array_shift($index_queries); $create_query = preg_replace("/{$tokenized_query['table_name']}/i", $temp_table, $create_query); if (preg_match("/\\b{$tokenized_query['old_column']}\\s*(.+?)(?=,)/ims", $create_query, $match)) { - if ($tokenized_query['column_def'] == trim($match[1])) { + if ($column_def == trim($match[1])) { return 'SELECT 1=1'; } else { - $create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.*?(?=,)/ims", "{$tokenized_query['new_column']} {$tokenized_query['column_def']}", $create_query); + $create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.*?(?=,)/ims", "{$tokenized_query['new_column']} {$column_def}", $create_query); } } elseif (preg_match("/\\b{$tokenized_query['old_column']}\\s*(.+?)(?=\))/ims", $create_query, $match)) { - if ($tokenized_query['column_def'] == trim($match[1])) { + if ($column_def == trim($match[1])) { return 'SELECT 1=1'; } else { - $create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.*?(?=\))/ims", "{$tokenized_query['new_column']} {$tokenized_query['column_def']}", $create_query); + $create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.*?(?=\))/ims", "{$tokenized_query['new_column']} {$column_def}", $create_query); } } $query[] = $create_query; @@ -414,28 +413,28 @@ class AlterQuery { */ private function convert_field_types($col_name, $col_def){ $array_types = array( - 'bit' => 'INTEGER', 'bool' => 'INTEGER', - 'boolean' => 'INTEGER', 'tinyint' => 'INTEGER', - 'smallint' => 'INTEGER', 'mediumint' => 'INTEGER', - 'int' => 'INTEGER', 'integer' => 'INTEGER', - 'bigint' => 'INTEGER', 'float' => 'REAL', - 'double' => 'REAL', 'decimal' => 'REAL', - 'dec' => 'REAL', 'numeric' => 'REAL', - 'fixed' => 'REAL', 'date' => 'TEXT', - 'datetime' => 'TEXT', 'timestamp' => 'TEXT', - 'time' => 'TEXT', 'year' => 'TEXT', - 'char' => 'TEXT', 'varchar' => 'TEXT', - 'binary' => 'INTEGER', 'varbinary' => 'BLOB', - 'tinyblob' => 'BLOB', 'tinytext' => 'TEXT', - 'blob' => 'BLOB', 'text' => 'TEXT', - 'mediumblob' => 'BLOB', 'mediumtext' => 'TEXT', - 'longblob' => 'BLOB', 'longtext' => 'TEXT' + 'bit' => 'INTEGER', 'bool' => 'INTEGER', + 'boolean' => 'INTEGER', 'tinyint' => 'INTEGER', + 'smallint' => 'INTEGER', 'mediumint' => 'INTEGER', + 'bigint' => 'INTEGER', 'integer' => 'INTEGER', + 'int' => 'INTEGER', 'float' => 'REAL', + 'double' => 'REAL', 'decimal' => 'REAL', + 'dec' => 'REAL', 'numeric' => 'REAL', + 'fixed' => 'REAL', 'datetime' => 'TEXT', + 'date' => 'TEXT', 'timestamp' => 'TEXT', + 'time' => 'TEXT', 'year' => 'TEXT', + 'varchar' => 'TEXT', 'char' => 'TEXT', + 'varbinary' => 'BLOB', 'binary' => 'BLOB', + 'tinyblob' => 'BLOB', 'mediumblob' => 'BLOB', + 'longblob' => 'BLOB', 'blob' => 'BLOB', + 'tinytext' => 'TEXT', 'mediumtext' => 'TEXT', + 'longtext' => 'TEXT', 'text' => 'TEXT' ); $array_curtime = array('current_timestamp', 'current_time', 'current_date'); $array_reptime = array("'0000-00-00 00:00:00'", "'0000-00-00 00:00:00'", "'0000-00-00'"); $def_string = str_replace('`', '', $col_def); foreach ($array_types as $o=>$r){ - $pattern = "/\\b" . $o . "\\s*(\([^\)]*\))?\\s*/imsx"; + $pattern = "/\\b$o\\s*(\([^\)]*\)*)?\\s*/ims"; if (preg_match($pattern, $def_string)) { $def_string = preg_replace($pattern, "$r ", $def_string); break; diff --git a/query_create.class.php b/query_create.class.php index c2c7bd7..13bdc2a 100644 --- a/query_create.class.php +++ b/query_create.class.php @@ -30,8 +30,9 @@ class CreateQuery{ } else { return $this->_query; } + } elseif (preg_match('/^CREATE\\s*(TEMP|TEMPORARY|)\\s*TRIGGER\\s*/im', $this->_query)) { + return $this->_query; } - $this->strip_backticks(); $this->get_table_name(); $this->rewrite_comments(); $this->rewrite_field_types(); @@ -45,6 +46,7 @@ class CreateQuery{ $this->rewrite_set(); $this->rewrite_key(); $this->add_if_not_exists(); + $this->strip_backticks(); return $this->post_process(); } @@ -85,8 +87,12 @@ class CreateQuery{ 'longblob' => 'blob', 'longtext' => 'text' ); foreach ($array_types as $o=>$r){ - $pattern = '/\\b(?_query = preg_replace($pattern, " $r ", $this->_query); + $pattern = "/\\b(?_query)) { + ; + } else { + $this->_query = preg_replace($pattern, " $r ", $this->_query); + } } } diff --git a/readme-ja.txt b/readme-ja.txt index 00d923d..06822b5 100644 --- a/readme-ja.txt +++ b/readme-ja.txt @@ -167,8 +167,14 @@ SQLite Integrationのアップグレードに失敗するようなら、FTPを == Changelog == += 1.3 (2013-08-11) = +* エラーメッセージの出力方法を一部変更しました。 +* query_create.class.phpの_rewrite_field_types()を変更しました。 +* BETWEEN関数が使えるようになりました。 +* New StatPressプラグインが使えるように、ALTER TABLE CHANGE COLUMNの扱いを修正しました。 + = 1.2.1 (2013-08-04) = -* wp-db.php の変更にともなう修正をしました。WordPress 3.6 との互換性を保つためのものです。 +* wp-db.phpの変更にともなって、wpdb::real_escapeプロパティを削除しました。WordPress 3.6 との互換性を保つための変更です。 = 1.2 (2013-08-03) = * カレンダー・ウィジェットでの不具合に対応するため、日付フォーマットとそのクオートを修正しました。 diff --git a/readme.txt b/readme.txt index d356370..ad4a4a2 100644 --- a/readme.txt +++ b/readme.txt @@ -158,8 +158,14 @@ When auto upgrading of SQLite Integration fails, please try manual upgrade via F == Changelog == += 1.3 (2013-08-10) = +* Changed the way of putting out the error messages. +* Modified the _rewrite_field_types() in query_create.class.php. +* Added the support for BETWEEN function. +* Fixed the manipulation of ALTER TABLE CHANGE COLUMN query for NewStatPress plugin to work. + = 1.2.1 (2013-08-04) = -* Changes following that of the wpdb.php file which makes the plugin compatible with Wordpress 3.6. +* Removed wpdb::real_escape property following the change of the wpdb.php file which makes the plugin compatible with Wordpress 3.6. = 1.2 (2013-08-03) = * Fixed the date string format and its quotation for calendar widget. diff --git a/schema.php b/schema.php index 6ea9508..8bdf71d 100644 --- a/schema.php +++ b/schema.php @@ -22,8 +22,8 @@ function make_db_sqlite() { $pdo = new PDO('sqlite:'.FQDB, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } catch (PDOException $err) { $err_data = $err->errorInfo; - $message = __("Database connection error!
", 'sqlite-integration'); - $message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err_data[2]); + $message = 'Database connection error!
'; + $message .= sprintf("Error message is: %s", $err_data[2]); echo $message; return false; } @@ -76,8 +76,8 @@ function make_db_sqlite() { $pdo->commit(); } else { $pdo->rollBack(); - $message = sprintf(__("Error occured while creating tables or indexes...
Query was: %s
", 'sqlite-integration'), var_export($rewritten_query, true)); - $message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err_data[2]); + $message = sprintf("Error occured while creating tables or indexes...
Query was: %s
", var_export($rewritten_query, true)); + $message .= sprintf("Error message is: %s", $err_data[2]); echo $message; return false; }