* define('USE_MYSQL', true);
*
+ *
+ * If you want to use SQLite, the line below will do. Or simply removing the line will
+ * be enough.
+ *
+ *
+ * define('USE_MYSQL', false);
+ *
*/
if (defined('USE_MYSQL') && USE_MYSQL === true) return;
diff --git a/functions-5-2.php b/functions-5-2.php
index 5e2fe84..8d5f2a5 100644
--- a/functions-5-2.php
+++ b/functions-5-2.php
@@ -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';
}
}
?>
\ No newline at end of file
diff --git a/functions.php b/functions.php
index 58d8445..7dd6247 100644
--- a/functions.php
+++ b/functions.php
@@ -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';
}
}
?>
\ No newline at end of file
diff --git a/js/sqlite.js b/js/sqlite.js
index 5fc8ffe..40dc4ce 100644
--- a/js/sqlite.js
+++ b/js/sqlite.js
@@ -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($) {
diff --git a/languages/sqlite-integration-ja.mo b/languages/sqlite-integration-ja.mo
index 7ecb4fc..231a9be 100644
Binary files a/languages/sqlite-integration-ja.mo and b/languages/sqlite-integration-ja.mo differ
diff --git a/languages/sqlite-integration-ja.po b/languages/sqlite-integration-ja.po
index 3abc30a..ce3592a 100644
--- a/languages/sqlite-integration-ja.po
+++ b/languages/sqlite-integration-ja.po
@@ -129,12 +129,11 @@ msgstr "パッチ"
#: utilities/documentation.php:32
msgid ""
-"This is a brief documentation about this plugin. For more details, see also "
-"the Plugin "
-"Page."
+"This is a brief documentation about this plugin. For more details, see also the "
+"SQLite Integration page."
msgstr ""
"このプラグインについての短いドキュメントです。詳しくは、プラグインのページをご覧ください。"
+"sqlite-integration/\">SQLite Integration のページをご覧ください。"
#: 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 Patch Utility. See also the SQLite Integration page for "
-"more details."
+"\"http://dogwood.skr.jp/wordpress/sqlite-integration/#plugin-compat\">SQLite Integration"
+" Page for more details."
msgstr ""
"MySQLの関数を書き換えると動作するプラグインがあります。いくつかはパッチファイルと、"
-"パッチをあてるページを作りました。"
-"プラグインのページもご覧ください。"
+"パッチをあてるページを作りました。"
+"SQLite Integration のページもご覧ください。"
#: 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のエラーログ"
diff --git a/languages/sqlite-integration.pot b/languages/sqlite-integration.pot
index 5e229dd..3345b1c 100644
--- a/languages/sqlite-integration.pot
+++ b/languages/sqlite-integration.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-09-03 14:31+0900\n"
+"POT-Creation-Date: 2014-02-06 01:39+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME We have been unable to "
"connect to the specified database.
The error message received was %s"
msgstr ""
-#: trunk/pdoengine.class.php:82 trunk/pdoengine.class.php:98
-msgid "Database connection error!
"
-msgstr ""
-
-#: trunk/pdoengine.class.php:83 trunk/pdoengine.class.php:99
-#, php-format
-msgid "Error message is: %s"
-msgstr ""
-
-#: trunk/pdoengine.class.php:156
+#: pdoengine.class.php:291
#, php-format
msgid ""
"
Sorry, we cannot determine the type of query " "that is requested.
The query is %s
" msgstr "" -#: trunk/pdoengine.class.php:315 -#, php-format -msgid "Problem preparing the PDO SQL Statement. Error was: %s" -msgstr "" - -#: trunk/pdoengine.class.php:372 -#, php-format -msgid "Error while executing query! Error message was: %s" -msgstr "" - -#: trunk/pdoengine.class.php:426 -msgid "The query is too big to parse properly" -msgstr "" - -#: trunk/pdoengine.class.php:635 -#, php-format -msgid "Problem in creating table or index. Error was: %s" -msgstr "" - -#: trunk/pdoengine.class.php:678 -#, php-format -msgid "Problem in executing alter query. Error was: %s" -msgstr "" - -#: trunk/sqlite-integration.php:158 trunk/sqlite-integration.php:181 -msgid "SQLite Integration" -msgstr "" - -#: trunk/utilities/documentation.php:16 trunk/utilities/documentation.php:18 -#: trunk/utilities/patch.php:161 trunk/utilities/patch.php:163 -#: trunk/utilities/utility.php:450 trunk/utilities/utility.php:452 -#: trunk/utilities/utility.php:636 trunk/utilities/utility.php:638 -msgid "You are not allowed to access this page!" -msgstr "" - -#: trunk/utilities/documentation.php:23 trunk/utilities/documentation.php:30 -#: trunk/utilities/patch.php:221 trunk/utilities/utility.php:422 -#: trunk/utilities/utility.php:457 trunk/utilities/utility.php:711 -msgid "Documentation" -msgstr "" - -#: trunk/utilities/documentation.php:24 trunk/utilities/patch.php:222 -#: trunk/utilities/utility.php:426 trunk/utilities/utility.php:458 -#: trunk/utilities/utility.php:712 -msgid "System Info" -msgstr "" - -#: trunk/utilities/documentation.php:25 trunk/utilities/patch.php:223 -#: trunk/utilities/utility.php:430 trunk/utilities/utility.php:459 -#: trunk/utilities/utility.php:713 -msgid "Miscellaneous" -msgstr "" - -#: trunk/utilities/documentation.php:26 trunk/utilities/patch.php:224 -#: trunk/utilities/utility.php:434 trunk/utilities/utility.php:460 -#: trunk/utilities/utility.php:714 -msgid "Patch Utility" -msgstr "" - -#: trunk/utilities/documentation.php:32 -msgid "" -"This is a brief documentation about this plugin. For more details, see also " -"the Plugin " -"Page." -msgstr "" - -#: trunk/utilities/documentation.php:35 -msgid "" -"Please don't forget: WordPress DOES NOT OFFICIALLY SUPPORT any database " -"other than MySQL. So if you ask about this plugin in the Forum, it's not " -"unlikely that you won't get no answers at all." -msgstr "" - -#: trunk/utilities/documentation.php:38 -msgid "Features" -msgstr "" - -#: trunk/utilities/documentation.php:40 -msgid "" -"This plugin is a successor to PDO for WordPress, which enabled WordPress to use " -"SQLite for its database. But PDO for WordPress doesn't seem to be maintained " -"any more only to be outdated. SQLite Integration makes use of the basic " -"ideas and framework of PDO for WordPress, adds some new features and updates " -"it to be able to work with the newest version of WordPress(3.6)." -msgstr "" - -#: trunk/utilities/documentation.php:43 -msgid "" -"SQLite Web Page says — SQLite " -"is a "software library that implements selfcontained, serverless, zero-" -"configuration, transactional SQL database engine". It is "a good " -"choice for small to medium size websites". It's small and portable, and " -"you don't need any database server system." -msgstr "" - -#: trunk/utilities/documentation.php:46 -msgid "" -"Unfortunately enough, WordPress only supports MySQL. Consequently it doesn't " -"provide any APIs for SQLite. So if you want to create a website using " -"WordPress without a database server, you've got to write a kind of wrapper " -"program yourself to use SQLite. This is the way SQLite Integration goes." -msgstr "" - -#: trunk/utilities/documentation.php:49 -msgid "SQLite Integration does the work as follows:" -msgstr "" - -#: trunk/utilities/documentation.php:52 -msgid "Intercepts SQL statement for MySQL from WordPress" -msgstr "" - -#: trunk/utilities/documentation.php:53 -msgid "Rewrites it as SQLite can execute" -msgstr "" - -#: trunk/utilities/documentation.php:54 -msgid "Gives it to SQLite" -msgstr "" - -#: trunk/utilities/documentation.php:55 -msgid "Gets the results from SQLite" -msgstr "" - -#: trunk/utilities/documentation.php:56 -msgid "Format the results as MySQL returns, if necessary" -msgstr "" - -#: trunk/utilities/documentation.php:57 -msgid "Gives back the results to WordPress" -msgstr "" - -#: trunk/utilities/documentation.php:60 -msgid "" -"WordPress doesn't know what has happened in the background and will be happy " -"with it." -msgstr "" - -#: trunk/utilities/documentation.php:63 -msgid "Limitations" -msgstr "" - -#: trunk/utilities/documentation.php:65 -msgid "" -"SQLite Integration uses SQLite, so the limitations of SQLite is, as it is, " -"those of SQLite Integration. MySQL is far from a simple SQL engine and has " -"many extended features and functionalities. WordPress uses some of them. " -"Among those are some SQLite doesn't implement. For those features that " -"WordPress uses, I made them work with SQLite Integration. But for others " -"that some plugins are using, SQLite Integration can't manipulate. So..." -msgstr "" - -#: trunk/utilities/documentation.php:68 -msgid "There are some plugins that you can't use in any way.Sorry, we cannot determine the type of query that is requested.
The query is %s
", '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 = '/(? 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; } /** diff --git a/query.class.php b/query.class.php index cd2899f..c5d81ab 100644 --- a/query.class.php +++ b/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'; @@ -521,14 +520,14 @@ class PDOSQLiteDriver { $unique_keys_for_check = array_map('trim', $unique_keys_for_check); } else { // Without unique key or primary key, UPDATE statement will affect all the rows! - $query = 'INSERT INTO '.$table_name.' '.$insert_data; + $query = 'INSERT INTO '.$table_name.' '.$insert_data; $this->_query = $query; $_wpdb = null; return; } // data check if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/ims', $insert_data, $match_1)) { - $col_array = explode(',', $match_1[1]); + $col_array = explode(',', $match_1[1]); $ins_data_array = explode(',', $match_1[2]); foreach ($col_array as $col) { $val = trim(array_shift($ins_data_array)); @@ -539,7 +538,7 @@ class PDOSQLiteDriver { foreach ($unique_keys_for_cond as $unique_key) { if (strpos($unique_key, ',') !== false) { $unique_key_array = explode(',', $unique_key); - $counter = count($unique_key_array); + $counter = count($unique_key_array); for ($i = 0; $i < $counter; ++$i) { $col = trim($unique_key_array[$i]); if (isset($ins_data_assoc[$col]) && $i == $counter - 1) { @@ -560,9 +559,9 @@ class PDOSQLiteDriver { } } } - $condition = rtrim($condition, ' OR '); + $condition = rtrim($condition, ' OR '); $test_query = "SELECT * FROM {$table_name} WHERE {$condition}"; - $results = $_wpdb->query($test_query); + $results = $_wpdb->query($test_query); $_wpdb = null; if ($results == 0) { $this->_query = 'INSERT INTO '.$table_name.' '.$insert_data; @@ -572,7 +571,7 @@ class PDOSQLiteDriver { if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/im', $insert_data, $match_2)) { $col_array = explode(',', $match_2[1]); $ins_array = explode(',', $match_2[2]); - $count = count($col_array); + $count = count($col_array); for ($i = 0; $i < $count; $i++) { $col = trim($col_array[$i]); $val = trim($ins_array[$i]); @@ -582,17 +581,17 @@ class PDOSQLiteDriver { // 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); + $tmp_array = explode(',', $update_data); foreach ($tmp_array as $pair) { list($col, $value) = explode('=', $pair); - $col = trim($col); + $col = trim($col); $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]); + $col = trim($match_3[1]); $value = $ins_array_assoc[$col]; } } @@ -610,8 +609,8 @@ class PDOSQLiteDriver { } } $update_strings = rtrim($update_strings, ','); - $unique_where = array_unique($where_array, SORT_REGULAR); - $where_string = ' WHERE ' . implode(' AND ', $unique_where); + $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; @@ -633,7 +632,7 @@ class PDOSQLiteDriver { * * @access private */ - private function _rewrite_between() { + 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]); @@ -641,7 +640,7 @@ class PDOSQLiteDriver { $max_value = trim($match[3]); $max_value = rtrim($max_value); $tokens = preg_split("/(''|')/s", $this->_query, -1, PREG_SPLIT_DELIM_CAPTURE); - $literal = false; + $literal = false; $rewriting = false; foreach ($tokens as $token) { if ($token == "'") { @@ -674,10 +673,10 @@ class PDOSQLiteDriver { * * @access private */ - private function _delete_workaround() { + 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"; + $pattern = "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2"; $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; @@ -692,7 +691,7 @@ class PDOSQLiteDriver { * * @access private */ - private function _return_true() { + private function return_true() { $this->_query = 'SELECT 1=1'; } } diff --git a/query_alter.class.php b/query_alter.class.php index c784651..933183c 100644 --- a/query_alter.class.php +++ b/query_alter.class.php @@ -27,10 +27,10 @@ class AlterQuery { } $query = str_replace('`', '', $query); if (preg_match('/^\\s*(ALTER\\s*TABLE)\\s*(\\w+)?\\s*/ims', $query, $match)) { - $tmp_query = array(); - $tokens = array(); + $tmp_query = array(); + $tokens = array(); $re_command = ''; - $command = str_ireplace($match[0], '', $query); + $command = str_ireplace($match[0], '', $query); $tmp_tokens['query_type'] = trim($match[1]); $tmp_tokens['table_name'] = trim($match[2]); // $command_array = $this->split_multiple($command); @@ -38,7 +38,7 @@ class AlterQuery { $single_command = array_shift($command_array); if (!empty($command_array)) { - $re_command = 'ALTER TABLE ' . $tmp_tokens['table_name'] . ' '; + $re_command = 'ALTER TABLE ' . $tmp_tokens['table_name'] . ' '; $re_command .= implode(',', $command_array); } $command_tokens = $this->command_tokenizer($single_command); @@ -105,17 +105,17 @@ class AlterQuery { if (in_array(strtolower($match_2), array('fulltext', 'constraint', 'foreign'))) { break; } elseif (stripos('column', $match_2) !== false) { - $tokens['command'] = $match_1.' '.$match_2; + $tokens['command'] = $match_1.' '.$match_2; $tokens['column_name'] = $match_3; - $tokens['column_def'] = trim($the_rest); + $tokens['column_def'] = trim($the_rest); } elseif (stripos('primary', $match_2) !== false) { - $tokens['command'] = $match_1.' '.$match_2.' '.$match_3; + $tokens['command'] = $match_1.' '.$match_2.' '.$match_3; $tokens['column_name'] = $the_rest; } elseif (stripos('unique', $match_2) !== false) { list($index_name, $col_name) = preg_split('/[\(\)]/s', trim($the_rest), -1, PREG_SPLIT_DELIM_CAPTURE); - $tokens['unique'] = true; - $tokens['command'] = $match_1.' '.$match_3; - $tokens['index_name'] = trim($index_name); + $tokens['unique'] = true; + $tokens['command'] = $match_1.' '.$match_3; + $tokens['index_name'] = trim($index_name); $tokens['column_name'] = '('.trim($col_name).')'; } elseif (in_array(strtolower($match_2), array('index', 'key'))) { $tokens['command'] = $match_1.' '.$match_2; @@ -126,65 +126,65 @@ class AlterQuery { } $tokens['column_name'] = trim($the_rest); } else { - $tokens['command'] = $match_1.' COLUMN'; + $tokens['command'] = $match_1.' COLUMN'; $tokens['column_name'] = $match_2; - $tokens['column_def'] = $match_3.' '.$the_rest; + $tokens['column_def'] = $match_3.' '.$the_rest; } break; case 'drop': if (stripos('column', $match_2) !== false) { - $tokens['command'] = $match_1.' '.$match_2; + $tokens['command'] = $match_1.' '.$match_2; $tokens['column_name'] = trim($match_3); } elseif (stripos('primary', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2.' '.$match_3; } elseif (in_array(strtolower($match_2), array('index', 'key'))) { - $tokens['command'] = $match_1.' '.$match_2; + $tokens['command'] = $match_1.' '.$match_2; $tokens['index_name'] = $match_3; } elseif (stripos('primary', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2.' '.$match_3; } else { - $tokens['command'] = $match_1.' COLUMN'; + $tokens['command'] = $match_1.' COLUMN'; $tokens['column_name'] = $match_2; } break; case 'rename': if (stripos('to', $match_2) !== false) { - $tokens['command'] = $match_1.' '.$match_2; + $tokens['command'] = $match_1.' '.$match_2; $tokens['column_name'] = $match_3; } else { - $tokens['command'] = $match_1.' TO'; + $tokens['command'] = $match_1.' TO'; $tokens['column_name'] = $match_2; } break; case 'modify': if (stripos('column', $match_2) !== false) { - $tokens['command'] = $match_1.' '.$match_2; + $tokens['command'] = $match_1.' '.$match_2; $tokens['column_name'] = $match_3; - $tokens['column_def'] = trim($the_rest); + $tokens['column_def'] = trim($the_rest); } else { - $tokens['command'] = $match_1.' COLUMN'; + $tokens['command'] = $match_1.' COLUMN'; $tokens['column_name'] = $match_2; - $tokens['column_def'] = $match_3.' '.trim($the_rest); + $tokens['column_def'] = $match_3.' '.trim($the_rest); } break; case 'change': $the_rest = trim($the_rest); if (stripos('column', $match_2) !== false) { - $tokens['command'] = $match_1.' '.$match_2; + $tokens['command'] = $match_1.' '.$match_2; $tokens['old_column'] = $match_3; - list($new_col) = explode(' ', $the_rest); - $tmp_col = preg_replace('/\(.+?\)/im', '', $new_col); + list($new_col) = explode(' ', $the_rest); + $tmp_col = preg_replace('/\(.+?\)/im', '', $new_col); if (array_key_exists(strtolower($tmp_col), $this->array_types)) { $tokens['column_def'] = $the_rest; } else { $tokens['new_column'] = $new_col; - $col_def = str_replace($new_col, '', $the_rest); + $col_def = str_replace($new_col, '', $the_rest); $tokens['column_def'] = trim($col_def); } } else { - $tokens['command'] = $match_1.' column'; + $tokens['command'] = $match_1.' column'; $tokens['old_column'] = $match_2; - $tmp_col = preg_replace('/\(.+?\)/im', '', $match_3); + $tmp_col = preg_replace('/\(.+?\)/im', '', $match_3); if (array_key_exists(strtolower($tmp_col), $this->array_types)) { $tokens['column_def'] = $match_3 . ' ' . $the_rest; } else { @@ -195,23 +195,23 @@ class AlterQuery { break; case 'alter': if (stripos('column', $match_2) !== false) { - $tokens['command'] = $match_1.' '.$match_2; + $tokens['command'] = $match_1.' '.$match_2; $tokens['column_name'] = $match_3; - list($set_or_drop) = explode(' ', $the_rest); + list($set_or_drop) = explode(' ', $the_rest); if (stripos('set', $set_or_drop) !== false) { $tokens['default_command'] = 'SET DEFAULT'; - $default_value = str_ireplace('set default', '', $the_rest); - $tokens['default_value'] = trim($default_value); + $default_value = str_ireplace('set default', '', $the_rest); + $tokens['default_value'] = trim($default_value); } else { $tokens['default_command'] = 'DROP DEFAULT'; } } else { - $tokens['command'] = $match_1.' COLUMN'; + $tokens['command'] = $match_1.' COLUMN'; $tokens['column_name'] = $match_2; if (stripos('set', $match_3) !== false) { $tokens['default_command'] = 'SET DEFAULT'; - $default_value = str_ireplace('default', '', $the_rest); - $tokens['default_value'] = trim($default_value); + $default_value = str_ireplace('default', '', $the_rest); + $tokens['default_value'] = trim($default_value); } else { $tokens['default_command'] = 'DROP DEFAULT'; } @@ -233,10 +233,10 @@ class AlterQuery { * @return multitype:string unknown Ambigous- SQLite Integration page.', $domain);?> + SQLite Integration page.', $domain);?>
@@ -76,7 +76,7 @@ class SQLiteIntegrationDocument {
Support Forum.', $domain);?> diff --git a/utilities/patch.php b/utilities/patch.php index b4b5f35..a5482b4 100644 --- a/utilities/patch.php +++ b/utilities/patch.php @@ -26,7 +26,7 @@ class PatchUtils { } else { if ($dir_handle = opendir(SQLitePatchDir)) { while (($file_name = readdir($dir_handle)) !== false) { - if ($file_name == '.' || $file_name == '..') + if ($file_name == '.' || $file_name == '..' || $file_name == '.htaccess') continue; $patch_files[] = $file_name; } @@ -148,31 +148,82 @@ class PatchUtils { * * It uploads a patch file to the server. You must have the permission to write to the * temporary directory. If there isn't SQLitePatchDir, this method will create it and - * set the permission to 0705. + * set the permission to 0707. * * No return values. * + * @return boolean * @access private */ private function upload_file() { global $utils; $domain = $utils->text_domain; if (!file_exists(SQLitePatchDir) || !is_dir(SQLitePatchDir)) { - mkdir(SQLitePatchDir, 0705, true); + if (!mkdir(SQLitePatchDir, 0707, true)) { + $message = __('Unable to create a patch directory.', $domain); + echo '
+ +