From 069f1ef306c8d2848ca196d2806ac01f81573884 Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Thu, 30 Jan 2025 13:45:21 +0100 Subject: [PATCH] Add a test for the reason to use backtick identifier escaping --- tests/WP_SQLite_Driver_Tests.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/WP_SQLite_Driver_Tests.php b/tests/WP_SQLite_Driver_Tests.php index 547334ff..38df86d5 100644 --- a/tests/WP_SQLite_Driver_Tests.php +++ b/tests/WP_SQLite_Driver_Tests.php @@ -3665,4 +3665,23 @@ public function testColumnDefaults(): void { $result[0]->{'Create Table'} ); } + + public function testSelectNonExistentColumn(): void { + $this->assertQuery( + 'CREATE TABLE t (id INT)' + ); + + /* + * Here, we're basically testing that identifiers are escaped using + * backticks instead of double quotes. In SQLite, double quotes may + * fallback to a string literal and thus produce no error. + * + * See: + * https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted + */ + $this->assertQuery( + 'SELECT non_existent_column FROM t LIMIT 0', + 'no such column: non_existent_column' + ); + } }