From 4bb2497d367717ea416d68ab724277daee7b3a6f Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Mon, 1 Sep 2025 11:24:12 -0400 Subject: [PATCH 1/6] Parser: translate true and false to 0 and 1 literals --- parser/src/parser.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 124058fc9..c392b628d 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -15,6 +15,9 @@ use crate::lexer::{Lexer, Token}; use crate::token::TokenType::{self, *}; use crate::Result; +const TRUE_LIT: &str = "TRUE"; +const FALSE_LIT: &str = "FALSE"; + macro_rules! peek_expect { ( $parser:expr, $( $x:ident ),* $(,)?) => { { @@ -1545,7 +1548,25 @@ impl<'a> Parser<'a> { Name::Ident(s) => Literal::String(s), }))) } else { - Ok(Box::new(Expr::Id(name))) + match name { + Name::Ident(s) => { + let ident = s.to_ascii_uppercase(); + match ident.as_str() { + TRUE_LIT => { + return Ok(Box::new(Expr::Literal(Literal::Numeric( + "1".into(), + )))) + } + FALSE_LIT => { + return Ok(Box::new(Expr::Literal(Literal::Numeric( + "0".into(), + )))) + } + _ => return Ok(Box::new(Expr::Id(Name::Ident(s)))), + } + } + _ => Ok(Box::new(Expr::Id(name))), + } } } } From 46182aa7ed891f8487bafe5224edb07122c0c63d Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Mon, 1 Sep 2025 11:25:10 -0400 Subject: [PATCH 2/6] add test for inserting boolean literals --- testing/insert.test | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/testing/insert.test b/testing/insert.test index be321b149..4550c4369 100755 --- a/testing/insert.test +++ b/testing/insert.test @@ -612,4 +612,14 @@ do_catchsql_test unknown-backtick-identifier-in-values-clause { do_execsql_test_in_memory_error_content null-insert-in-nulltype-column-notnull-constraint { CREATE TABLE test (id INTEGER,name NULL NOT NULL); INSERT INTO test (id, name) VALUES (1, NULL); -} {NOT NULL constraint failed} \ No newline at end of file +} {NOT NULL constraint failed} + +do_execsql_test_on_specific_db {:memory:} returning-true-literal { + CREATE TABLE test (id INTEGER, value TEXT); + INSERT INTO test (id, value) VALUES (1, true) RETURNING id, value; +} {1|1} + +do_execsql_test_on_specific_db {:memory:} returning-false-literal { + CREATE TABLE test (id INTEGER, value TEXT); + INSERT INTO test (id, value) VALUES (1, false) RETURNING id, value; +} {1|0} From 46f5565fafe2f53a499e6edc82e31a418317d648 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Mon, 1 Sep 2025 11:25:16 -0400 Subject: [PATCH 3/6] Add more tests for boolean literals --- testing/null.test | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/testing/null.test b/testing/null.test index 420f8b5d0..ec71af8a3 100755 --- a/testing/null.test +++ b/testing/null.test @@ -17,4 +17,12 @@ do_execsql_test notnull { do_execsql_test not-null { select null not null, 'hi' not null; -} {0|1} \ No newline at end of file +} {0|1} + +do_execsql_test sel-true { + select true; +}{1} + +do_execsql_test sel-false { + select false; +}{0} From bd9d6aa168f3eb96880d889152e6ba6c4d77a46a Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Mon, 1 Sep 2025 11:27:43 -0400 Subject: [PATCH 4/6] Add edge-case tests for boolean literals --- testing/insert.test | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/testing/insert.test b/testing/insert.test index 4550c4369..dbd20af3f 100755 --- a/testing/insert.test +++ b/testing/insert.test @@ -623,3 +623,13 @@ do_execsql_test_on_specific_db {:memory:} returning-false-literal { CREATE TABLE test (id INTEGER, value TEXT); INSERT INTO test (id, value) VALUES (1, false) RETURNING id, value; } {1|0} + +do_execsql_test_on_specific_db {:memory:} boolean-literal-edgecase { + CREATE TABLE true (id INTEGER, value TEXT); + INSERT INTO true (id, value) VALUES (1, true) RETURNING id, value; +} {1|1} + +do_execsql_test_on_specific_db {:memory:} boolean-literal-edgecase-false { + CREATE TABLE false (id INTEGER, true TEXT); + INSERT INTO false (id, true) VALUES (1, false) RETURNING id, false; +} {1|0} From f02e02af7589d2862416bd89000147ca29af24af Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Mon, 1 Sep 2025 11:39:43 -0400 Subject: [PATCH 5/6] Fix TCL test --- testing/null.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/null.test b/testing/null.test index ec71af8a3..682c23bfa 100755 --- a/testing/null.test +++ b/testing/null.test @@ -21,8 +21,8 @@ do_execsql_test not-null { do_execsql_test sel-true { select true; -}{1} +} {1} do_execsql_test sel-false { select false; -}{0} +} {0} From b76f9b773341cf3498e1e0de10e1177159719628 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Mon, 1 Sep 2025 12:32:33 -0400 Subject: [PATCH 6/6] Use eq_ignore_ascii_case in place of allocating new string in parser --- parser/src/parser.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/parser/src/parser.rs b/parser/src/parser.rs index c392b628d..b7a363030 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -1549,22 +1549,15 @@ impl<'a> Parser<'a> { }))) } else { match name { - Name::Ident(s) => { - let ident = s.to_ascii_uppercase(); - match ident.as_str() { - TRUE_LIT => { - return Ok(Box::new(Expr::Literal(Literal::Numeric( - "1".into(), - )))) - } - FALSE_LIT => { - return Ok(Box::new(Expr::Literal(Literal::Numeric( - "0".into(), - )))) - } - _ => return Ok(Box::new(Expr::Id(Name::Ident(s)))), + Name::Ident(s) => match s.as_str() { + s if s.eq_ignore_ascii_case(TRUE_LIT) => { + return Ok(Box::new(Expr::Literal(Literal::Numeric("1".into())))) } - } + s if s.eq_ignore_ascii_case(FALSE_LIT) => { + return Ok(Box::new(Expr::Literal(Literal::Numeric("0".into())))) + } + _ => return Ok(Box::new(Expr::Id(Name::Ident(s)))), + }, _ => Ok(Box::new(Expr::Id(name))), } }