Merge 'parser: translate boolean values to literal when parsing column constraints' from Preston Thorpe

closes #3796

Closes #3804
This commit is contained in:
Pekka Enberg
2025-10-22 09:11:03 +03:00
committed by GitHub
2 changed files with 25 additions and 3 deletions

View File

@@ -3120,9 +3120,17 @@ impl<'a> Parser<'a> {
TK_NULL | TK_BLOB | TK_STRING | TK_FLOAT | TK_INTEGER | TK_CTIME_KW => {
Ok(ColumnConstraint::Default(self.parse_term()?))
}
_ => Ok(ColumnConstraint::Default(Box::new(Expr::Id(
self.parse_nm()?,
)))),
_ => {
let name = self.parse_nm()?;
let expr = if name.as_str().eq_ignore_ascii_case("true") {
Expr::Literal(Literal::Numeric("1".into()))
} else if name.as_str().eq_ignore_ascii_case("false") {
Expr::Literal(Literal::Numeric("0".into()))
} else {
Expr::Id(name)
};
Ok(ColumnConstraint::Default(Box::new(expr)))
}
}
}

View File

@@ -101,3 +101,17 @@ do_execsql_test_in_memory_any_error create_view_index_collision-1 {
CREATE INDEX ix_same ON t4(w);
CREATE VIEW ix_same AS SELECT 1;
}
# https://github.com/tursodatabase/turso/issues/3796
do_execsql_test_on_specific_db {:memory:} col-default-true {
create table t(id integer primary key, a default true);
insert into t (id) values (1);
SELECT a from t;
} {1}
# https://github.com/tursodatabase/turso/issues/3796
do_execsql_test_on_specific_db {:memory:} col-default-false {
create table t(id integer primary key, a default false);
insert into t (id) values (1);
SELECT a from t;
} {0}