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
This commit is contained in:
kjmtsh 2013-08-13 00:34:40 +00:00
parent ce9c138473
commit 6401a9b0ec
10 changed files with 68 additions and 41 deletions

8
db.php
View File

@ -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.');
}
/**

View File

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

View File

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

View File

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

View File

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

View File

@ -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;
@ -417,25 +416,25 @@ class AlterQuery {
'bit' => 'INTEGER', 'bool' => 'INTEGER',
'boolean' => 'INTEGER', 'tinyint' => 'INTEGER',
'smallint' => 'INTEGER', 'mediumint' => 'INTEGER',
'int' => 'INTEGER', 'integer' => 'INTEGER',
'bigint' => 'INTEGER', 'float' => 'REAL',
'bigint' => 'INTEGER', 'integer' => 'INTEGER',
'int' => 'INTEGER', 'float' => 'REAL',
'double' => 'REAL', 'decimal' => 'REAL',
'dec' => 'REAL', 'numeric' => 'REAL',
'fixed' => 'REAL', 'date' => 'TEXT',
'datetime' => 'TEXT', 'timestamp' => 'TEXT',
'fixed' => 'REAL', 'datetime' => 'TEXT',
'date' => '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'
'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;

View File

@ -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,10 +87,14 @@ class CreateQuery{
'longblob' => 'blob', 'longtext' => 'text'
);
foreach ($array_types as $o=>$r){
$pattern = '/\\b(?<!`)'.$o.'\\b\\s*(\([^\)]*\)*)?\\s*/imsx';
$pattern = "/\\b(?<!`)$o\\b\\s*(\([^\)]*\)*)?\\s*/ims";
if (preg_match("/^\\s*.*?\\s*\(.*?$o.*?\)/im", $this->_query)) {
;
} else {
$this->_query = preg_replace($pattern, " $r ", $this->_query);
}
}
}
/**
* Method for stripping the comments from the SQL statement

View File

@ -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) =
* カレンダー・ウィジェットでの不具合に対応するため、日付フォーマットとそのクオートを修正しました。

View File

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

View File

@ -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!<br />", 'sqlite-integration');
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err_data[2]);
$message = 'Database connection error!<br />';
$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...<br />Query was: %s<br />", '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...<br />Query was: %s<br />", var_export($rewritten_query, true));
$message .= sprintf("Error message is: %s", $err_data[2]);
echo $message;
return false;
}