From 90f4d69774359bad393fabd443587cb7a9d4d651 Mon Sep 17 00:00:00 2001 From: Diego Reis Date: Mon, 29 Sep 2025 22:30:31 -0300 Subject: [PATCH] fix(3301): Remove identifier assert assumption Not every identifier should be double-quoted --- core/translate/optimizer/mod.rs | 6 +----- testing/cli_tests/cli_test_cases.py | 15 +++++++++++++++ testing/default_value.test | 7 +++++-- testing/select.test | 14 +++++++------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/core/translate/optimizer/mod.rs b/core/translate/optimizer/mod.rs index edbd35ec9..627017b27 100644 --- a/core/translate/optimizer/mod.rs +++ b/core/translate/optimizer/mod.rs @@ -707,11 +707,7 @@ impl Optimizable for ast::Expr { func.is_deterministic() && args.iter().all(|arg| arg.is_constant(resolver)) } Expr::FunctionCallStar { .. } => false, - Expr::Id(id) => { - // If we got here with an id, this has to be double-quotes identifier - assert!(id.quoted_with('"')); - true - } + Expr::Id(_) => true, Expr::Column { .. } => false, Expr::RowId { .. } => false, Expr::InList { lhs, rhs, .. } => { diff --git a/testing/cli_tests/cli_test_cases.py b/testing/cli_tests/cli_test_cases.py index c649c7474..fa07285d4 100755 --- a/testing/cli_tests/cli_test_cases.py +++ b/testing/cli_tests/cli_test_cases.py @@ -355,6 +355,20 @@ def test_copy_memory_db_to_file(): sqlite.quit() +def test_parse_error(): + testpath = "testing/memory.db" + if Path(testpath).exists(): + os.unlink(Path(testpath)) + time.sleep(0.2) # make sure closed + + turso = TestTursoShell(init_commands="") + turso.run_test_fn( + "select * from sqlite_schema limit asdf;", + lambda res: "Parse error: " in res, + "Try to LIMIT using an identifier should trigger a Parse error", + ) + + def main(): console.info("Running all turso CLI tests...") test_basic_queries() @@ -378,6 +392,7 @@ def main(): test_uri_readonly() test_copy_db_file() test_copy_memory_db_to_file() + test_parse_error() console.info("All tests have passed") diff --git a/testing/default_value.test b/testing/default_value.test index 8215527e1..b4fc9c9aa 100644 --- a/testing/default_value.test +++ b/testing/default_value.test @@ -39,5 +39,8 @@ do_execsql_test_on_specific_db {:memory:} default-value-function { SELECT y FROM t7 WHERE x = 1; } {5} - - +do_execsql_test_on_specific_db {:memory:} default-value-identifier { + CREATE TABLE t7 (x INTEGER PRIMARY KEY, y DEFAULT asdf); + INSERT INTO t7 (x) VALUES (1); + SELECT y FROM t7 WHERE x = 1; +} {asdf} diff --git a/testing/select.test b/testing/select.test index bfa214e81..cfa12ce17 100755 --- a/testing/select.test +++ b/testing/select.test @@ -261,15 +261,15 @@ do_execsql_test select-invalid-numeric-text { do_execsql_test_on_specific_db {:memory:} select-union-all-1 { CREATE TABLE t1 (x INTEGER); - CREATE TABLE t2 (x INTEGER); + CREATE TABLE t2 (x INTEGER); CREATE TABLE t3 (x INTEGER); - + INSERT INTO t1 VALUES(1),(2),(3); INSERT INTO t2 VALUES(4),(5),(6); INSERT INTO t3 VALUES(7),(8),(9); - + SELECT x FROM t1 - UNION ALL + UNION ALL SELECT x FROM t2 UNION ALL SELECT x FROM t3; @@ -287,14 +287,14 @@ do_execsql_test_on_specific_db {:memory:} select-union-all-with-filters { CREATE TABLE t4 (x INTEGER); CREATE TABLE t5 (x INTEGER); CREATE TABLE t6 (x INTEGER); - + INSERT INTO t4 VALUES(1),(2),(3),(4); INSERT INTO t5 VALUES(5),(6),(7),(8); INSERT INTO t6 VALUES(9),(10),(11),(12); SELECT x FROM t4 WHERE x > 2 UNION ALL - SELECT x FROM t5 WHERE x < 7 + SELECT x FROM t5 WHERE x < 7 UNION ALL SELECT x FROM t6 WHERE x = 10; } {3 @@ -786,4 +786,4 @@ do_execsql_test_on_specific_db {:memory:} rowid-references { AND "oid" = 2 AND `oid` = 2 AND [oid] = 2; -} {2|2|2|2|2|2|2|2|2|2|2|2} \ No newline at end of file +} {2|2|2|2|2|2|2|2|2|2|2|2}