Skip to content

Commit

Permalink
build(includes/sqlite-database-integration) update from v4
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Apr 5, 2024
1 parent a23abfe commit cad4290
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 99 deletions.
5 changes: 3 additions & 2 deletions includes/sqlite-database-integration/activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/
function sqlite_plugin_activation_redirect( $plugin ) {
if ( plugin_basename( SQLITE_MAIN_FILE ) === $plugin ) {
wp_redirect( admin_url( 'options-general.php?page=sqlite-integration' ) );
exit;
if ( wp_safe_redirect( admin_url( 'options-general.php?page=sqlite-integration' ) ) ) {
exit;
}
}
}
add_action( 'activated_plugin', 'sqlite_plugin_activation_redirect' );
Expand Down
8 changes: 7 additions & 1 deletion includes/sqlite-database-integration/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
* @since 1.0.0
*/
function sqlite_add_admin_menu() {
add_options_page(__( 'SQLite integration', 'sqlite-database-integration' ), __( 'SQLite integration', 'sqlite-database-integration' ), 'manage_options', 'sqlite-integration', 'sqlite_integration_admin_screen');
add_options_page(
__( 'SQLite integration', 'sqlite-database-integration' ),
__( 'SQLite integration', 'sqlite-database-integration' ),
'manage_options',
'sqlite-integration',
'sqlite_integration_admin_screen'
);
}
add_action( 'admin_menu', 'sqlite_add_admin_menu' );

