version 1.7 release
git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/tags/1.7@980581 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
parent
8286b0ac20
commit
6727d8887b
|
@ -0,0 +1,8 @@
|
|||
* Version 1.7 can't create wp-config.php when installing with WordPress 4.0
|
||||
|
||||
When install process notices that there's no wp-config.php, it tries to
|
||||
create one from wp-config-sample.php. During that time, WordPress unsets
|
||||
global $wpdb and calls require_wp_db() function.
|
||||
That function newly instantiates wpdb class. SQLite Integration has no
|
||||
way of intercepting that process.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
2014-09-05 KOJIMA Toshiyasu
|
||||
|
||||
* version 1.7 release.
|
||||
* update readme.txt and readme-ja.txt.
|
||||
|
||||
2014-08-29 KOJIMA Toshiyasu
|
||||
|
||||
* Added ChangeLog and BUGS files.
|
3
db.php
3
db.php
|
@ -5,7 +5,7 @@
|
|||
* This file must be placed in the directory wordpress/wp-content/db.php.
|
||||
* WordPress loads this file automatically.
|
||||
*
|
||||
* @version 1.6.2
|
||||
* @version 1.7
|
||||
* @package SQLite Integration
|
||||
* @author Kojima Toshiyasu
|
||||
*
|
||||
|
@ -34,7 +34,6 @@ if (!defined('ABSPATH')) { // Oh, you are not WordPress!
|
|||
if (defined('USE_MYSQL') && USE_MYSQL) return;
|
||||
|
||||
function pdo_log_error($message, $data = null) {
|
||||
|
||||
if (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin') !== false) {
|
||||
$admin_dir = '';
|
||||
} else {
|
||||
|
|
|
@ -172,7 +172,6 @@ class PDOSQLiteUDFS {
|
|||
//convert to ISO time
|
||||
$date = date("Y-m-d H:i:s", $field);
|
||||
//now submit to dateformat
|
||||
|
||||
return is_null($format) ? $date : $self->dateformat($date, $format);
|
||||
}
|
||||
/**
|
||||
|
@ -342,7 +341,6 @@ class PDOSQLiteUDFS {
|
|||
$type .= 's';
|
||||
}
|
||||
return "$_parts[0] $_parts[1]";
|
||||
break;
|
||||
case "minute_second":
|
||||
list($minutes, $seconds) = explode (':', $_parts[0]);
|
||||
$minutes = intval($minutes);
|
||||
|
@ -350,8 +348,6 @@ class PDOSQLiteUDFS {
|
|||
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
|
||||
$seconds = ($seconds > 1) ? "$seconds seconds" : "$seconds second";
|
||||
return "$minutes $seconds";
|
||||
break;
|
||||
|
||||
case "hour_second":
|
||||
list($hours, $minutes, $seconds) = explode (':', $_parts[0]);
|
||||
$hours = intval($hours);
|
||||
|
@ -361,7 +357,6 @@ class PDOSQLiteUDFS {
|
|||
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
|
||||
$seconds = ($seconds > 1) ? "$seconds seconds" : "$seconds second";
|
||||
return "$hours $minutes $seconds";
|
||||
break;
|
||||
case "hour_minute":
|
||||
list($hours, $minutes) = explode (':', $_parts[0]);
|
||||
$hours = intval($hours);
|
||||
|
@ -369,7 +364,6 @@ class PDOSQLiteUDFS {
|
|||
$hours = ($hours > 1) ? "$hours hours" : "$hours hour";
|
||||
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
|
||||
return "$hours $minutes";
|
||||
break;
|
||||
case "day_second":
|
||||
$days = intval($_parts[0]);
|
||||
list($hours, $minutes, $seconds) = explode (':', $_parts[1]);
|
||||
|
@ -381,7 +375,6 @@ class PDOSQLiteUDFS {
|
|||
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
|
||||
$seconds = ($seconds > 1) ? "$seconds seconds" : "$seconds second";
|
||||
return "$days $hours $minutes $seconds";
|
||||
break;
|
||||
case "day_minute":
|
||||
$days = intval($_parts[0]);
|
||||
list($hours, $minutes) = explode (':', $_parts[1]);
|
||||
|
@ -391,14 +384,12 @@ class PDOSQLiteUDFS {
|
|||
$hours = ($hours > 1) ? "$hours hours" : "$hours hour";
|
||||
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
|
||||
return "$days $hours $minutes";
|
||||
break;
|
||||
case "day_hour":
|
||||
$days = intval($_parts[0]);
|
||||
$hours = intval($_parts[1]);
|
||||
$days = $days > 1 ? "$days days" : "$days day";
|
||||
$hours = ($hours > 1) ? "$hours hours" : "$hours hour";
|
||||
return "$days $hours";
|
||||
break;
|
||||
case "year_month":
|
||||
list($years, $months) = explode ('-', $_parts[0]);
|
||||
$years = intval($years);
|
||||
|
@ -406,7 +397,6 @@ class PDOSQLiteUDFS {
|
|||
$years = ($years > 1) ? "$years years" : "$years year";
|
||||
$months = ($months > 1) ? "$months months": "$months month";
|
||||
return "$years $months";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -488,14 +478,21 @@ class PDOSQLiteUDFS {
|
|||
* @return unsigned integer
|
||||
*/
|
||||
public function field() {
|
||||
global $wpdb;
|
||||
$numArgs = func_num_args();
|
||||
if ($numArgs < 2 or is_null(func_get_arg(0))) {
|
||||
return 0;
|
||||
} else {
|
||||
$arg_list = func_get_args();
|
||||
}
|
||||
$arr = func_get_args();
|
||||
$searchString = strtolower(array_shift($arr));
|
||||
$searchString = array_shift($arg_list);
|
||||
$str_to_check = substr($searchString, 0, strpos($searchString, '.'));
|
||||
$str_to_check = str_replace($wpdb->prefix, '', $str_to_check);
|
||||
if ($str_to_check && in_array(trim($str_to_check), $wpdb->tables)) return;
|
||||
for ($i = 0; $i < $numArgs-1; $i++) {
|
||||
if ($searchString === strtolower($arr[$i])) return $i + 1;
|
||||
if ($searchString === strtolower($arg_list[$i])) {
|
||||
return $i + 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -342,34 +342,27 @@ class PDOSQLiteUDFS {
|
|||
case "minute_second":
|
||||
list($minutes, $seconds) = explode(':', $_parts[0]);
|
||||
return 'PT' . $minutes . 'M' . $seconds . 'S';
|
||||
break;
|
||||
case "hour_second":
|
||||
list($hours, $minutes, $seconds) = explode (':', $_parts[0]);
|
||||
return 'PT' . $hours . 'H' . $minutes . 'M' . $seconds . 'S';
|
||||
break;
|
||||
case "hour_minute":
|
||||
list($hours, $minutes) = explode (':', $_parts[0]);
|
||||
return 'PT' . $hours . 'H' . $minutes . 'M';
|
||||
break;
|
||||
case "day_second":
|
||||
$days = intval($_parts[0]);
|
||||
list($hours, $minutes, $seconds) = explode (':', $_parts[1]);
|
||||
return 'P' . $days . 'D' . 'T' . $hours . 'H' . $minutes . 'M' . $seconds . 'S';
|
||||
break;
|
||||
case "day_minute":
|
||||
$days = intval($_parts[0]);
|
||||
list($hours, $minutes) = explode(':', $parts[1]);
|
||||
return 'P' . $days . 'D' . 'T' . $hours . 'H' . $minutes . 'M';
|
||||
break;
|
||||
case "day_hour":
|
||||
$days = intval($_parts[0]);
|
||||
$hours = intval($_parts[1]);
|
||||
return 'P' . $days . 'D' . 'T' . $hours . 'H';
|
||||
break;
|
||||
case "year_month":
|
||||
list($years, $months) = explode ('-', $_parts[0]);
|
||||
return 'P' . $years . 'Y' . $months . 'M';
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -449,6 +442,7 @@ class PDOSQLiteUDFS {
|
|||
* @return unsigned integer
|
||||
*/
|
||||
public function field() {
|
||||
global $wpdb;
|
||||
$numArgs = func_num_args();
|
||||
if ($numArgs < 2 or is_null(func_get_arg(0))) {
|
||||
return 0;
|
||||
|
@ -456,6 +450,9 @@ class PDOSQLiteUDFS {
|
|||
$arg_list = func_get_args();
|
||||
}
|
||||
$searchString = array_shift($arg_list);
|
||||
$str_to_check = substr($searchString, 0, strpos($searchString, '.'));
|
||||
$str_to_check = str_replace($wpdb->prefix, '', $str_to_check);
|
||||
if ($str_to_check && in_array(trim($str_to_check), $wpdb->tables)) return;
|
||||
for ($i = 0; $i < $numArgs-1; $i++) {
|
||||
if ($searchString === strtolower($arg_list[$i])) {
|
||||
return $i + 1;
|
||||
|
@ -590,7 +587,6 @@ class PDOSQLiteUDFS {
|
|||
$unsigned_int_data = sprintf('%u', $address);
|
||||
return $unsigned_int_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL DATEDIFF() function.
|
||||
*
|
||||
|
|
|
@ -43,7 +43,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::__construct()
|
||||
*/
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
register_shutdown_function(array($this, '__destruct'));
|
||||
|
||||
if (WP_DEBUG)
|
||||
|
@ -60,7 +60,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::__destruct()
|
||||
*/
|
||||
function __destruct() {
|
||||
public function __destruct() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::set_charset()
|
||||
*/
|
||||
function set_charset($dbh, $charset = null, $collate = null) {
|
||||
public function set_charset($dbh, $charset = null, $collate = null) {
|
||||
if ( ! isset( $charset ) )
|
||||
$charset = $this->charset;
|
||||
if ( ! isset( $collate ) )
|
||||
|
@ -82,7 +82,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::set_sql_mode()
|
||||
*/
|
||||
function set_sql_mode($modes = array()) {
|
||||
public function set_sql_mode($modes = array()) {
|
||||
unset($modes);
|
||||
return;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::select()
|
||||
*/
|
||||
function select($db, $dbh = null) {
|
||||
public function select($db, $dbh = null) {
|
||||
if (is_null($dbh))
|
||||
$dbh = $this->dbh;
|
||||
$this->ready = true;
|
||||
|
@ -116,7 +116,18 @@ class PDODB extends wpdb {
|
|||
function _real_escape($string) {
|
||||
return addslashes($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to dummy out wpdb::esc_like() function.
|
||||
*
|
||||
* WordPress 4.0.0 introduced esc_like() function that adds backslashes to %,
|
||||
* underscore and backslash, which is not interpreted as escape character
|
||||
* by SQLite. So we override it and dummy out this function.
|
||||
*
|
||||
* @see wpdb::esc_like()
|
||||
*/
|
||||
public function esc_like($text) {
|
||||
return $text;
|
||||
}
|
||||
/**
|
||||
* Method to put out the error message.
|
||||
*
|
||||
|
@ -124,7 +135,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::print_error()
|
||||
*/
|
||||
function print_error($str = '') {
|
||||
public function print_error($str = '') {
|
||||
global $EZSQL_ERROR;
|
||||
|
||||
if (!$str) {
|
||||
|
@ -172,7 +183,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::flush
|
||||
*/
|
||||
function flush() {
|
||||
public function flush() {
|
||||
$this->last_result = array();
|
||||
$this->col_info = null;
|
||||
$this->last_query = null;
|
||||
|
@ -187,7 +198,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::db_connect()
|
||||
*/
|
||||
function db_connect($allow_bail=true) {
|
||||
public function db_connect($allow_bail=true) {
|
||||
if (WP_DEBUG) {
|
||||
$this->dbh = new PDOEngine();
|
||||
} else {
|
||||
|
@ -202,13 +213,14 @@ class PDODB extends wpdb {
|
|||
}
|
||||
$is_enabled_foreign_keys = @$this->get_var('PRAGMA foreign_keys');
|
||||
if ($is_enabled_foreign_keys == '0') @$this->query('PRAGMA foreign_keys = ON');
|
||||
$this->has_connected = true;
|
||||
$this->ready = true;
|
||||
}
|
||||
/**
|
||||
* Method to dummy out wpdb::check_connection()
|
||||
*
|
||||
*/
|
||||
function check_connection($allow_bail=true) {
|
||||
public function check_connection($allow_bail=true) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
|
@ -219,7 +231,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::query()
|
||||
*/
|
||||
function query($query) {
|
||||
public function query($query) {
|
||||
if (!$this->ready)
|
||||
return false;
|
||||
|
||||
|
@ -267,7 +279,14 @@ class PDODB extends wpdb {
|
|||
return $return_val;
|
||||
}
|
||||
/**
|
||||
* Method for future use?
|
||||
*
|
||||
* WordPress 3.9 separated the method to execute real query from query() function.
|
||||
* This is for the restoration from the case that nothing returns from database.
|
||||
* But this is necessary because we aleady did error manipulations in
|
||||
* pdoengine.class.php. So we don't use this function.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _do_query($query) {
|
||||
if (defined('SAVEQUERIES') && SAVEQUERIES) {
|
||||
|
@ -301,7 +320,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::has_cap()
|
||||
*/
|
||||
function has_cap($db_cap) {
|
||||
public function has_cap($db_cap) {
|
||||
switch(strtolower($db_cap)) {
|
||||
case 'collation':
|
||||
case 'group_concat':
|
||||
|
@ -322,7 +341,7 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* @see wpdb::db_version()
|
||||
*/
|
||||
function db_version() {
|
||||
public function db_version() {
|
||||
//global $required_mysql_version;
|
||||
//return $required_mysql_version;
|
||||
return '5.5';
|
||||
|
|
|
@ -26,6 +26,12 @@ class PDOEngine extends PDO {
|
|||
* @var unsigned integer
|
||||
*/
|
||||
public $found_rows_result = null;
|
||||
/**
|
||||
* Class variable used for query with ORDER BY FIELD()
|
||||
*
|
||||
* @var array of the object
|
||||
*/
|
||||
public $pre_ordered_results = null;
|
||||
/**
|
||||
* Class variable to store the rewritten queries.
|
||||
*
|
||||
|
@ -157,15 +163,36 @@ class PDOEngine extends PDO {
|
|||
* @param none
|
||||
*/
|
||||
function __construct() {
|
||||
register_shutdown_function(array($this, '__destruct'));
|
||||
$this->init();
|
||||
}
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* If SQLITE_MEM_DEBUG constant is defined, append information about
|
||||
* memory usage into database/mem_debug.txt.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function __destruct() {
|
||||
$this->pdo = null;
|
||||
if (defined('SQLITE_MEM_DEBUG') && SQLITE_MEM_DEBUG) {
|
||||
$max = ini_get('memory_limit');
|
||||
if (is_null($max)) {
|
||||
$message = sprintf("[%s] Memory_limit is not set in php.ini file.", date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']));
|
||||
file_put_contents(FQDBDIR . 'mem_debug.txt', $message, FILE_APPEND);
|
||||
return true;
|
||||
}
|
||||
if (stripos($max, 'M') !== false) {
|
||||
$max = (int) $max * 1024 * 1024;
|
||||
}
|
||||
$peak = memory_get_peak_usage(true);
|
||||
$used = round((int) $peak / (int) $max * 100, 2);
|
||||
if ($used > 90) {
|
||||
$message = sprintf("[%s] Memory peak usage warning: %s %% used. (max: %sM, now: %sM)\n", date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']), $used, $max, $peak);
|
||||
file_put_contents(FQDBDIR . 'mem_debug.txt', $message, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
//$this->pdo = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -370,6 +397,12 @@ class PDOEngine extends PDO {
|
|||
default:
|
||||
$engine = $this->prepare_engine($this->query_type);
|
||||
$this->rewritten_query = $engine->rewrite_query($query, $this->query_type);
|
||||
if (!is_null($this->pre_ordered_results)) {
|
||||
$this->results = $this->pre_ordered_results;
|
||||
$this->num_rows = $this->return_value = count($this->results);
|
||||
$this->pre_ordered_results = null;
|
||||
break;
|
||||
}
|
||||
$this->queries[] = "Rewritten:\n$this->rewritten_query";
|
||||
$this->extract_variables();
|
||||
$statement = $this->prepare_query();
|
||||
|
@ -714,6 +747,10 @@ class PDOEngine extends PDO {
|
|||
//long queries can really kill this
|
||||
$pattern = '/(?<!\\\\)([\'"])(.*?)(?<!\\\\)\\1/imsx';
|
||||
$_limit = $limit = ini_get('pcre.backtrack_limit');
|
||||
// if user's setting is more than default * 10, make PHP do the job.
|
||||
if ($limit > 10000000) {
|
||||
$query = preg_replace_callback($pattern, array($this, 'replace_variables_with_placeholders'), $this->rewritten_query);
|
||||
} else {
|
||||
do {
|
||||
if ($limit > 10000000) {
|
||||
$message = 'The query is too big to parse properly';
|
||||
|
@ -724,10 +761,11 @@ class PDOEngine extends PDO {
|
|||
$query = preg_replace_callback($pattern, array($this,'replace_variables_with_placeholders'), $this->rewritten_query);
|
||||
}
|
||||
$limit = $limit * 10;
|
||||
} while (empty($query));
|
||||
} while (is_null($query));
|
||||
|
||||
//reset the pcre.backtrack_limist
|
||||
ini_set('pcre.backtrack_limit', $_limit);
|
||||
}
|
||||
$this->queries[] = "With Placeholders:\n" . $query;
|
||||
$this->prepared_query = $query;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,18 @@ class PDOSQLiteDriver {
|
|||
* @var boolean
|
||||
*/
|
||||
private $rewrite_between = false;
|
||||
/**
|
||||
* Variable to check how many times rewriting BETWEEN is needed.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $num_of_rewrite_between = 0;
|
||||
/**
|
||||
* Variable to check order by field() with column data.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $orderby_field = false;
|
||||
/**
|
||||
* Method to rewrite a query string for SQLite to execute.
|
||||
*
|
||||
|
@ -91,6 +103,7 @@ class PDOSQLiteDriver {
|
|||
//$this->rewrite_boolean();
|
||||
$this->fix_date_quoting();
|
||||
$this->rewrite_between();
|
||||
$this->handle_orderby_field();
|
||||
break;
|
||||
case 'insert':
|
||||
//$this->safe_strip_backticks();
|
||||
|
@ -184,6 +197,10 @@ class PDOSQLiteDriver {
|
|||
}
|
||||
if (stripos($token, 'BETWEEN') !== false) {
|
||||
$this->rewrite_between = true;
|
||||
$this->num_of_rewrite_between++;
|
||||
}
|
||||
if (stripos($token, 'ORDER BY FIELD') !== false) {
|
||||
$this->orderby_field = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +402,6 @@ class PDOSQLiteDriver {
|
|||
* @access private
|
||||
*/
|
||||
private function handle_describe_query(){
|
||||
// $this->_query = "select 1=1";
|
||||
$pattern = '/^\\s*(DESCRIBE|DESC)\\s*(.*)/i';
|
||||
if (preg_match($pattern, $this->_query, $match)) {
|
||||
$tablename = preg_replace('/[\';]/', '', $match[2]);
|
||||
|
@ -429,7 +445,7 @@ class PDOSQLiteDriver {
|
|||
if (stripos($opt->compile_option, 'ENABLE_UPDATE_DELETE_LIMIT') !== false) return;
|
||||
}
|
||||
if (stripos($this->_query, '(select') === false) {
|
||||
$this->_query = preg_replace('/\\s*ORDER\\s*BY\\s*.*$/i', '', $this->_query);
|
||||
$this->_query = preg_replace('/\\s+ORDER\\s+BY\\s*.*$/i', '', $this->_query);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -619,7 +635,6 @@ class PDOSQLiteDriver {
|
|||
$val = trim(array_shift($ins_data_array));
|
||||
$ins_data_assoc[trim($col)] = $val;
|
||||
}
|
||||
// $ins_data_assoc = array_combine($col_array, $ins_array);
|
||||
$condition = '';
|
||||
foreach ($unique_keys_for_cond as $unique_key) {
|
||||
if (strpos($unique_key, ',') !== false) {
|
||||
|
@ -635,7 +650,6 @@ class PDOSQLiteDriver {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
// $condition = rtrim($condition, ' AND ');
|
||||
} else {
|
||||
$col = trim($unique_key);
|
||||
if (isset($ins_data_assoc[$col])) {
|
||||
|
@ -653,7 +667,6 @@ class PDOSQLiteDriver {
|
|||
$this->_query = 'INSERT INTO '.$table_name.' '.$insert_data;
|
||||
return;
|
||||
} else {
|
||||
// change (col, col...) values (data, data...) to array(col=>data, col=>data...)
|
||||
if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/im', $insert_data, $match_2)) {
|
||||
$col_array = explode(',', $match_2[1]);
|
||||
$ins_array = explode(',', $match_2[2]);
|
||||
|
@ -664,8 +677,6 @@ class PDOSQLiteDriver {
|
|||
$ins_array_assoc[$col] = $val;
|
||||
}
|
||||
}
|
||||
// change col = data, col = data to array(col=>data, col=>data)
|
||||
// some plugins have semi-colon at the end of the query
|
||||
$update_data = rtrim($update_data, ';');
|
||||
$tmp_array = explode(',', $update_data);
|
||||
foreach ($tmp_array as $pair) {
|
||||
|
@ -674,7 +685,6 @@ class PDOSQLiteDriver {
|
|||
$value = trim($value);
|
||||
$update_array_assoc[$col] = $value;
|
||||
}
|
||||
// change array(col=>values(col)) to array(col=>data)
|
||||
foreach ($update_array_assoc as $key => &$value) {
|
||||
if (preg_match('/^VALUES\\s*\((.*)\)$/im', $value, $match_3)) {
|
||||
$col = trim($match_3[1]);
|
||||
|
@ -697,18 +707,11 @@ class PDOSQLiteDriver {
|
|||
$update_strings = rtrim($update_strings, ',');
|
||||
$unique_where = array_unique($where_array, SORT_REGULAR);
|
||||
$where_string = ' WHERE ' . implode(' AND ', $unique_where);
|
||||
// $where_string = ' WHERE ' . rtrim($where_string, ',');
|
||||
$update_query = 'UPDATE ' . $table_name . ' SET ' . $update_strings . $where_string;
|
||||
$this->_query = $update_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;
|
||||
// }
|
||||
}
|
||||
/**
|
||||
* Method to rewrite BETWEEN A AND B clause.
|
||||
|
@ -720,15 +723,57 @@ class PDOSQLiteDriver {
|
|||
*/
|
||||
private function rewrite_between() {
|
||||
if (!$this->rewrite_between) return;
|
||||
$pattern = '/\\s*(CAST\(.+?\)|[^\\s\(]*)?\\s*BETWEEN\\s*([^\\s]*)?\\s*AND\\s*([^\\s\)]*)?\\s*/ims';
|
||||
$pattern = '/\\s*(CAST\([^\)]+?\)|[^\\s\(]*)?\\s*BETWEEN\\s*([^\\s]*)?\\s*AND\\s*([^\\s\)]*)?\\s*/ims';
|
||||
do {
|
||||
if (preg_match($pattern, $this->_query, $match)) {
|
||||
$column_name = trim($match[1]);
|
||||
$min_value = trim($match[2]);
|
||||
$max_value = trim($match[3]);
|
||||
$max_value = rtrim($max_value);
|
||||
$replacement = " $column_name >= $min_value AND $column_name <= $max_value";
|
||||
$replacement = " ($column_name >= $min_value AND $column_name <= $max_value)";
|
||||
$this->_query = str_ireplace($match[0], $replacement, $this->_query);
|
||||
}
|
||||
$this->num_of_rewrite_between--;
|
||||
} while ($this->num_of_rewrite_between > 0);
|
||||
}
|
||||
/**
|
||||
* Method to handle ORDER BY FIELD() clause.
|
||||
*
|
||||
* When FIELD() function has column name to compare, we can't rewrite it with
|
||||
* use defined functions. When this function detect column name in the argument,
|
||||
* it creates another instance, does the query withuot ORDER BY clause and gives
|
||||
* the result array sorted to the main instance.
|
||||
*
|
||||
* If FIELD() function doesn't have column name, it will use the user defined
|
||||
* function. usort() function closure function to compare the items.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function handle_orderby_field() {
|
||||
if (!$this->orderby_field) return;
|
||||
global $wpdb;
|
||||
$pattern = '/\\s+ORDER\\s+BY\\s+FIELD\\s*\(\\s*([^\)]+?)\\s*\)/i';
|
||||
if (preg_match($pattern, $this->_query, $match)) {
|
||||
global $flipped;
|
||||
$params = explode(',', $match[1]);
|
||||
$params = array_map('trim', $params);
|
||||
$tbl_col = array_shift($params);
|
||||
$flipped = array_flip($params);
|
||||
$tbl_name = substr($tbl_col, 0, strpos($tbl_col, '.'));
|
||||
$tbl_name = str_replace($wpdb->prefix, '', $tbl_name);
|
||||
if ($tbl_name && in_array($tbl_name, $wpdb->tables)) {
|
||||
$query = str_replace($match[0], '', $this->_query);
|
||||
$_wpdb = new PDODB();
|
||||
$results = $_wpdb->get_results($query);
|
||||
$_wpdb = null;
|
||||
$compare = function($a, $b) {
|
||||
global $flipped;
|
||||
return $flipped[$a->ID] - $flipped[$b->ID];
|
||||
};
|
||||
usort($results, $compare);
|
||||
}
|
||||
$wpdb->dbh->pre_ordered_results = $results;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Method to avoid DELETE with JOIN statement.
|
||||
|
@ -743,11 +788,22 @@ class PDOSQLiteDriver {
|
|||
*/
|
||||
private function delete_workaround() {
|
||||
global $wpdb;
|
||||
// $pattern = "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (option_name) WHERE o2.option_id > o1.option_id";
|
||||
$pattern = "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2";
|
||||
$pattern2 = "DELETE a, b FROM $wpdb->sitemeta AS a, $wpdb->sitemeta AS b";
|
||||
$rewritten = "DELETE FROM $wpdb->options WHERE option_id IN (SELECT MIN(option_id) FROM $wpdb->options GROUP BY option_name HAVING COUNT(*) > 1)";
|
||||
if (stripos($this->_query, $pattern) !== false) {
|
||||
$this->_query = $rewritten;
|
||||
} else if (stripos($this->_query, $pattern2) !== false) {
|
||||
$time = time();
|
||||
$prep_query = "SELECT a.meta_id AS aid, b.meta_id AS bid FROM $wpdb->sitemeta AS a INNER JOIN $wpdb->sitemeta AS b ON a.meta_key='_site_transient_timeout_'||substr(b.meta_key, 17) WHERE b.meta_key='_site_transient_'||substr(a.meta_key, 25) AND a.meta_value < $time";
|
||||
$_wpdb = new PDODB();
|
||||
$ids = $_wpdb->get_results($prep_query);
|
||||
foreach ($ids as $id) {
|
||||
$ids_to_delete[] = $id->aid;
|
||||
$ids_to_delete[] = $id->bid;
|
||||
}
|
||||
$rewritten = "DELETE FROM $wpdb->sitemeta WHERE meta_id IN (".implode(',', $ids_to_delete).")";
|
||||
$this->_query = $rewritten;
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -48,7 +48,6 @@ class AlterQuery {
|
|||
$this->_query = 'SELECT 1=1';
|
||||
return $this->_query;
|
||||
}
|
||||
// foreach ($tokens as $token) {
|
||||
$command_name = strtolower($tokens['command']);
|
||||
switch ($command_name) {
|
||||
case 'add column': case 'rename to': case 'add index': case 'drop index':
|
||||
|
@ -72,7 +71,6 @@ class AlterQuery {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
// }
|
||||
if (!is_array($tmp_query)) {
|
||||
$this->_query[] = $tmp_query;
|
||||
} else {
|
||||
|
|
|
@ -130,7 +130,7 @@ class CreateQuery{
|
|||
'longblob' => 'blob', 'longtext' => 'text'
|
||||
);
|
||||
foreach ($array_types as $o=>$r){
|
||||
$pattern = "/\\b(?<!`)$o\\b\\s*(\([^\)]*\)*)?\\s*/ims";
|
||||
$pattern = "/\\b(?<!')$o\\b\\s*(\([^\)]*\)*)?\\s*/ims";
|
||||
if (preg_match("/^\\s*.*?\\s*\(.*?$o.*?\)/im", $this->_query)) {
|
||||
;
|
||||
} else {
|
||||
|
|
|
@ -6,8 +6,8 @@ Tags: database, SQLite, PDO
|
|||
Author: Kojima Toshiyasu
|
||||
Author URI: http://dogwood.skr.jp/
|
||||
Requires at least: 3.3
|
||||
Tested up to: 3.9
|
||||
Stable tag: 1.6.3
|
||||
Tested up to: 4.0
|
||||
Stable tag: 1.7
|
||||
License: GPLv2
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
|
@ -115,6 +115,10 @@ SQLite に戻りたいときには、この行を次のように変更するか
|
|||
|
||||
== よくある質問 ==
|
||||
|
||||
= 「データベース接続エラー」でインストールが止まります =
|
||||
|
||||
wp-config.php を手動で作成することが必要です。WordPress に作らせようとすると、途中でインストールが止まります。
|
||||
|
||||
= データベース・ファイルが作られません =
|
||||
|
||||
ディレクトリやファイルを作るのに失敗するのは、多くの場合、PHPにその権限がないことが原因です。サーバの設定を確認するか、管理者に聞いてみてください。
|
||||
|
@ -160,10 +164,18 @@ SQLite に戻りたいときには、この行を次のように変更するか
|
|||
|
||||
== Upgrade Notice ==
|
||||
|
||||
メタクエリを使うときのバグを修正しました。自動アップグレードで失敗するようなら、FTPを使っての手動アップグレードを試してみてください。
|
||||
WordPress 4.0 での動作チェックをして、いくつかのバグを修正しました。アップグレードをお勧めします。自動アップグレードで失敗するようなら、FTPを使っての手動アップグレードを試してみてください。
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.7 (2014-09-05) =
|
||||
* エディタ画面で、添付ファイルの並べ替えができなかったのを修正しました。
|
||||
* CREATE クエリのバグを修正しました。
|
||||
* 128x128 アイコンと 256x256 アイコンを追加しました。
|
||||
* pcre.backtrack_limit が大きな値に設定されている場合、それを使うようにしました。
|
||||
* メタクエリの BETWEEN の扱いを変更しました。
|
||||
* WordPress 4.0 での動作チェックをしました。
|
||||
|
||||
= 1.6.3 (2014-05-10) =
|
||||
* BETWEEN 比較をするメタクエリのバグを修正しました。
|
||||
* スペイン語カタログを追加しました。
|
||||
|
|
17
readme.txt
17
readme.txt
|
@ -6,8 +6,8 @@ Tags: database, SQLite, PDO
|
|||
Author: Kojima Toshiyasu
|
||||
Author URI: http://dogwood.skr.jp/
|
||||
Requires at least: 3.3
|
||||
Tested up to: 3.9
|
||||
Stable tag: 1.6.3
|
||||
Tested up to: 4.0
|
||||
Stable tag: 1.7
|
||||
License: GPLv2
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
|
@ -115,6 +115,10 @@ If export or import fails for some reason, please visit our site and try another
|
|||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Install stops with 'Error establishing a database connection' =
|
||||
|
||||
It is required that you should prepare wp-config.php manually. If you try to make WordPress create wp-config.php, you'll get that message and can't continue install process.
|
||||
|
||||
= Database file is not created =
|
||||
|
||||
The reason of failure in creating directory or files is often that PHP is not allowed to craete them. Please check your server setting or ask the administrator.
|
||||
|
@ -158,10 +162,17 @@ This plugin doesn't support 'WP_PLUGIN_URL' constant.
|
|||
|
||||
== Upgrade Notice ==
|
||||
|
||||
Fixed the bug about meta query with BETWEEN comparison which may cause some plugins to work correctly. Upgrade is recommended. When auto upgrading fails, please try manual upgrade via FTP.
|
||||
WordPress 4.0 compatibility is checked and some bugs are fixed. Upgrade is recommended. When auto upgrading fails, please try manual upgrade via FTP.
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.7 (2014-09-05) =
|
||||
* Fixed the bug about changing the order of the attachment file in the editor screen.
|
||||
* Fixed the bug about the manipulation of CREATE query.
|
||||
* Added an 128x128 icon and 256x256 icon.
|
||||
* Change for checking the user defined value of pcre.backtrack_limit and using it.
|
||||
* WordPress 4.0 compatibilitiy checked.
|
||||
|
||||
= 1.6.3 (2014-05-10) =
|
||||
* Fixed the bug about manipulating meta query with BETWEEN comparison.
|
||||
* Added the Spanish langugae support.
|
||||
|
|
|
@ -4,7 +4,7 @@ Plugin Name: SQLite Integration
|
|||
Plugin URI: http://dogwood.skr.jp/wordpress/sqlite-integration/
|
||||
Description: SQLite Integration is the plugin that enables WordPress to use SQLite. If you don't have MySQL and want to build a WordPress website, it's for you.
|
||||
Author: Kojima Toshiyasu
|
||||
Version: 1.6.3
|
||||
Version: 1.7
|
||||
Author URI: http://dogwood.skr.jp
|
||||
Text Domain: sqlite-integration
|
||||
Domain Path: /languages
|
||||
|
@ -44,7 +44,7 @@ $siteurl = get_option('siteurl');
|
|||
/*
|
||||
* Defines basic constants.
|
||||
*/
|
||||
define('SQLITE_INTEGRATION_VERSION', '1.6.2');
|
||||
define('SQLITE_INTEGRATION_VERSION', '1.7');
|
||||
define('SQLiteDir', dirname(plugin_basename(__FILE__)));
|
||||
define('SQLiteFilePath', dirname(__FILE__));
|
||||
define('SQLiteDirName', basename(SQLiteFilePath));
|
||||
|
@ -109,6 +109,7 @@ class SQLiteIntegration {
|
|||
register_activation_hook(__FILE__, array($this, 'install'));
|
||||
}
|
||||
if (function_exists('register_deactivation_hook')) {
|
||||
;
|
||||
}
|
||||
if (function_exists('register_uninstall_hook')) {
|
||||
register_uninstall_hook(__FILE__, array('SQLiteIntegration', 'uninstall'));
|
||||
|
|
|
@ -39,7 +39,7 @@ class SQLiteIntegrationUtils {
|
|||
return;
|
||||
$notice_string = __('Upgrading Notice: To finish upgrading, please activate SQLite Integration and go Setting >> SQLite Integration >> Miscellaneous, and click the button "update" at the bottom of the page. Or else replace wp-content/db.php with the one in sqlite-integration directory manually.', 'sqlite-integration');
|
||||
$current_version = defined('SQLITE_INTEGRATION_VERSION') ? SQLITE_INTEGRATION_VERSION : '';
|
||||
if (version_compare($current_version, '1.6.2', '=')) return;
|
||||
if (version_compare($current_version, '1.7', '=')) return;
|
||||
$version = '';
|
||||
if (defined('WP_CONTENT_DIR')) {
|
||||
$path = WP_CONTENT_DIR . '/db.php';
|
||||
|
|
Loading…
Reference in New Issue