This repository was archived by the owner on Jun 2, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -5139,4 +5139,29 @@ public function testColumnNamesAreNotCaseSensitive(): void {
5139
5139
$ this ->assertCount ( 1 , $ result );
5140
5140
$ this ->assertSame ( 'value ' , $ result [0 ]->Field );
5141
5141
}
5142
+
5143
+ public function testAliasesMustBeAscii (): void {
5144
+ $ this ->expectException ( WP_SQLite_Driver_Exception::class );
5145
+ $ this ->expectExceptionMessage ( 'The SQLite driver only supports ASCII characters in identifiers. ' );
5146
+ $ this ->assertQuery ( 'SELECT 123 AS `ńôñ-ášçíì` ' );
5147
+ }
5148
+
5149
+ public function testTableNamesMustBeAscii (): void {
5150
+ $ this ->expectException ( WP_SQLite_Driver_Exception::class );
5151
+ $ this ->expectExceptionMessage ( 'The SQLite driver only supports ASCII characters in identifiers. ' );
5152
+ $ this ->assertQuery ( 'CREATE TABLE `ńôñ-ášçíì` (id INT) ' );
5153
+ }
5154
+
5155
+ public function testColumnNamesMustBeAscii (): void {
5156
+ $ this ->expectException ( WP_SQLite_Driver_Exception::class );
5157
+ $ this ->expectExceptionMessage ( 'The SQLite driver only supports ASCII characters in identifiers. ' );
5158
+ $ this ->assertQuery ( 'CREATE TABLE t (`ńôñ-ášçíì` INT) ' );
5159
+ }
5160
+
5161
+ public function testIndexNamesMustBeAscii (): void {
5162
+ $ this ->expectException ( WP_SQLite_Driver_Exception::class );
5163
+ $ this ->expectExceptionMessage ( 'The SQLite driver only supports ASCII characters in identifiers. ' );
5164
+ $ this ->assertQuery ( 'CREATE TABLE t (id INT) ' );
5165
+ $ this ->assertQuery ( 'CREATE INDEX `ńôñ-ášçíì` ON t (id) ' );
5166
+ }
5142
5167
}
Original file line number Diff line number Diff line change @@ -2121,7 +2121,21 @@ private function translate( $node ): ?string {
2121
2121
case 'identifierKeyword ' :
2122
2122
return '` ' . $ this ->translate ( $ node ->get_first_child () ) . '` ' ;
2123
2123
case 'pureIdentifier ' :
2124
- return $ this ->translate_pure_identifier ( $ node );
2124
+ $ value = $ this ->translate_pure_identifier ( $ node );
2125
+
2126
+ /*
2127
+ * At the moment, we only support ASCII bytes in all identifiers.
2128
+ * This is because SQLite doesn't support case-insensitive Unicode
2129
+ * character matching: https://sqlite.org/faq.html#q18
2130
+ */
2131
+ for ( $ i = 0 ; $ i < strlen ( $ value ); $ i ++ ) {
2132
+ if ( ord ( $ value [ $ i ] ) > 127 ) {
2133
+ throw $ this ->new_driver_exception (
2134
+ 'The SQLite driver only supports ASCII characters in identifiers. '
2135
+ );
2136
+ }
2137
+ }
2138
+ return $ value ;
2125
2139
case 'textStringLiteral ' :
2126
2140
return $ this ->translate_string_literal ( $ node );
2127
2141
case 'dataType ' :
Original file line number Diff line number Diff line change @@ -2113,6 +2113,19 @@ private function get_value( WP_Parser_Node $node ): string {
2113
2113
foreach ( $ node ->get_children () as $ child ) {
2114
2114
if ( $ child instanceof WP_Parser_Node ) {
2115
2115
$ value = $ this ->get_value ( $ child );
2116
+
2117
+ /*
2118
+ * At the moment, we only support ASCII bytes in all identifiers.
2119
+ * This is because SQLite doesn't support case-insensitive Unicode
2120
+ * character matching: https://sqlite.org/faq.html#q18
2121
+ */
2122
+ if ( 'pureIdentifier ' === $ child ->rule_name ) {
2123
+ for ( $ i = 0 ; $ i < strlen ( $ value ); $ i ++ ) {
2124
+ if ( ord ( $ value [ $ i ] ) > 127 ) {
2125
+ throw new Exception ( 'The SQLite driver only supports ASCII characters in identifiers. ' );
2126
+ }
2127
+ }
2128
+ }
2116
2129
} else {
2117
2130
$ value = $ child ->get_value ();
2118
2131
}
You can’t perform that action at this time.
0 commit comments