Expand Down
2 changes: 1 addition & 1 deletion includes/sqlite-database-integration/deactivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function sqlite_plugin_remove_db_file() {
// Run an action on `shutdown`, to deactivate the option in the MySQL database.
add_action(
'shutdown',
function() {
function () {
global $table_prefix;

// Get credentials for the MySQL database.
Expand Down
1 change: 1 addition & 0 deletions includes/sqlite-database-integration/health-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function sqlite_plugin_filter_site_status_tests( $tests ) {
if ( 'sqlite' === $db_engine ) {
unset( $tests['direct']['utf8mb4_support'] );
unset( $tests['direct']['sql_server'] );
unset( $tests['direct']['persistent_object_cache'] ); // Throws an error because DB_NAME is not defined.
}

return $tests;
Expand Down
6 changes: 3 additions & 3 deletions includes/sqlite-database-integration/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/**
* Plugin Name: SQLite Database Integration
* Description: SQLite database driver drop-in.
* Author: WordPress Performance Team
* Version: 2.1.2
* Requires PHP: 5.6
* Author: The WordPress Team
* Version: 2.1.7
* Requires PHP: 7.0
* Textdomain: sqlite-database-integration
*
* This feature plugin allows WordPress to use SQLite instead of MySQL as its database.
Expand Down
4 changes: 2 additions & 2 deletions includes/sqlite-database-integration/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Contributors: wordpressdotorg, aristath
Requires at least: 6.0
Tested up to: 6.4
Requires PHP: 5.6
Stable tag: 2.1.2
Stable tag: 2.1.7
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, database

SQLite-integration plugin from the WordPress Performance Team.
SQLite integration plugin by the WordPress Team.

== Description ==

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function select( $db, $dbh = null ) {
*
* @return string escaped
*/
function _real_escape( $str ) {
public function _real_escape( $str ) {
return addslashes( $str );
}

Expand Down Expand Up @@ -278,7 +278,7 @@ public function query( $query ) {
}

$this->result = $this->dbh->query( $query );
$this->num_queries++;
++$this->num_queries;

if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
Expand Down Expand Up @@ -349,7 +349,7 @@ public function has_cap( $db_cap ) {
* @see wpdb::db_version()
*/
public function db_version() {
return '5.5';
return '8.0';
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This file is a port of the Lexer & Tokens_List classes from the PHPMyAdmin/sql-parser library.
* This file is a port of the Lexer & TokensList classes from the PHPMyAdmin/sql-parser library.
*
* @package wp-sqlite-integration
* @see https://github.com/phpmyadmin/sql-parser
Expand Down Expand Up @@ -33,7 +33,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
public static $parser_methods = array(
const PARSER_METHODS = array(
// It is best to put the parsers in order of their complexity
// (ascending) and their occurrence rate (descending).
//
Expand Down Expand Up @@ -77,7 +77,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
public $keyword_name_indicators = array(
const KEYWORD_NAME_INDICATORS = array(
'FROM',
'SET',
'WHERE',
Expand All @@ -89,7 +89,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
public $operator_name_indicators = array(
const OPERATOR_NAME_INDICATORS = array(
',',
'.',
);
Expand Down Expand Up @@ -1486,7 +1486,7 @@ public function lex() {
*/
$token = null;

foreach ( static::$parser_methods as $method ) {
foreach ( self::PARSER_METHODS as $method ) {
$token = $this->$method();

if ( $token ) {
Expand Down Expand Up @@ -1668,10 +1668,10 @@ private function solve_ambiguity_on_function_keywords() {
$next = $this->tokens_get_next();
if (
( WP_SQLite_Token::TYPE_KEYWORD !== $next->type
|| ! in_array( $next->value, $this->keyword_name_indicators, true )
|| ! in_array( $next->value, self::KEYWORD_NAME_INDICATORS, true )
)
&& ( WP_SQLite_Token::TYPE_OPERATOR !== $next->type
|| ! in_array( $next->value, $this->operator_name_indicators, true )
|| ! in_array( $next->value, self::OPERATOR_NAME_INDICATORS, true )
)
&& ( null !== $next->value )
) {
Expand Down Expand Up @@ -2068,7 +2068,7 @@ public function parse_number() {
} elseif (
$this->last + 1 < $this->string_length
&& '0' === $this->str[ $this->last ]
&& ( 'x' === $this->str[ $this->last + 1 ] || 'X' === $this->str[ $this->last + 1 ] )
&& 'x' === $this->str[ $this->last + 1 ]
) {
$token .= $this->str[ $this->last++ ];
$state = 2;
Expand Down Expand Up @@ -2260,7 +2260,7 @@ public function parse_symbol() {
if ( null === $str ) {
$str = $this->parse_unknown();

if ( null === $str ) {
if ( null === $str && ! ( $flags & WP_SQLite_Token::FLAG_SYMBOL_PARAMETER ) ) {
$this->error( 'Variable name was expected.', $this->str[ $this->last ], $this->last );
}
}
Expand Down Expand Up @@ -2514,15 +2514,10 @@ public static function is_separator( $str ) {
* Constructor.
*
* @param stdClass[] $tokens The initial array of tokens.
* @param int $count The count of tokens in the initial array.
*/
public function tokens( array $tokens = array(), $count = -1 ) {
if ( empty( $tokens ) ) {
return;
}

public function tokens( array $tokens = array() ) {
$this->tokens = $tokens;
$this->tokens_count = -1 === $count ? count( $tokens ) : $count;
$this->tokens_count = count( $tokens );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function month( $field ) {
* From https://www.php.net/manual/en/datetime.format.php:
*
* n - Numeric representation of a month, without leading zeros.
* 1 through 12
* 1 through 12
*/
return intval( gmdate( 'n', strtotime( $field ) ) );
}
Expand Down Expand Up @@ -446,14 +446,14 @@ public function isnull( $field ) {
*
* As 'IF' is a reserved word for PHP, function name must be changed.
*
* @param mixed $expression the statement to be evaluated as true or false.
* @param mixed $true statement or value returned if $expression is true.
* @param mixed $false statement or value returned if $expression is false.
* @param mixed $expression The statement to be evaluated as true or false.
* @param mixed $truthy Statement or value returned if $expression is true.
* @param mixed $falsy Statement or value returned if $expression is false.
*
* @return mixed
*/
public function _if( $expression, $true, $false ) {
return ( true === $expression ) ? $true : $false;
public function _if( $expression, $truthy, $falsy ) {
return ( true === $expression ) ? $truthy : $falsy;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class WP_SQLite_Token {
*
* @var mixed|string|null
*/
public $keyword;
public $keyword = null;

/**
* The type of this token.
Expand Down Expand Up @@ -195,11 +195,10 @@ class WP_SQLite_Token {
* @param int $flags The flags of the token.
*/
public function __construct( $token, $type = 0, $flags = 0 ) {
$this->token = $token;
$this->type = $type;
$this->flags = $flags;
$this->keyword = null;
$this->value = $this->extract();
$this->token = $token;
$this->type = $type;
$this->flags = $flags;
$this->value = $this->extract();
}

/**
Expand Down Expand Up @@ -262,8 +261,8 @@ private function extract() {
case self::TYPE_NUMBER:
$ret = str_replace( '--', '', $this->token ); // e.g. ---42 === -42.
if ( $this->flags & self::FLAG_NUMBER_HEX ) {
$ret = str_replace( array( '-', '+' ), '', $this->token );
if ( $this->flags & self::FLAG_NUMBER_NEGATIVE ) {
$ret = str_replace( '-', '', $this->token );
$ret = -hexdec( $ret );
} else {
$ret = hexdec( $ret );
Expand Down
Loading

0 comments on commit cad4290

Please sign in to comment.