Skip to content

Commit 39fa104

Browse files
authored
Merge pull request #9 from WordPress/lexer-translation
SQLite support via a MySQL parser
2 parents 847e250 + ecc760d commit 39fa104

22 files changed

+8698
-3747
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
.gitignore export-ignore
55
composer.json export-ignore
66
phpcs.xml.dist export-ignore
7+
tests/*.php export-ignore

load.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* Plugin Name: SQLite Database Integration
44
* Description: SQLite database driver drop-in. (based on SQLite Integration by Kojima Toshiyasu)
55
* Author: WordPress Performance Team
6-
* Version: 1.0.3
6+
* Version: 2.0
77
* Requires PHP: 5.6
88
* Textdomain: sqlite-database-integration
99
*
1010
* This project is based on the original work of Kojima Toshiyasu and his SQLite Integration plugin,
1111
* and the work of Evan Mattson and his WP SQLite DB plugin - See https://github.com/aaemnnosttv/wp-sqlite-db
12+
*
13+
* @package wp-sqlite-integration
1214
*/
1315

1416
define( 'SQLITE_MAIN_FILE', __FILE__ );

phpcs.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<file>.</file>
2424

2525
<rule ref="WordPress-Core"/>
26+
<rule ref="WordPress-Docs"/>
2627
<rule ref="WordPress.CodeAnalysis.EmptyStatement"/>
2728

2829
<!-- Directories and third party library exclusions. -->

readme.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: wordpressdotorg, aristath
44
Requires at least: 6.0
55
Tested up to: 6.1
66
Requires PHP: 5.6
7-
Stable tag: 1.0.3
7+
Stable tag: 2.0
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010
Tags: performance, database
@@ -15,11 +15,16 @@ SQLite-integration plugin from the WordPress Performance Team.
1515

1616
The SQLite plugin is a community, feature plugin. The intent is to allow testing an SQLite integration with WordPress and gather feedback, with the goal of eventually landing it in WordPress core.
1717

18+
This project is based on the original work of Kojima Toshiyasu and his SQLite Integration plugin, and the work of Evan Mattson and his WP SQLite DB plugin - See https://github.com/aaemnnosttv/wp-sqlite-db.
19+
20+
It also includes code from the PHPMyAdmin project (specifically parts of the PHPMyAdmin/sql-parser library), licensed under the GPL v2 or later. More info on the PHPMyAdmin/sql-parser library can be found on [GitHub](https://github.com/phpmyadmin/sql-parser).
21+
1822
== Frequently Asked Questions ==
1923

2024
= What is the purpose of this plugin? =
2125

2226
The primary purpose of the SQLite plugin is to allow testing the use of an SQLite database, with the goal to eventually land in WordPress core.
27+
2328
You can read the original proposal on the [Make blog](https://make.wordpress.org/core/2022/09/12/lets-make-wordpress-officially-support-sqlite/), as well as the [call for testing](https://make.wordpress.org/core/2022/12/20/help-us-test-the-sqlite-implementation/) for more context and useful information.
2429

2530
= Can I use this plugin on my production site? =

tests/QueryRewriterTests.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
require __DIR__ . '/class-wp-sqlite-query-rewriter.php';
4+
require __DIR__ . '/class-wp-sqlite-lexer.php';
5+
6+
use PHPUnit\Framework\TestCase;
7+
8+
class WP_SQLite_Query_RewriterTests extends TestCase {
9+
10+
11+
public function testConsume() {
12+
$r = new WP_SQLite_Query_Rewriter(
13+
array(
14+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_DELIMITER ),
15+
WP_SQLite_Lexer::get_token( 'int', WP_SQLite_Lexer::TYPE_KEYWORD, WP_SQLite_Lexer::FLAG_KEYWORD_DATA_TYPE ),
16+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_DELIMITER ),
17+
WP_SQLite_Lexer::get_token( 'DATE_ADD', WP_SQLite_Lexer::TYPE_KEYWORD, WP_SQLite_Lexer::FLAG_KEYWORD_FUNCTION ),
18+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_DELIMITER ),
19+
WP_SQLite_Lexer::get_token( 'SET', WP_SQLite_Lexer::TYPE_KEYWORD ),
20+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_WHITESPACE ),
21+
)
22+
);
23+
$this->assertEquals(
24+
'int',
25+
$r->consume(
26+
array(
27+
'type' => WP_SQLite_Lexer::TYPE_KEYWORD,
28+
'flags' => WP_SQLite_Lexer::FLAG_KEYWORD_DATA_TYPE,
29+
)
30+
)->value
31+
);
32+
$this->assertEquals(
33+
'DATE_ADD',
34+
$r->consume(
35+
array(
36+
'type' => WP_SQLite_Lexer::TYPE_KEYWORD,
37+
'flags' => WP_SQLite_Lexer::FLAG_KEYWORD_FUNCTION,
38+
)
39+
)->value
40+
);
41+
}
42+
public function testSkip() {
43+
$r = new WP_SQLite_Query_Rewriter(
44+
array(
45+
WP_SQLite_Lexer::get_token( 'DO', WP_SQLite_Lexer::TYPE_KEYWORD ),
46+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_WHITESPACE ),
47+
WP_SQLite_Lexer::get_token( 'UPDATE', WP_SQLite_Lexer::TYPE_KEYWORD ),
48+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_WHITESPACE ),
49+
WP_SQLite_Lexer::get_token( 'SET', WP_SQLite_Lexer::TYPE_KEYWORD ),
50+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_WHITESPACE ),
51+
)
52+
);
53+
$this->assertEquals(
54+
'DO',
55+
$r->skip()->value
56+
);
57+
$this->assertEquals(
58+
'UPDATE',
59+
$r->skip()->value
60+
);
61+
}
62+
63+
public function skip_over() {
64+
$r = new WP_SQLite_Query_Rewriter(
65+
array(
66+
WP_SQLite_Lexer::get_token( 'DO', WP_SQLite_Lexer::TYPE_KEYWORD ),
67+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_WHITESPACE ),
68+
WP_SQLite_Lexer::get_token( 'UPDATE', WP_SQLite_Lexer::TYPE_KEYWORD ),
69+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_WHITESPACE ),
70+
WP_SQLite_Lexer::get_token( 'SET', WP_SQLite_Lexer::TYPE_KEYWORD ),
71+
WP_SQLite_Lexer::get_token( ' ', WP_SQLite_Lexer::TYPE_WHITESPACE ),
72+
)
73+
);
74+
$buffer = $r->skip_over(
75+
array(
76+
'values' => array( 'UPDATE' ),
77+
)
78+
);
79+
$this->assertCount( 3, $buffer );
80+
$this->assertEquals( 'DO', $buffer[0]->value );
81+
$this->assertEquals( ' ', $buffer[1]->value );
82+
$this->assertEquals( 'UPDATE', $buffer[2]->value );
83+
}
84+
85+
}

0 commit comments

Comments
 (0)