Fixed some bugs and added more features.
git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@852178 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
parent
22a658ac3a
commit
71a1df03db
8
db.php
8
db.php
|
@ -18,9 +18,17 @@ if (!defined('ABSPATH')) { // Oh, you are not WordPress!
|
|||
* USE_MYSQL is a directive for using MySQL for database.
|
||||
* If you want to change the database from SQLite to MySQL or from MySQL to SQLite,
|
||||
* the line below in the wp-config.php will enable you to use MySQL.
|
||||
*
|
||||
* <code>
|
||||
* define('USE_MYSQL', true);
|
||||
* </code>
|
||||
*
|
||||
* If you want to use SQLite, the line below will do. Or simply removing the line will
|
||||
* be enough.
|
||||
*
|
||||
* <code>
|
||||
* define('USE_MYSQL', false);
|
||||
* </code>
|
||||
*/
|
||||
if (defined('USE_MYSQL') && USE_MYSQL === true) return;
|
||||
|
||||
|
|
|
@ -82,6 +82,9 @@ class PDOSQLiteUDFS {
|
|||
'inet_aton' => 'inet_aton',
|
||||
'datediff' => 'datediff',
|
||||
'locate' => 'locate',
|
||||
'utc_date' => 'utc_date',
|
||||
'utc_time' => 'utc_time',
|
||||
'utc_timestamp' => 'utc_timestamp',
|
||||
'version' => 'version'
|
||||
);
|
||||
/**
|
||||
|
@ -224,7 +227,8 @@ class PDOSQLiteUDFS {
|
|||
/**
|
||||
* Method to emulate MySQL SUBSTRING() function.
|
||||
*
|
||||
* This function rewrites the function name to SQLite compatible substr().
|
||||
* This function rewrites the function name to SQLite compatible substr(),
|
||||
* which can manipulate UTF-8 characters.
|
||||
*
|
||||
* @param string $text
|
||||
* @param integer $pos representing the start point.
|
||||
|
@ -667,17 +671,45 @@ class PDOSQLiteUDFS {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Method to return MySQL version.
|
||||
*
|
||||
* This function only returns WordPress $required_mysql_version, because it is
|
||||
* meaningless for SQLite database.
|
||||
* Method to return GMT date in the string format.
|
||||
*
|
||||
* @param none
|
||||
* @return string representing the version number
|
||||
* @return string formatted GMT date 'dddd-mm-dd'
|
||||
*/
|
||||
public function utc_date() {
|
||||
return gmdate('Y-m-d', time());
|
||||
}
|
||||
/**
|
||||
* Method to return GMT time in the string format.
|
||||
*
|
||||
* @param none
|
||||
* @return string formatted GMT time '00:00:00'
|
||||
*/
|
||||
public function utc_time() {
|
||||
return gmdate('H:i:s', time());
|
||||
}
|
||||
/**
|
||||
* Method to return GMT time stamp in the string format.
|
||||
*
|
||||
* @param none
|
||||
* @return string formatted GMT timestamp 'yyyy-mm-dd 00:00:00'
|
||||
*/
|
||||
public function utc_timestamp() {
|
||||
return gmdate('Y-m-d H:i:s', time());
|
||||
}
|
||||
/**
|
||||
* Method to return MySQL version.
|
||||
*
|
||||
* This function only returns the current newest version number of MySQL,
|
||||
* because it is meaningless for SQLite database.
|
||||
*
|
||||
* @param none
|
||||
* @return string representing the version number: major_version.minor_version
|
||||
*/
|
||||
public function version() {
|
||||
global $required_mysql_version;
|
||||
return $required_mysql_version;
|
||||
// global $required_mysql_version;
|
||||
// return $required_mysql_version;
|
||||
return '5.5';
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -84,6 +84,9 @@ class PDOSQLiteUDFS {
|
|||
'inet_aton' => 'inet_aton',
|
||||
'datediff' => 'datediff',
|
||||
'locate' => 'locate',
|
||||
'utc_date' => 'utc_date',
|
||||
'utc_time' => 'utc_time',
|
||||
'utc_timestamp' => 'utc_timestamp',
|
||||
'version' => 'version'
|
||||
);
|
||||
/**
|
||||
|
@ -225,7 +228,8 @@ class PDOSQLiteUDFS {
|
|||
/**
|
||||
* Method to emulate MySQL SUBSTRING() function.
|
||||
*
|
||||
* This function rewrites the function name to SQLite compatible substr().
|
||||
* This function rewrites the function name to SQLite compatible substr(),
|
||||
* which can manipulate UTF-8 characters.
|
||||
*
|
||||
* @param string $text
|
||||
* @param integer $pos representing the start point.
|
||||
|
@ -640,17 +644,45 @@ class PDOSQLiteUDFS {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Method to return MySQL version.
|
||||
*
|
||||
* This function only returns WordPress $required_mysql_version, because it is
|
||||
* meaningless for SQLite database.
|
||||
* Method to return GMT date in the string format.
|
||||
*
|
||||
* @param none
|
||||
* @return string representing the version number
|
||||
* @return string formatted GMT date 'dddd-mm-dd'
|
||||
*/
|
||||
public function utc_date() {
|
||||
return gmdate('Y-m-d', time());
|
||||
}
|
||||
/**
|
||||
* Method to return GMT time in the string format.
|
||||
*
|
||||
* @param none
|
||||
* @return string formatted GMT time '00:00:00'
|
||||
*/
|
||||
public function utc_time() {
|
||||
return gmdate('H:i:s', time());
|
||||
}
|
||||
/**
|
||||
* Method to return GMT time stamp in the string format.
|
||||
*
|
||||
* @param none
|
||||
* @return string formatted GMT timestamp 'yyyy-mm-dd 00:00:00'
|
||||
*/
|
||||
public function utc_timestamp() {
|
||||
return gmdate('Y-m-d H:i:s', time());
|
||||
}
|
||||
/**
|
||||
* Method to return MySQL version.
|
||||
*
|
||||
* This function only returns the current newest version number of MySQL,
|
||||
* because it is meaningless for SQLite database.
|
||||
*
|
||||
* @param none
|
||||
* @return string representing the version number: major_version.minor_version
|
||||
*/
|
||||
public function version() {
|
||||
global $required_mysql_version;
|
||||
return $required_mysql_version;
|
||||
// global $required_mysql_version;
|
||||
// return $required_mysql_version;
|
||||
return '5.5';
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -3,6 +3,7 @@
|
|||
*
|
||||
* This script is only included on the documentation and utility page.
|
||||
*
|
||||
* @package SQLite Integration
|
||||
* @author Kojima Toshiyasu
|
||||
*/
|
||||
jQuery(document).ready(function($) {
|
||||
|
|
Binary file not shown.
|
@ -129,12 +129,11 @@ msgstr "パッチ"
|
|||
|
||||
#: utilities/documentation.php:32
|
||||
msgid ""
|
||||
"This is a brief documentation about this plugin. For more details, see also "
|
||||
"the <a href=\"http://dogwood.skr.jp/wordpress/sqlite-integration\">Plugin "
|
||||
"Page</a>."
|
||||
"This is a brief documentation about this plugin. For more details, see also the "
|
||||
"<a href=\"http://dogwood.skr.jp/wordpress/sqlite-integration/\">SQLite Integration page</a>."
|
||||
msgstr ""
|
||||
"このプラグインについての短いドキュメントです。詳しくは、<a href=\"http://dogwood.skr.jp/wordpress/"
|
||||
"sqlite-integration\">プラグインのページ</a>をご覧ください。"
|
||||
"sqlite-integration/\">SQLite Integration</a> のページ</a>をご覧ください。"
|
||||
|
||||
#: utilities/documentation.php:35
|
||||
msgid ""
|
||||
|
@ -266,12 +265,12 @@ msgstr ""
|
|||
msgid ""
|
||||
"Some plugins do work fine if you rewrite MySQL functions. I made some patch "
|
||||
"files and <a href=\"%s?page=patch\">Patch Utility</a>. See also the <a href="
|
||||
"\"http://dogwood.skr.jp/wordpress/sqlite-integration\">SQLite Integration page</a> for "
|
||||
"more details."
|
||||
"\"http://dogwood.skr.jp/wordpress/sqlite-integration/#plugin-compat\">SQLite Integration"
|
||||
" Page</a> for more details."
|
||||
msgstr ""
|
||||
"MySQLの関数を書き換えると動作するプラグインがあります。いくつかはパッチファイルと、<a href=\"%s?page=patch\">"
|
||||
"パッチをあてる</a>ページを作りました。<a href=\"http://dogwood.skr.jp/wordpress/sqlite-integration\">"
|
||||
"プラグインのページ</a>もご覧ください。"
|
||||
"パッチをあてる</a>ページを作りました。<a href=\"http://dogwood.skr.jp/wordpress/sqlite-integration-ja/#plugin-compat\">"
|
||||
"SQLite Integration のページ</a>もご覧ください。"
|
||||
|
||||
#: utilities/documentation.php:74
|
||||
msgid ""
|
||||
|
@ -429,13 +428,40 @@ msgstr "エラー! ファイル%sは削除されていません。"
|
|||
msgid "Error!: patches directory is not accessible."
|
||||
msgstr "エラー! パッチ・ディレクトリにアクセスできません。"
|
||||
|
||||
msgid "Unable to create a patch directory."
|
||||
msgstr "パッチ・ディレクトリを作成できませんでした。"
|
||||
|
||||
msgid "Unable to create a .htaccess file."
|
||||
msgstr ".htaccess ファイルを作成できませんでした。"
|
||||
|
||||
msgid "Invalid operation."
|
||||
msgstr "不正な操作です。"
|
||||
|
||||
msgid "File is too large to upload."
|
||||
msgstr "ファイルサイズが制限を越えています。"
|
||||
|
||||
msgid "File upload is not complete."
|
||||
msgstr "ファイルアップロードは完了しませんでした。"
|
||||
|
||||
msgid "File is not uploaded."
|
||||
msgstr "ファイルはアップロードされませんでした。"
|
||||
|
||||
msgid "Temporary directory is not writable."
|
||||
msgstr "テンポラリ・ディレクトリに書込みできません。"
|
||||
|
||||
msgid "File cannot be written on the disk."
|
||||
msgstr "ファイルをディスクに書き込めません。"
|
||||
|
||||
msgid "Unknown error."
|
||||
msgstr "不明なエラーです。"
|
||||
|
||||
#: utilities/patch.php:142
|
||||
msgid "File is uploaded"
|
||||
msgid "File is successfully uploaded."
|
||||
msgstr "ファイルをアップロードしました"
|
||||
|
||||
#: utilities/patch.php:146
|
||||
msgid "File is not uploaded"
|
||||
msgstr "ファイルはアップロードされていません"
|
||||
msgid "File upload failed. Possible file upload attack."
|
||||
msgstr "アップロードに失敗しました。不正なファイルです。"
|
||||
|
||||
#: utilities/patch.php:150
|
||||
msgid "File is not selected"
|
||||
|
@ -630,9 +656,11 @@ msgstr "ファイルを選択"
|
|||
#: utilities/patch.php:286
|
||||
msgid ""
|
||||
"Select file from your computer. If the file name is the same as existent "
|
||||
"file, this operation will override it."
|
||||
"file, this operation will override it. You can't upload the file whose "
|
||||
"size is over 500kB."
|
||||
msgstr ""
|
||||
"あなたのコンピュータにあるファイルを選択します。ファイル名がすでに存在する場合は、それを上書きします。"
|
||||
"500kB を越えるサイズのファイルはアップロードできません。"
|
||||
|
||||
#: utilities/patch.php:288
|
||||
msgid "Upload"
|
||||
|
@ -705,6 +733,16 @@ msgstr "たぶん可"
|
|||
msgid "Checked"
|
||||
msgstr "チェック済"
|
||||
|
||||
msgid "Checked*"
|
||||
msgstr "チェック済*"
|
||||
|
||||
msgid ""
|
||||
"\"Checked*\" with an asterisk is from the users' information. "
|
||||
"I didn't check myself yet. If you found any malfunctioning, please let me know."
|
||||
msgstr ""
|
||||
"「チェック済*」のようにアステリスクのついたものは、ユーザからの情報にもとづいたものです。"
|
||||
"私自身はチェックしていません。もし、不具合があるようでしたら、お知らせください。"
|
||||
|
||||
#: utilities/utility.php:257 utilities/utility.php:263
|
||||
msgid "Not Checked"
|
||||
msgstr "未確認"
|
||||
|
@ -968,12 +1006,18 @@ msgstr "データベースの最適化、エラーログ、初期化ファイル
|
|||
|
||||
#: utilities/utility.php:695
|
||||
msgid "Please select backup file(s)."
|
||||
msgstr "データベースを最適化する"
|
||||
msgstr "バックアップファイルを選択してください。"
|
||||
|
||||
#: utilities/utility.php:704
|
||||
msgid "Error! Please remove file(s) manyally."
|
||||
msgstr "エラー! 手動でファイルを削除してください。"
|
||||
|
||||
msgid "Please select backup file."
|
||||
msgstr "バックアップファイルを選択してください。"
|
||||
|
||||
msgid "Please select one file at a time."
|
||||
msgstr "複数ファイルは選択できません。"
|
||||
|
||||
#: utilities/utility.php:718
|
||||
msgid "Database Optimization, Error Log, Init File"
|
||||
msgstr "データベース最適化、エラー・ログ、初期化ファイル"
|
||||
|
@ -1025,9 +1069,16 @@ msgid ""
|
|||
msgstr ""
|
||||
"バックアップファイルを削除したい場合は、ファイルをチェックして削除ボタンをクリックしてください。複数ファイルを選択できます。"
|
||||
|
||||
msgid ""
|
||||
"If you want to download a file, check the file name and click the Download button."
|
||||
" Please check one file at a time."
|
||||
msgstr ""
|
||||
"バックアップファイルをダウンロードしたい場合は、ファイルをチェックしてダウンロードボタンをクリックしてください。"
|
||||
"1ファイルのみ選択できます。"
|
||||
|
||||
#: utilities/utility.php:748
|
||||
msgid "Delete"
|
||||
msgstr "削除"
|
||||
msgid "Delete/Download"
|
||||
msgstr "削除/ダウンロード"
|
||||
|
||||
#: utilities/utility.php:749
|
||||
msgid "Backup Files"
|
||||
|
@ -1051,6 +1102,11 @@ msgid ""
|
|||
msgstr ""
|
||||
"バックアップファイルを削除します。\\n\\n中止する場合は[Cancel]を、続ける場合は[OK]をクリックしてください。"
|
||||
|
||||
msgid ""
|
||||
"Are you sure to download backup file?\\n\\nClick [Cancel] to stop, [OK] to continue."
|
||||
msgstr ""
|
||||
"バックアップファイルをダウンロードします。\\n\\n中止する場合は[Cancel]を、続ける場合は[OK]をクリックしてください。"
|
||||
|
||||
#: utilities/utility.php:768
|
||||
msgid "SQLite Integration Error Log"
|
||||
msgstr "SQLite Integrationのエラーログ"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -149,7 +149,22 @@ class PDODB extends wpdb {
|
|||
</div>";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to flush cached data.
|
||||
*
|
||||
* This overrides wpdb::flush(). This is not necessarily overridden, because
|
||||
* $result will never be resource.
|
||||
*
|
||||
* @see wpdb::flush
|
||||
*/
|
||||
function flush() {
|
||||
$this->last_result = array();
|
||||
$this->col_info = null;
|
||||
$this->last_query = null;
|
||||
$this->rows_affected = $this->num_rows = 0;
|
||||
$this->last_error = '';
|
||||
$this->result = null;
|
||||
}
|
||||
/**
|
||||
* Method to do the database connection.
|
||||
*
|
||||
|
@ -234,8 +249,9 @@ class PDODB extends wpdb {
|
|||
* This overrides wpdb::load_col_info(), which uses a mysql function.
|
||||
*
|
||||
* @see wpdb::load_col_info()
|
||||
* @access protected
|
||||
*/
|
||||
function load_col_info() {
|
||||
protected function load_col_info() {
|
||||
if ($this->col_info)
|
||||
return;
|
||||
$this->col_info = $this->dbh->get_columns();
|
||||
|
@ -266,13 +282,14 @@ class PDODB extends wpdb {
|
|||
*
|
||||
* This overrides wpdb::db_version() to avoid using MySQL function.
|
||||
* It returns mysql version number, but it means nothing for SQLite.
|
||||
* So it return the required mysql version.
|
||||
* So it return the newest mysql version.
|
||||
*
|
||||
* @see wpdb::db_version()
|
||||
*/
|
||||
function db_version() {
|
||||
global $required_mysql_version;
|
||||
return $required_mysql_version;
|
||||
// global $required_mysql_version;
|
||||
// return $required_mysql_version;
|
||||
return '5.5';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,18 +110,44 @@ class PDOEngine extends PDO {
|
|||
*/
|
||||
private $affected_rows;
|
||||
/**
|
||||
* Class variable to store the queried column names.
|
||||
* Class variable to store the queried column info.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $column_names;
|
||||
private $column_data;
|
||||
/**
|
||||
* Variable to emulate MySQL affected row.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $num_rows;
|
||||
/**
|
||||
* Return value from query().
|
||||
*
|
||||
* Each query has its own return value.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $return_value;
|
||||
/**
|
||||
* Variable to determine which insert query to use.
|
||||
*
|
||||
* Whether VALUES clause in the INSERT query can take multiple values or not
|
||||
* depends on the version of SQLite library. We check the version and set
|
||||
* this varable to true or false.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $can_insert_multiple_rows = false;
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $param_num;
|
||||
/**
|
||||
* Varible to check if there is an active transaction.
|
||||
* @var boolean
|
||||
* @access protected
|
||||
*/
|
||||
protected $has_active_transaction = false;
|
||||
|
||||
|
@ -144,7 +170,7 @@ class PDOEngine extends PDO {
|
|||
}
|
||||
|
||||
/**
|
||||
* Function to initialize database.
|
||||
* Function to initialize database, executed in the contructor.
|
||||
*
|
||||
* It checks if there's a database directory and database file, creates the tables,
|
||||
* and binds the user defined function to the pdo object.
|
||||
|
@ -152,7 +178,7 @@ class PDOEngine extends PDO {
|
|||
* @return boolean
|
||||
*/
|
||||
private function init() {
|
||||
$dsn = 'sqlite:' . FQDB;
|
||||
$dsn = 'sqlite:' . FQDB;
|
||||
$result = $this->prepare_directory();
|
||||
if (!$result) return false;
|
||||
if (is_file(FQDB)) {
|
||||
|
@ -167,9 +193,9 @@ class PDOEngine extends PDO {
|
|||
array( // PDO options
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
));
|
||||
$statement = $this->pdo->query("SELECT COUNT(*) FROM sqlite_master WHERE type='table'");
|
||||
$statement = $this->pdo->query("SELECT COUNT(*) FROM sqlite_master WHERE type='table'");
|
||||
$number_of_tables = $statement->fetchColumn(0);
|
||||
$statement = null;
|
||||
$statement = null;
|
||||
if ($number_of_tables == 0) {
|
||||
$this->make_sqlite_tables();
|
||||
}
|
||||
|
@ -180,7 +206,7 @@ class PDOEngine extends PDO {
|
|||
if ($status == 5 || $status == 6) {
|
||||
$locked = true;
|
||||
} else {
|
||||
$message = 'Database connection error!<br />';
|
||||
$message = 'Database connection error!<br />';
|
||||
$message .= sprintf("Error message is: %s", $err->getMessage());
|
||||
$this->set_error(__LINE__, __FUNCTION__, $message);
|
||||
return false;
|
||||
|
@ -196,7 +222,7 @@ class PDOEngine extends PDO {
|
|||
try {
|
||||
$this->pdo = new PDO($dsn, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
|
||||
} catch (PDOException $err) {
|
||||
$message = 'Database initialization error!<br />';
|
||||
$message = 'Database initialization error!<br />';
|
||||
$message .= sprintf("Error message is: %s", $err->getMessage());
|
||||
$this->set_error(__LINE__, __FUNCTION__, $message);
|
||||
return false;
|
||||
|
@ -259,7 +285,7 @@ class PDOEngine extends PDO {
|
|||
public function query($query) {
|
||||
$this->flush();
|
||||
|
||||
$this->queries[] = "Raw query:\t$query";
|
||||
$this->queries[] = "Raw query:\n$query";
|
||||
$res = $this->determine_query_type($query);
|
||||
if (!$res) {
|
||||
$bailoutString = sprintf(__("<h1>Unknown query type</h1><p>Sorry, we cannot determine the type of query that is requested.</p><p>The query is %s</p>", 'sqlite-integration'), $query);
|
||||
|
@ -268,14 +294,14 @@ class PDOEngine extends PDO {
|
|||
switch (strtolower($this->query_type)) {
|
||||
case 'foundrows':
|
||||
$_column = array('FOUND_ROWS()' => '');
|
||||
$column = array();
|
||||
$column = array();
|
||||
if (!is_null($this->found_rows_result)) {
|
||||
$this->num_rows = count($this->found_rows_result);
|
||||
foreach ($this->found_rows_result[0] as $key => $value) {
|
||||
$_column['FOUND_ROWS()'] = $value;
|
||||
}
|
||||
$column[] = new ObjectArray($_column);
|
||||
$this->results = $column;
|
||||
$column[] = new ObjectArray($_column);
|
||||
$this->results = $column;
|
||||
$this->found_rows_result = null;
|
||||
}
|
||||
break;
|
||||
|
@ -300,9 +326,9 @@ class PDOEngine extends PDO {
|
|||
case 'drop_index':
|
||||
$pattern = '/^\\s*(DROP\\s*INDEX\\s*.*?)\\s*ON\\s*(.*)/im';
|
||||
if (preg_match($pattern, $query, $match)) {
|
||||
$drop_query = 'ALTER TABLE ' . trim($match[2]) . ' ' . trim($match[1]);
|
||||
$this->query_type = 'alter';
|
||||
$result = $this->execute_alter_query($drop_query);
|
||||
$drop_query = 'ALTER TABLE ' . trim($match[2]) . ' ' . trim($match[1]);
|
||||
$this->query_type = 'alter';
|
||||
$result = $this->execute_alter_query($drop_query);
|
||||
$this->return_value = $result;
|
||||
} else {
|
||||
$this->return_value = false;
|
||||
|
@ -311,7 +337,7 @@ class PDOEngine extends PDO {
|
|||
default:
|
||||
$engine = $this->prepare_engine($this->query_type);
|
||||
$this->rewritten_query = $engine->rewrite_query($query, $this->query_type);
|
||||
$this->queries[] = "Rewritten: $this->rewritten_query";
|
||||
$this->queries[] = "Rewritten:\n$this->rewritten_query";
|
||||
$this->extract_variables();
|
||||
$statement = $this->prepare_query();
|
||||
$this->execute_query($statement);
|
||||
|
@ -346,10 +372,58 @@ class PDOEngine extends PDO {
|
|||
/**
|
||||
* Function to return the queried column names.
|
||||
*
|
||||
* @return string
|
||||
* These data are meaningless for SQLite. So they are dummy emulating
|
||||
* MySQL columns data.
|
||||
*
|
||||
* @return array of the object
|
||||
*/
|
||||
public function get_columns() {
|
||||
return $this->column_names;
|
||||
if (!empty($this->results)) {
|
||||
$primary_key = array(
|
||||
'meta_id', 'comment_ID', 'link_ID', 'option_id',
|
||||
'blog_id', 'option_name', 'ID', 'term_id', 'object_id',
|
||||
'term_taxonomy_id', 'umeta_id', 'id');
|
||||
$unique_key = array('term_id', 'taxonomy', 'slug');
|
||||
$data = array(
|
||||
'name' => '', // column name
|
||||
'table' => '', // table name
|
||||
'max_length' => 0, // max length of the column
|
||||
'not_null' => 1, // 1 if not null
|
||||
'primary_key' => 0, // 1 if column has primary key
|
||||
'unique_key' => 0, // 1 if column has unique key
|
||||
'multiple_key' => 0, // 1 if column doesn't have unique key
|
||||
'numeric' => 0, // 1 if column has numeric value
|
||||
'blob' => 0, // 1 if column is blob
|
||||
'type' => '', // type of the column
|
||||
'unsigned' => 0, // 1 if column is unsigned integer
|
||||
'zerofill' => 0 // 1 if column is zero-filled
|
||||
);
|
||||
if (preg_match("/\s*FROM\s*(.*)?\s*/i", $this->rewritten_query, $match)) {
|
||||
$table_name = trim($match[1]);
|
||||
} else {
|
||||
$table_name = '';
|
||||
}
|
||||
foreach ($this->results[0] as $key => $value) {
|
||||
$data['name'] = $key;
|
||||
$data['table'] = $table_name;
|
||||
if (in_array($key, $primary_key)) {
|
||||
$data['primary_key'] = 1;
|
||||
} elseif (in_array($key, $unique_key)) {
|
||||
$data['unique_key'] = 1;
|
||||
} else {
|
||||
$data['multiple_key'] = 1;
|
||||
}
|
||||
$this->column_data[] = new ObjectArray($data);
|
||||
$data['name'] = '';
|
||||
$data['table'] = '';
|
||||
$data['primary_key'] = 0;
|
||||
$data['unique_key'] = 0;
|
||||
$data['multiple_key'] = 0;
|
||||
}
|
||||
return $this->column_data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Function to return the queried result data.
|
||||
|
@ -382,7 +456,7 @@ class PDOEngine extends PDO {
|
|||
*/
|
||||
public function get_error_message(){
|
||||
if (count($this->error_messages) === 0){
|
||||
$this->is_error = false;
|
||||
$this->is_error = false;
|
||||
$this->error_messages = array();
|
||||
return '';
|
||||
}
|
||||
|
@ -429,7 +503,7 @@ class PDOEngine extends PDO {
|
|||
$this->_results = null;
|
||||
$this->last_insert_id = null;
|
||||
$this->affected_rows = null;
|
||||
$this->column_names = array();
|
||||
$this->column_data = array();
|
||||
$this->num_rows = null;
|
||||
$this->return_value = null;
|
||||
$this->extracted_variables = array();
|
||||
|
@ -466,15 +540,15 @@ class PDOEngine extends PDO {
|
|||
* @return PDOStatement
|
||||
*/
|
||||
private function prepare_query(){
|
||||
$this->queries[] = 'Prepare: ' . $this->prepared_query;
|
||||
$reason = 0;
|
||||
$message = '';
|
||||
$statement = null;
|
||||
$this->queries[] = "Prepare:\n" . $this->prepared_query;
|
||||
$reason = 0;
|
||||
$message = '';
|
||||
$statement = null;
|
||||
do {
|
||||
try {
|
||||
$statement = $this->pdo->prepare($this->prepared_query);
|
||||
} catch (PDOException $err) {
|
||||
$reason = $err->getCode();
|
||||
$reason = $err->getCode();
|
||||
$message = $err->getMessage();
|
||||
}
|
||||
} while (5 == $reason || 6 == $reason);
|
||||
|
@ -496,12 +570,12 @@ class PDOEngine extends PDO {
|
|||
* @return boolean
|
||||
*/
|
||||
private function execute_query($statement) {
|
||||
$reason = 0;
|
||||
$reason = 0;
|
||||
$message = '';
|
||||
if (!is_object($statement))
|
||||
return false;
|
||||
if (count($this->extracted_variables) > 0) {
|
||||
$this->queries[] = 'Executing: ' . var_export($this->extracted_variables, true);
|
||||
$this->queries[] = "Executing:\n" . var_export($this->extracted_variables, true);
|
||||
do {
|
||||
if ($this->query_type == 'update' || $this->query_type == 'replace') {
|
||||
try {
|
||||
|
@ -509,7 +583,7 @@ class PDOEngine extends PDO {
|
|||
$statement->execute($this->extracted_variables);
|
||||
$this->commit();
|
||||
} catch (PDOException $err) {
|
||||
$reason = $err->getCode();
|
||||
$reason = $err->getCode();
|
||||
$message = $err->getMessage();
|
||||
$this->rollBack();
|
||||
}
|
||||
|
@ -517,7 +591,7 @@ class PDOEngine extends PDO {
|
|||
try {
|
||||
$statement->execute($this->extracted_variables);
|
||||
} catch (PDOException $err) {
|
||||
$reason = $err->getCode();
|
||||
$reason = $err->getCode();
|
||||
$message = $err->getMessage();
|
||||
}
|
||||
}
|
||||
|
@ -531,7 +605,7 @@ class PDOEngine extends PDO {
|
|||
$statement->execute();
|
||||
$this->commit();
|
||||
} catch (PDOException $err) {
|
||||
$reason = $err->getCode();
|
||||
$reason = $err->getCode();
|
||||
$message = $err->getMessage();
|
||||
$this->rollBack();
|
||||
}
|
||||
|
@ -539,7 +613,7 @@ class PDOEngine extends PDO {
|
|||
try {
|
||||
$statement->execute();
|
||||
} catch (PDOException $err) {
|
||||
$reason = $err->getCode();
|
||||
$reason = $err->getCode();
|
||||
$message = $err->getMessage();
|
||||
}
|
||||
}
|
||||
|
@ -558,8 +632,8 @@ class PDOEngine extends PDO {
|
|||
case 'update':
|
||||
case 'replace':
|
||||
$this->last_insert_id = $this->pdo->lastInsertId();
|
||||
$this->affected_rows = $statement->rowCount();
|
||||
$this->return_value = $this->affected_rows;
|
||||
$this->affected_rows = $statement->rowCount();
|
||||
$this->return_value = $this->affected_rows;
|
||||
break;
|
||||
case 'select':
|
||||
case 'show':
|
||||
|
@ -570,12 +644,12 @@ class PDOEngine extends PDO {
|
|||
case 'check':
|
||||
case 'analyze':
|
||||
// case "foundrows":
|
||||
$this->num_rows = count($this->_results);
|
||||
$this->num_rows = count($this->_results);
|
||||
$this->return_value = $this->num_rows;
|
||||
break;
|
||||
case 'delete':
|
||||
$this->affected_rows = $statement->rowCount();
|
||||
$this->return_value = $this->affected_rows;
|
||||
$this->return_value = $this->affected_rows;
|
||||
break;
|
||||
case 'alter':
|
||||
case 'drop':
|
||||
|
@ -606,7 +680,7 @@ class PDOEngine extends PDO {
|
|||
|
||||
//long queries can really kill this
|
||||
$pattern = '/(?<!\\\\)([\'"])(.*?)(?<!\\\\)\\1/imsx';
|
||||
$_limit = $limit = ini_get('pcre.backtrack_limit');
|
||||
$_limit = $limit = ini_get('pcre.backtrack_limit');
|
||||
do {
|
||||
if ($limit > 10000000) {
|
||||
$message = 'The query is too big to parse properly';
|
||||
|
@ -621,7 +695,7 @@ class PDOEngine extends PDO {
|
|||
|
||||
//reset the pcre.backtrack_limist
|
||||
ini_set('pcre.backtrack_limit', $_limit);
|
||||
$this->queries[]= 'With Placeholders: ' . $query;
|
||||
$this->queries[] = "With Placeholders:\n" . $query;
|
||||
$this->prepared_query = $query;
|
||||
}
|
||||
/**
|
||||
|
@ -699,11 +773,11 @@ class PDOEngine extends PDO {
|
|||
* @param string $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->queries[] = 'Rewritten: ' . $this->rewritten_query;
|
||||
$this->queries[] = "Rewritten:\n" . $this->rewritten_query;
|
||||
$this->extract_variables();
|
||||
$statement = $this->prepare_query();
|
||||
$statement = $this->prepare_query();
|
||||
$this->execute_query($statement);
|
||||
}
|
||||
/**
|
||||
|
@ -717,11 +791,11 @@ class PDOEngine extends PDO {
|
|||
private function execute_insert_query($query) {
|
||||
global $wpdb;
|
||||
$multi_insert = false;
|
||||
$statement = null;
|
||||
$engine = $this->prepare_engine($this->query_type);
|
||||
$statement = null;
|
||||
$engine = $this->prepare_engine($this->query_type);
|
||||
if (preg_match('/(INSERT.*?VALUES\\s*)(\(.*\))/imsx', $query, $matched)) {
|
||||
$query_prefix = $matched[1];
|
||||
$values_data = $matched[2];
|
||||
$values_data = $matched[2];
|
||||
if (stripos($values_data, 'ON DUPLICATE KEY') !== false) {
|
||||
$exploded_parts = $values_data;
|
||||
} elseif (stripos($query_prefix, "INSERT INTO $wpdb->comments") !== false) {
|
||||
|
@ -742,9 +816,9 @@ class PDOEngine extends PDO {
|
|||
} else {
|
||||
$suffix = ')';
|
||||
}
|
||||
$query_string = $query_prefix . ' ' . $value . $suffix;
|
||||
$this->rewritten_query = $engine->rewrite_query($query_string, $this->query_type);
|
||||
$this->queries[] = 'Rewritten: ' . $this->rewritten_query;
|
||||
$query_string = $query_prefix . ' ' . $value . $suffix;
|
||||
$this->rewritten_query = $engine->rewrite_query($query_string, $this->query_type);
|
||||
$this->queries[] = "Rewritten:\n" . $this->rewritten_query;
|
||||
$this->extracted_variables = array();
|
||||
$this->extract_variables();
|
||||
if ($first) {
|
||||
|
@ -757,7 +831,7 @@ class PDOEngine extends PDO {
|
|||
}
|
||||
} else {
|
||||
$this->rewritten_query = $engine->rewrite_query($query, $this->query_type);
|
||||
$this->queries[] = 'Rewritten: ' . $this->rewritten_query;
|
||||
$this->queries[] = "Rewritten:\n" . $this->rewritten_query;
|
||||
$this->extract_variables();
|
||||
$statement = $this->prepare_query();
|
||||
$this->execute_query($statement);
|
||||
|
@ -813,22 +887,22 @@ class PDOEngine extends PDO {
|
|||
* @return boolean
|
||||
*/
|
||||
private function execute_create_query($query) {
|
||||
$engine = $this->prepare_engine($this->query_type);
|
||||
$engine = $this->prepare_engine($this->query_type);
|
||||
$rewritten_query = $engine->rewrite_query($query);
|
||||
$reason = 0;
|
||||
$message = '';
|
||||
$reason = 0;
|
||||
$message = '';
|
||||
// $queries = explode(";", $this->rewritten_query);
|
||||
try {
|
||||
$this->beginTransaction();
|
||||
foreach ($rewritten_query as $single_query) {
|
||||
$this->queries[] = "Executing:\t" . $single_query;
|
||||
$single_query = trim($single_query);
|
||||
$this->queries[] = "Executing:\n" . $single_query;
|
||||
$single_query = trim($single_query);
|
||||
if (empty($single_query)) continue;
|
||||
$this->pdo->exec($single_query);
|
||||
}
|
||||
$this->commit();
|
||||
} catch (PDOException $err) {
|
||||
$reason = $err->getCode();
|
||||
$reason = $err->getCode();
|
||||
$message = $err->getMessage();
|
||||
if (5 == $reason || 6 == $reason) {
|
||||
$this->commit();
|
||||
|
@ -850,10 +924,10 @@ class PDOEngine extends PDO {
|
|||
* @return boolean
|
||||
*/
|
||||
private function execute_alter_query($query) {
|
||||
$engine = $this->prepare_engine($this->query_type);
|
||||
$reason = 0;
|
||||
$message = '';
|
||||
$re_query = '';
|
||||
$engine = $this->prepare_engine($this->query_type);
|
||||
$reason = 0;
|
||||
$message = '';
|
||||
$re_query = '';
|
||||
$rewritten_query = $engine->rewrite_query($query, $this->query_type);
|
||||
if (is_array($rewritten_query) && array_key_exists('recursion', $rewritten_query)) {
|
||||
$re_query = $rewritten_query['recursion'];
|
||||
|
@ -863,19 +937,19 @@ class PDOEngine extends PDO {
|
|||
$this->beginTransaction();
|
||||
if (is_array($rewritten_query)) {
|
||||
foreach ($rewritten_query as $single_query) {
|
||||
$this->queries[] = "Executing:\t" . $single_query;
|
||||
$single_query = trim($single_query);
|
||||
$this->queries[] = "Executing:\n" . $single_query;
|
||||
$single_query = trim($single_query);
|
||||
if (empty($single_query)) continue;
|
||||
$this->pdo->exec($single_query);
|
||||
}
|
||||
} else {
|
||||
$this->queries[] = "Executing:\t" . $rewritten_query;
|
||||
$this->queries[] = "Executing:\n" . $rewritten_query;
|
||||
$rewritten_query = trim($rewritten_query);
|
||||
$this->pdo->exec($rewritten_query);
|
||||
}
|
||||
$this->commit();
|
||||
} catch (PDOException $err) {
|
||||
$reason = $err->getCode();
|
||||
$reason = $err->getCode();
|
||||
$message = $err->getMessage();
|
||||
if (5 == $reason || 6 == $reason) {
|
||||
$this->commit();
|
||||
|
@ -906,7 +980,7 @@ class PDOEngine extends PDO {
|
|||
*/
|
||||
private function show_variables_workaround($query) {
|
||||
$dummy_data = array('Variable_name' => '', 'Value' => null);
|
||||
$pattern = '/SHOW\\s*VARIABLES\\s*LIKE\\s*(.*)?$/im';
|
||||
$pattern = '/SHOW\\s*VARIABLES\\s*LIKE\\s*(.*)?$/im';
|
||||
if (preg_match($pattern, $query, $match)) {
|
||||
$value = str_replace("'", '', $match[1]);
|
||||
$dummy_data['Variable_name'] = trim($value);
|
||||
|
@ -917,9 +991,9 @@ class PDOEngine extends PDO {
|
|||
$dummy_data['Value'] = '';
|
||||
}
|
||||
}
|
||||
$_results[] = new ObjectArray($dummy_data);
|
||||
$this->results = $_results;
|
||||
$this->num_rows = count($this->results);
|
||||
$_results[] = new ObjectArray($dummy_data);
|
||||
$this->results = $_results;
|
||||
$this->num_rows = count($this->results);
|
||||
$this->return_value = $this->num_rows;
|
||||
return true;
|
||||
}
|
||||
|
@ -952,9 +1026,9 @@ class PDOEngine extends PDO {
|
|||
*/
|
||||
private function set_error ($line, $function, $message){
|
||||
global $wpdb;
|
||||
$this->errors[] = array("line"=>$line, "function"=>$function);
|
||||
$this->errors[] = array("line"=>$line, "function"=>$function);
|
||||
$this->error_messages[] = $message;
|
||||
$this->is_error = true;
|
||||
$this->is_error = true;
|
||||
if ($wpdb->suppress_errors) return false;
|
||||
if (!$wpdb->show_errors) return false;
|
||||
file_put_contents (FQDBDIR .'debug.txt', "Line $line, Function: $function, Message: $message \n", FILE_APPEND);
|
||||
|
@ -1005,7 +1079,7 @@ class PDOEngine extends PDO {
|
|||
$_columns['Null'] = $row->notnull ? "NO" : "YES";
|
||||
$_columns['Key'] = $row->pk ? "PRI" : "";
|
||||
$_columns['Default'] = $row->dflt_value;
|
||||
$_results[] = new ObjectArray($_columns);
|
||||
$_results[] = new ObjectArray($_columns);
|
||||
}
|
||||
}
|
||||
$this->results = $_results;
|
||||
|
@ -1081,7 +1155,7 @@ class PDOEngine extends PDO {
|
|||
$_columns['Null'] = 'NO';
|
||||
$_columns['Index_type'] = 'BTREE';
|
||||
$_columns['Comment'] = '';
|
||||
$_results[] = new ObjectArray($_columns);
|
||||
$_results[] = new ObjectArray($_columns);
|
||||
}
|
||||
if (stripos($this->queries[0], 'WHERE') !== false) {
|
||||
preg_match('/WHERE\\s*(.*)$/im', $this->queries[0], $match);
|
||||
|
@ -1122,7 +1196,7 @@ class PDOEngine extends PDO {
|
|||
'Msg_text' => 'Table is already up to date'
|
||||
);
|
||||
}
|
||||
$_results[] = new ObjectArray($_columns);
|
||||
$_results[] = new ObjectArray($_columns);
|
||||
$this->results = $_results;
|
||||
}
|
||||
/**
|
||||
|
|
187
query.class.php
187
query.class.php
|
@ -37,68 +37,68 @@ class PDOSQLiteDriver {
|
|||
$this->_query = $query;
|
||||
switch ($this->query_type) {
|
||||
case 'truncate':
|
||||
$this->_handle_truncate_query();
|
||||
$this->handle_truncate_query();
|
||||
break;
|
||||
case 'alter':
|
||||
$this->_handle_alter_query();
|
||||
$this->handle_alter_query();
|
||||
break;
|
||||
case 'create':
|
||||
$this->_handle_create_query();
|
||||
$this->handle_create_query();
|
||||
break;
|
||||
case 'describe':
|
||||
case 'desc':
|
||||
$this->_handle_describe_query();
|
||||
$this->handle_describe_query();
|
||||
break;
|
||||
case 'show':
|
||||
$this->_handle_show_query();
|
||||
$this->handle_show_query();
|
||||
break;
|
||||
case 'showcolumns':
|
||||
$this->_handle_show_columns_query();
|
||||
$this->handle_show_columns_query();
|
||||
break;
|
||||
case 'showindex':
|
||||
$this->_handle_show_index();
|
||||
$this->handle_show_index();
|
||||
break;
|
||||
case 'select':
|
||||
$this->_strip_backticks();
|
||||
$this->_handle_sql_count();
|
||||
$this->_rewrite_date_sub();
|
||||
$this->_delete_index_hints();
|
||||
$this->_rewrite_regexp();
|
||||
$this->_rewrite_boolean();
|
||||
$this->_fix_date_quoting();
|
||||
$this->_rewrite_between();
|
||||
$this->strip_backticks();
|
||||
$this->handle_sql_count();
|
||||
$this->rewrite_date_sub();
|
||||
$this->delete_index_hints();
|
||||
$this->rewrite_regexp();
|
||||
$this->rewrite_boolean();
|
||||
$this->fix_date_quoting();
|
||||
$this->rewrite_between();
|
||||
break;
|
||||
case 'insert':
|
||||
$this->_safe_strip_backticks();
|
||||
$this->_execute_duplicate_key_update();
|
||||
$this->_rewrite_insert_ignore();
|
||||
$this->_rewrite_regexp();
|
||||
$this->_fix_date_quoting();
|
||||
$this->safe_strip_backticks();
|
||||
$this->execute_duplicate_key_update();
|
||||
$this->rewrite_insert_ignore();
|
||||
$this->rewrite_regexp();
|
||||
$this->fix_date_quoting();
|
||||
break;
|
||||
case 'update':
|
||||
$this->_safe_strip_backticks();
|
||||
$this->_rewrite_update_ignore();
|
||||
$this->safe_strip_backticks();
|
||||
$this->rewrite_update_ignore();
|
||||
// $this->_rewrite_date_sub();
|
||||
$this->_rewrite_limit_usage();
|
||||
$this->_rewrite_order_by_usage();
|
||||
$this->_rewrite_regexp();
|
||||
$this->_rewrite_between();
|
||||
$this->rewrite_limit_usage();
|
||||
$this->rewrite_order_by_usage();
|
||||
$this->rewrite_regexp();
|
||||
$this->rewrite_between();
|
||||
break;
|
||||
case 'delete':
|
||||
$this->_strip_backticks();
|
||||
$this->_rewrite_limit_usage();
|
||||
$this->_rewrite_order_by_usage();
|
||||
$this->_rewrite_date_sub();
|
||||
$this->_rewrite_regexp();
|
||||
$this->_delete_workaround();
|
||||
$this->strip_backticks();
|
||||
$this->rewrite_limit_usage();
|
||||
$this->rewrite_order_by_usage();
|
||||
$this->rewrite_date_sub();
|
||||
$this->rewrite_regexp();
|
||||
$this->delete_workaround();
|
||||
break;
|
||||
case 'replace':
|
||||
$this->_safe_strip_backticks();
|
||||
$this->_rewrite_date_sub();
|
||||
$this->_rewrite_regexp();
|
||||
$this->safe_strip_backticks();
|
||||
$this->rewrite_date_sub();
|
||||
$this->rewrite_regexp();
|
||||
break;
|
||||
case 'optimize':
|
||||
$this->_rewrite_optimize();
|
||||
$this->rewrite_optimize();
|
||||
break;
|
||||
case 'pragma':
|
||||
break;
|
||||
|
@ -106,7 +106,7 @@ class PDOSQLiteDriver {
|
|||
if (defined(WP_DEBUG) && WP_DEBUG) {
|
||||
break;
|
||||
} else {
|
||||
$this->_return_true();
|
||||
$this->return_true();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -118,9 +118,9 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _handle_show_query(){
|
||||
private function handle_show_query(){
|
||||
$table_name = '';
|
||||
$pattern = '/^\\s*SHOW\\s*TABLES\\s*.*?(LIKE\\s*(.*))$/im';
|
||||
$pattern = '/^\\s*SHOW\\s*TABLES\\s*.*?(LIKE\\s*(.*))$/im';
|
||||
if (preg_match($pattern, $this->_query, $matches)) {
|
||||
$table_name = str_replace(array("'", ';'), '', $matches[2]);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _strip_backticks(){
|
||||
private function strip_backticks(){
|
||||
$this->_query = str_replace('`', '', $this->_query);
|
||||
}
|
||||
/**
|
||||
|
@ -150,10 +150,10 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _safe_strip_backticks() {
|
||||
private function safe_strip_backticks() {
|
||||
$query_string = '';
|
||||
$tokens = preg_split("/(''|')/s", $this->_query, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$literal = false;
|
||||
$tokens = preg_split("/(''|')/s", $this->_query, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$literal = false;
|
||||
$query_string = '';
|
||||
foreach ($tokens as $token) {
|
||||
if ($token == "'") {
|
||||
|
@ -188,16 +188,15 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _handle_sql_count(){
|
||||
private function handle_sql_count(){
|
||||
if (stripos($this->_query, 'SELECT SQL_CALC_FOUND_ROWS') !== false){
|
||||
global $wpdb;
|
||||
// first strip the code. this is the end of rewriting process
|
||||
$this->_query = str_ireplace('SQL_CALC_FOUND_ROWS', '', $this->_query);
|
||||
$this->_query = str_ireplace('SQL_CALC_FOUND_ROWS', '', $this->_query);
|
||||
// we make the data for next SELECE FOUND_ROWS() statement
|
||||
$unlimited_query = preg_replace('/\\bLIMIT\\s*.*/imsx', '', $this->_query);
|
||||
// $unlimited_query = preg_replace('/\\bFALSE\\s*.*/imsx', '0', $unlimited_query);
|
||||
$unlimited_query = preg_replace('/\\bGROUP\\s*BY\\s*.*/imsx', '', $unlimited_query);
|
||||
$unlimited_query = $this->__transform_to_count($unlimited_query);
|
||||
$unlimited_query = $this->_transform_to_count($unlimited_query);
|
||||
$_wpdb = new PDODB();
|
||||
$result = $_wpdb->query($unlimited_query);
|
||||
$wpdb->dbh->found_rows_result = $_wpdb->last_result;
|
||||
|
@ -213,7 +212,7 @@ class PDOSQLiteDriver {
|
|||
* @return string the transformed query
|
||||
* @access private
|
||||
*/
|
||||
private function __transform_to_count($query){
|
||||
private function _transform_to_count($query){
|
||||
$pattern = '/^\\s*SELECT\\s*(DISTINCT|)?.*?FROM\b/isx';
|
||||
$_query = preg_replace($pattern, 'SELECT \\1 COUNT(*) FROM ', $query);
|
||||
return $_query;
|
||||
|
@ -223,7 +222,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_insert_ignore(){
|
||||
private function rewrite_insert_ignore(){
|
||||
$this->_query = str_ireplace('INSERT IGNORE', 'INSERT OR IGNORE ', $this->_query);
|
||||
}
|
||||
/**
|
||||
|
@ -231,7 +230,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_update_ignore(){
|
||||
private function rewrite_update_ignore(){
|
||||
$this->_query = str_ireplace('UPDATE IGNORE', 'UPDATE OR IGNORE ', $this->_query);
|
||||
}
|
||||
/**
|
||||
|
@ -242,11 +241,11 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_date_add(){
|
||||
private function rewrite_date_add(){
|
||||
//(date,interval expression unit)
|
||||
$pattern = '/\\s*date_add\\s*\(([^,]*),([^\)]*)\)/imsx';
|
||||
if (preg_match($pattern, $this->_query, $matches)) {
|
||||
$expression = "'".trim($matches[2])."'";
|
||||
$expression = "'".trim($matches[2])."'";
|
||||
$this->_query = preg_replace($pattern, " date_add($matches[1], $expression) ", $this->_query);
|
||||
}
|
||||
}
|
||||
|
@ -258,11 +257,11 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_date_sub(){
|
||||
private function rewrite_date_sub(){
|
||||
//(date,interval expression unit)
|
||||
$pattern = '/\\s*date_sub\\s*\(([^,]*),([^\)]*)\)/imsx';
|
||||
if (preg_match($pattern, $this->_query, $matches)) {
|
||||
$expression = "'".trim($matches[2])."'";
|
||||
$expression = "'".trim($matches[2])."'";
|
||||
$this->_query = preg_replace($pattern, " date_sub($matches[1], $expression) ", $this->_query);
|
||||
}
|
||||
}
|
||||
|
@ -274,7 +273,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _handle_create_query(){
|
||||
private function handle_create_query(){
|
||||
require_once PDODIR . 'query_create.class.php';
|
||||
$engine = new CreateQuery();
|
||||
$this->_query = $engine->rewrite_query($this->_query);
|
||||
|
@ -289,7 +288,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _handle_alter_query(){
|
||||
private function handle_alter_query(){
|
||||
require_once PDODIR . 'query_alter.class.php';
|
||||
$engine = new AlterQuery();
|
||||
$this->_query = $engine->rewrite_query($this->_query, 'alter');
|
||||
|
@ -304,7 +303,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _handle_describe_query(){
|
||||
private function handle_describe_query(){
|
||||
// $this->_query = "select 1=1";
|
||||
$pattern = '/^\\s*(DESCRIBE|DESC)\\s*(.*)/i';
|
||||
if (preg_match($pattern, $this->_query, $match)) {
|
||||
|
@ -323,7 +322,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_limit_usage(){
|
||||
private function rewrite_limit_usage(){
|
||||
$_wpdb = new PDODB();
|
||||
$options = $_wpdb->get_results('PRAGMA compile_options');
|
||||
foreach ($options as $opt) {
|
||||
|
@ -342,7 +341,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_order_by_usage() {
|
||||
private function rewrite_order_by_usage() {
|
||||
$_wpdb = new PDODB();
|
||||
$options = $_wpdb->get_results('PRAGMA compile_options');
|
||||
foreach ($options as $opt) {
|
||||
|
@ -357,7 +356,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _handle_truncate_query(){
|
||||
private function handle_truncate_query(){
|
||||
$pattern = '/TRUNCATE TABLE (.*)/im';
|
||||
$this->_query = preg_replace($pattern, 'DELETE FROM $1', $this->_query);
|
||||
}
|
||||
|
@ -369,7 +368,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_optimize(){
|
||||
private function rewrite_optimize(){
|
||||
$this->_query ="VACUUM";
|
||||
}
|
||||
/**
|
||||
|
@ -384,7 +383,7 @@ class PDOSQLiteDriver {
|
|||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_badly_formed_dates(){
|
||||
private function rewrite_badly_formed_dates(){
|
||||
$pattern = '/([12]\d{3,}-\d{2}-)(\d )/ims';
|
||||
$this->_query = preg_replace($pattern, '${1}0$2', $this->_query);
|
||||
}
|
||||
|
@ -394,7 +393,7 @@ class PDOSQLiteDriver {
|
|||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
private function _delete_index_hints(){
|
||||
private function delete_index_hints(){
|
||||
$pattern = '/\\s*(use|ignore|force)\\s+index\\s*\(.*?\)/i';
|
||||
$this->_query = preg_replace($pattern, '', $this->_query);
|
||||
}
|
||||
|
@ -412,9 +411,9 @@ class PDOSQLiteDriver {
|
|||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
private function _fix_date_quoting() {
|
||||
private function fix_date_quoting() {
|
||||
$pattern = '/(month|year|second|day|minute|hour|dayofmonth)\\s*\((.*?)\)\\s*=\\s*["\']?(\d{1,4})[\'"]?\\s*/im';
|
||||
$this->_query = preg_replace_callback($pattern, array($this, '__fix_date_quoting'), $this->_query);
|
||||
$this->_query = preg_replace_callback($pattern, array($this, '_fix_date_quoting'), $this->_query);
|
||||
}
|
||||
/**
|
||||
* Call back method to rewrite date string.
|
||||
|
@ -423,7 +422,7 @@ class PDOSQLiteDriver {
|
|||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
private function __fix_date_quoting($match) {
|
||||
private function _fix_date_quoting($match) {
|
||||
$fixed_val = "{$match[1]}({$match[2]})='" . intval($match[3]) . "' ";
|
||||
return $fixed_val;
|
||||
}
|
||||
|
@ -435,7 +434,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_regexp(){
|
||||
private function rewrite_regexp(){
|
||||
$pattern = '/\s([^\s]*)\s*regexp\s*(\'.*?\')/im';
|
||||
$this->_query = preg_replace($pattern, ' regexpp(\1, \2)', $this->_query);
|
||||
}
|
||||
|
@ -446,7 +445,7 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _rewrite_boolean() {
|
||||
private function rewrite_boolean() {
|
||||
$query = str_ireplace('TRUE', "1", $this->_query);
|
||||
$query = str_ireplace('FALSE', "0", $query);
|
||||
$this->_query = $query;
|
||||
|
@ -456,16 +455,16 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _handle_show_columns_query() {
|
||||
private function handle_show_columns_query() {
|
||||
$pattern_like = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?\\s*LIKE\\s*(.*)?/i';
|
||||
$pattern = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?/i';
|
||||
$pattern = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?/i';
|
||||
if (preg_match($pattern_like, $this->_query, $matches)) {
|
||||
$table_name = str_replace("'", "", trim($matches[2]));
|
||||
$column_name = str_replace("'", "", trim($matches[3]));
|
||||
$table_name = str_replace("'", "", trim($matches[2]));
|
||||
$column_name = str_replace("'", "", trim($matches[3]));
|
||||
$query_string = "SELECT sql FROM sqlite_master WHERE tbl_name='$table_name' AND sql LIKE '%$column_name%'";
|
||||
$this->_query = $query_string;
|
||||
} elseif (preg_match($pattern, $this->_query, $matches)) {
|
||||
$table_name = $matches[2];
|
||||
$table_name = $matches[2];
|
||||
$query_string = preg_replace($pattern, "PRAGMA table_info($table_name)", $this->_query);
|
||||
$this->_query = $query_string;
|
||||
}
|
||||
|
@ -477,11 +476,11 @@ class PDOSQLiteDriver {
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _handle_show_index() {
|
||||
private function handle_show_index() {
|
||||
$pattern = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?/im';
|
||||
if (preg_match($pattern, $this->_query, $match)) {
|
||||
$table_name = preg_replace("/[\';]/", '', $match[1]);
|
||||
$table_name = trim($table_name);
|
||||
$table_name = preg_replace("/[\';]/", '', $match[1]);
|
||||
$table_name = trim($table_name);
|
||||
$this->_query = "SELECT * FROM sqlite_master WHERE tbl_name='$table_name'";
|
||||
}
|
||||
}
|
||||
|
@ -494,8 +493,8 @@ class PDOSQLiteDriver {
|
|||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
private function _execute_duplicate_key_update() {
|
||||
$update = false;
|
||||
private function execute_duplicate_key_update() {
|
||||
$update = false;
|
||||
$unique_keys_for_cond = array();
|
||||
$unique_keys_for_check = array();
|
||||
$pattern = '/^\\s*INSERT\\s*INTO\\s*(\\w+)?\\s*(.*)\\s*ON\\s*DUPLICATE\\s*KEY\\s*UPDATE\\s*(.*)$/ims';
|
||||
|
|