Browse Source

Fixed some bugs and added more features.

git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@852178 b8457f37-d9ea-0310-8a92-e5e31aec5664
master
kjmtsh 9 years ago
parent
commit
71a1df03db
30 changed files with 2204 additions and 947 deletions
  1. +8
    -0
      db.php
  2. +38
    -6
      functions-5-2.php
  3. +38
    -6
      functions.php
  4. +1
    -0
      js/sqlite.js
  5. BIN
      languages/sqlite-integration-ja.mo
  6. +71
    -15
      languages/sqlite-integration-ja.po
  7. +709
    -607
      languages/sqlite-integration.pot
  8. +22
    -5
      pdodb.class.php
  9. +144
    -70
      pdoengine.class.php
  10. +93
    -94
      query.class.php
  11. +66
    -66
      query_alter.class.php
  12. +55
    -19
      query_create.class.php
  13. +5
    -1
      readme-ja.txt
  14. +5
    -1
      readme.txt
  15. +8
    -7
      schema.php
  16. +70
    -26
      sqlite-integration.php
  17. +2
    -0
      styles/blue.css
  18. +2
    -0
      styles/coffee.css
  19. +2
    -0
      styles/ectoplasm.css
  20. +2
    -0
      styles/light.css
  21. +2
    -0
      styles/midnight.css
  22. +2
    -0
      styles/ocean.css
  23. +7
    -2
      styles/style.css
  24. +1
    -1
      styles/style.min.css
  25. +2
    -0
      styles/sunrise.css
  26. +8
    -3
      utilities/database_maintenance.php
  27. +2
    -2
      utilities/documentation.php
  28. +60
    -8
      utilities/patch.php
  29. +695
    -2
      utilities/plugin_lists.json
  30. +84
    -6
      utilities/utility.php

+ 8
- 0
db.php View File

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

+ 38
- 6
functions-5-2.php View File

@ -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.
@ -666,18 +670,46 @@ class PDOSQLiteUDFS {
}
}
}
/**
* Method to return GMT date in the string format.
*
* @param none
* @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 WordPress $required_mysql_version, because it is
* meaningless for SQLite database.
* 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
* @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';
}
}
?>

+ 38
- 6
functions.php View File

@ -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.
@ -639,18 +643,46 @@ class PDOSQLiteUDFS {
}
}
}
/**
* Method to return GMT date in the string format.
*
* @param none
* @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 WordPress $required_mysql_version, because it is
* meaningless for SQLite database.
* 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
* @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';
}
}
?>

+ 1
- 0
js/sqlite.js View File

@ -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($) {

BIN
languages/sqlite-integration-ja.mo View File


+ 71
- 15
languages/sqlite-integration-ja.po View File

@ -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ใฎใ‚จใƒฉใƒผใƒญใ‚ฐ"

+ 709
- 607
languages/sqlite-integration.pot
File diff suppressed because it is too large
View File


+ 22
- 5
pdodb.class.php View File

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

+ 144
- 70
pdoengine.class.php View File

@ -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: class="se">\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;
}
/**

+ 93
- 94
query.class.php View File

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