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:
parent
ce9c138473
commit
6401a9b0ec
8
db.php
8
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) {
|
if (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin') !== false) {
|
||||||
$admin_dir = '';
|
$admin_dir = '';
|
||||||
|
@ -37,15 +37,15 @@ HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version_compare( PHP_VERSION, '5.2.4', '<')) {
|
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')) {
|
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')) {
|
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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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 = '') {
|
function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') {
|
||||||
if (!empty($deprecated))
|
if (!empty($deprecated))
|
||||||
|
|
|
@ -83,7 +83,7 @@ class PDODB extends wpdb {
|
||||||
|
|
||||||
if (!$str) {
|
if (!$str) {
|
||||||
$err = $this->dbh->get_error_message() ? $this->dbh->get_error_message() : '';
|
$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);
|
$EZSQL_ERROR[] = array('query' => $this->last_query, 'error_str' => $str);
|
||||||
|
|
||||||
|
|
|
@ -114,14 +114,14 @@ class PDOEngine extends PDO {
|
||||||
if (!is_dir(FQDBDIR)) {
|
if (!is_dir(FQDBDIR)) {
|
||||||
if (!@mkdir(FQDBDIR, 0777, true)) {
|
if (!@mkdir(FQDBDIR, 0777, true)) {
|
||||||
umask($u);
|
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;
|
echo $message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!is_writable(FQDBDIR)) {
|
if (!is_writable(FQDBDIR)) {
|
||||||
umask($u);
|
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;
|
echo $message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ class PDOEngine extends PDO {
|
||||||
$fh = fopen(FQDBDIR . '.htaccess', "w");
|
$fh = fopen(FQDBDIR . '.htaccess', "w");
|
||||||
if (!$fh) {
|
if (!$fh) {
|
||||||
umask($u);
|
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;
|
echo $message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +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();
|
||||||
break;
|
break;
|
||||||
case 'insert':
|
case 'insert':
|
||||||
$this->_strip_backticks();
|
$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
|
* workaround function to avoid DELETE with JOIN
|
||||||
* wp-admin/includes/upgrade.php contains 'DELETE ... JOIN' statement.
|
* wp-admin/includes/upgrade.php contains 'DELETE ... JOIN' statement.
|
||||||
|
|
|
@ -136,9 +136,8 @@ class AlterQuery {
|
||||||
if ($match_2 == 'column') {
|
if ($match_2 == 'column') {
|
||||||
$tokens['command'] = $match_1.' '.$match_2;
|
$tokens['command'] = $match_1.' '.$match_2;
|
||||||
$tokens['old_column'] = $match_3;
|
$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;
|
$tokens['new_column'] = $new_col;
|
||||||
$col_def = str_ireplace($new_col, '', $the_rest);
|
|
||||||
$tokens['column_def'] = trim($col_def);
|
$tokens['column_def'] = trim($col_def);
|
||||||
} else {
|
} else {
|
||||||
$tokens['command'] = $match_1.' column';
|
$tokens['command'] = $match_1.' column';
|
||||||
|
@ -348,16 +347,16 @@ class AlterQuery {
|
||||||
$create_query = array_shift($index_queries);
|
$create_query = array_shift($index_queries);
|
||||||
$create_query = preg_replace("/{$tokenized_query['table_name']}/i", $temp_table, $create_query);
|
$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 (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';
|
return 'SELECT 1=1';
|
||||||
} else {
|
} 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)) {
|
} 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';
|
return 'SELECT 1=1';
|
||||||
} else {
|
} 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;
|
$query[] = $create_query;
|
||||||
|
@ -414,28 +413,28 @@ class AlterQuery {
|
||||||
*/
|
*/
|
||||||
private function convert_field_types($col_name, $col_def){
|
private function convert_field_types($col_name, $col_def){
|
||||||
$array_types = array(
|
$array_types = array(
|
||||||
'bit' => 'INTEGER', 'bool' => 'INTEGER',
|
'bit' => 'INTEGER', 'bool' => 'INTEGER',
|
||||||
'boolean' => 'INTEGER', 'tinyint' => 'INTEGER',
|
'boolean' => 'INTEGER', 'tinyint' => 'INTEGER',
|
||||||
'smallint' => 'INTEGER', 'mediumint' => 'INTEGER',
|
'smallint' => 'INTEGER', 'mediumint' => 'INTEGER',
|
||||||
'int' => 'INTEGER', 'integer' => 'INTEGER',
|
'bigint' => 'INTEGER', 'integer' => 'INTEGER',
|
||||||
'bigint' => 'INTEGER', 'float' => 'REAL',
|
'int' => 'INTEGER', 'float' => 'REAL',
|
||||||
'double' => 'REAL', 'decimal' => 'REAL',
|
'double' => 'REAL', 'decimal' => 'REAL',
|
||||||
'dec' => 'REAL', 'numeric' => 'REAL',
|
'dec' => 'REAL', 'numeric' => 'REAL',
|
||||||
'fixed' => 'REAL', 'date' => 'TEXT',
|
'fixed' => 'REAL', 'datetime' => 'TEXT',
|
||||||
'datetime' => 'TEXT', 'timestamp' => 'TEXT',
|
'date' => 'TEXT', 'timestamp' => 'TEXT',
|
||||||
'time' => 'TEXT', 'year' => 'TEXT',
|
'time' => 'TEXT', 'year' => 'TEXT',
|
||||||
'char' => 'TEXT', 'varchar' => 'TEXT',
|
'varchar' => 'TEXT', 'char' => 'TEXT',
|
||||||
'binary' => 'INTEGER', 'varbinary' => 'BLOB',
|
'varbinary' => 'BLOB', 'binary' => 'BLOB',
|
||||||
'tinyblob' => 'BLOB', 'tinytext' => 'TEXT',
|
'tinyblob' => 'BLOB', 'mediumblob' => 'BLOB',
|
||||||
'blob' => 'BLOB', 'text' => 'TEXT',
|
'longblob' => 'BLOB', 'blob' => 'BLOB',
|
||||||
'mediumblob' => 'BLOB', 'mediumtext' => 'TEXT',
|
'tinytext' => 'TEXT', 'mediumtext' => 'TEXT',
|
||||||
'longblob' => 'BLOB', 'longtext' => 'TEXT'
|
'longtext' => 'TEXT', 'text' => 'TEXT'
|
||||||
);
|
);
|
||||||
$array_curtime = array('current_timestamp', 'current_time', 'current_date');
|
$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'");
|
$array_reptime = array("'0000-00-00 00:00:00'", "'0000-00-00 00:00:00'", "'0000-00-00'");
|
||||||
$def_string = str_replace('`', '', $col_def);
|
$def_string = str_replace('`', '', $col_def);
|
||||||
foreach ($array_types as $o=>$r){
|
foreach ($array_types as $o=>$r){
|
||||||
$pattern = "/\\b" . $o . "\\s*(\([^\)]*\))?\\s*/imsx";
|
$pattern = "/\\b$o\\s*(\([^\)]*\)*)?\\s*/ims";
|
||||||
if (preg_match($pattern, $def_string)) {
|
if (preg_match($pattern, $def_string)) {
|
||||||
$def_string = preg_replace($pattern, "$r ", $def_string);
|
$def_string = preg_replace($pattern, "$r ", $def_string);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -30,8 +30,9 @@ class CreateQuery{
|
||||||
} else {
|
} else {
|
||||||
return $this->_query;
|
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->get_table_name();
|
||||||
$this->rewrite_comments();
|
$this->rewrite_comments();
|
||||||
$this->rewrite_field_types();
|
$this->rewrite_field_types();
|
||||||
|
@ -45,6 +46,7 @@ class CreateQuery{
|
||||||
$this->rewrite_set();
|
$this->rewrite_set();
|
||||||
$this->rewrite_key();
|
$this->rewrite_key();
|
||||||
$this->add_if_not_exists();
|
$this->add_if_not_exists();
|
||||||
|
$this->strip_backticks();
|
||||||
|
|
||||||
return $this->post_process();
|
return $this->post_process();
|
||||||
}
|
}
|
||||||
|
@ -85,8 +87,12 @@ class CreateQuery{
|
||||||
'longblob' => 'blob', 'longtext' => 'text'
|
'longblob' => 'blob', 'longtext' => 'text'
|
||||||
);
|
);
|
||||||
foreach ($array_types as $o=>$r){
|
foreach ($array_types as $o=>$r){
|
||||||
$pattern = '/\\b(?<!`)'.$o.'\\b\\s*(\([^\)]*\)*)?\\s*/imsx';
|
$pattern = "/\\b(?<!`)$o\\b\\s*(\([^\)]*\)*)?\\s*/ims";
|
||||||
$this->_query = preg_replace($pattern, " $r ", $this->_query);
|
if (preg_match("/^\\s*.*?\\s*\(.*?$o.*?\)/im", $this->_query)) {
|
||||||
|
;
|
||||||
|
} else {
|
||||||
|
$this->_query = preg_replace($pattern, " $r ", $this->_query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,8 +167,14 @@ SQLite Integrationのアップグレードに失敗するようなら、FTPを
|
||||||
|
|
||||||
== Changelog ==
|
== 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) =
|
= 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) =
|
= 1.2 (2013-08-03) =
|
||||||
* カレンダー・ウィジェットでの不具合に対応するため、日付フォーマットとそのクオートを修正しました。
|
* カレンダー・ウィジェットでの不具合に対応するため、日付フォーマットとそのクオートを修正しました。
|
||||||
|
|
|
@ -158,8 +158,14 @@ When auto upgrading of SQLite Integration fails, please try manual upgrade via F
|
||||||
|
|
||||||
== Changelog ==
|
== 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) =
|
= 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) =
|
= 1.2 (2013-08-03) =
|
||||||
* Fixed the date string format and its quotation for calendar widget.
|
* Fixed the date string format and its quotation for calendar widget.
|
||||||
|
|
|
@ -22,8 +22,8 @@ function make_db_sqlite() {
|
||||||
$pdo = new PDO('sqlite:'.FQDB, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
|
$pdo = new PDO('sqlite:'.FQDB, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
|
||||||
} catch (PDOException $err) {
|
} catch (PDOException $err) {
|
||||||
$err_data = $err->errorInfo;
|
$err_data = $err->errorInfo;
|
||||||
$message = __("Database connection error!<br />", 'sqlite-integration');
|
$message = 'Database connection error!<br />';
|
||||||
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err_data[2]);
|
$message .= sprintf("Error message is: %s", $err_data[2]);
|
||||||
echo $message;
|
echo $message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,8 @@ function make_db_sqlite() {
|
||||||
$pdo->commit();
|
$pdo->commit();
|
||||||
} else {
|
} else {
|
||||||
$pdo->rollBack();
|
$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 occured while creating tables or indexes...<br />Query was: %s<br />", var_export($rewritten_query, true));
|
||||||
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err_data[2]);
|
$message .= sprintf("Error message is: %s", $err_data[2]);
|
||||||
echo $message;
|
echo $message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue