Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wordpress Sqlite implementation #126

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Add fixes for sqlite db.php peachpie support, add wal journal mode
  • Loading branch information
LORDofDOOM committed Sep 11, 2022
commit 59c3d841ea112f99310829bfaaf8a240e40cc850
43 changes: 40 additions & 3 deletions wordpress/wp-content/db.php
Original file line number Diff line number Diff line change
@@ -1770,7 +1770,13 @@ private function extract_variables()

//long queries can really kill this
$pattern = '/(?<!\\\\)([\'"])(.*?)(?<!\\\\)\\1/imsx';
$_limit = $limit = ini_get('pcre.backtrack_limit');
if (defined('PEACHPIE_VERSION'))
{
$_limit = $limit = 10000000;
} else {
$_limit = $limit = ini_get('pcre.backtrack_limit');
}

// if user's setting is more than default * 10, make PHP do the job.
if ($limit > 10000000) {
$query = preg_replace_callback($pattern, [$this, 'replace_variables_with_placeholders'],
@@ -1781,15 +1787,21 @@ private function extract_variables()
$this->set_error(__LINE__, __FUNCTION__, 'The query is too big to parse properly');
break; //no point in continuing execution, would get into a loop
} else {
ini_set('pcre.backtrack_limit', $limit);
if (!defined('PEACHPIE_VERSION'))
{
ini_set('pcre.backtrack_limit', $limit);
}
$query = preg_replace_callback($pattern, [$this, 'replace_variables_with_placeholders'],
$this->rewritten_query);
}
$limit = $limit * 10;
} while (is_null($query));

//reset the pcre.backtrack_limit
ini_set('pcre.backtrack_limit', $_limit);
if (!defined('PEACHPIE_VERSION'))
{
ini_set('pcre.backtrack_limit', $_limit);
}
}

if (isset($query)) {
@@ -1820,6 +1832,13 @@ private function replace_variables_with_placeholders($matches)
if (in_array($param[0], ["'", '"'])) {
$param = substr($param, 1); //start
}

if (defined('PEACHPIE_VERSION'))
{
$this->extracted_variables[] = $param;
return ' ? ';
}

//$this->extracted_variables[] = $param;
$key = ':param_' . $this->param_num++;
$this->extracted_variables[] = $param;
@@ -2409,6 +2428,11 @@ private function convert_result_check_or_analyze()
*/
private function get_sqlite_version()
{
if (defined('PEACHPIE_VERSION'))
{
return;
}

try {
$statement = $this->pdo->prepare('SELECT sqlite_version()');
$statement->execute();
@@ -2428,6 +2452,10 @@ private function get_sqlite_version()
*/
public function beginTransaction()
{
if (defined('PEACHPIE_VERSION'))
{
return;
}
if ($this->has_active_transaction) {
return false;
} else {
@@ -2444,6 +2472,10 @@ public function beginTransaction()
*/
public function commit()
{
if (defined('PEACHPIE_VERSION'))
{
return;
}
$this->pdo->commit();
$this->has_active_transaction = false;
}
@@ -2455,6 +2487,10 @@ public function commit()
*/
public function rollBack()
{
if (defined('PEACHPIE_VERSION'))
{
return;
}
$this->pdo->rollBack();
$this->has_active_transaction = false;
}
@@ -4900,5 +4936,6 @@ function wp_install($blog_title, $user_name, $user_email, $public, $deprecated =
}

$GLOBALS['wpdb'] = new WP_SQLite_DB\wpsqlitedb();
$GLOBALS['wpdb']->query('PRAGMA journal_mode = wal;');
}