diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 124058fc9..b7a363030 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,18 @@ impl<'a> Parser<'a> { Name::Ident(s) => Literal::String(s), }))) } else { - Ok(Box::new(Expr::Id(name))) + match name { + 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))), + } } } } diff --git a/testing/insert.test b/testing/insert.test index be321b149..dbd20af3f 100755 --- a/testing/insert.test +++ b/testing/insert.test @@ -612,4 +612,24 @@ 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} + +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} diff --git a/testing/null.test b/testing/null.test index 420f8b5d0..682c23bfa 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}