From edaa1b675e1a23cca2bc50ada43c97c6a6c48fc2 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Thu, 16 Oct 2025 15:45:20 -0400 Subject: [PATCH] Prevent column definitions on CREATE TABLE or opening DB with ON CONFLICT on column def --- core/schema.rs | 25 +++++++++++++++++++++---- core/translate/schema.rs | 10 ++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/core/schema.rs b/core/schema.rs index c708b2f4d..ce30d3950 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -1641,8 +1641,14 @@ pub fn create_table(tbl_name: &str, body: &CreateTableBody, root_page: i64) -> R ast::ColumnConstraint::PrimaryKey { order: o, auto_increment, + conflict_clause, .. } => { + if conflict_clause.is_some() { + crate::bail_parse_error!( + "ON CONFLICT not implemented for column definition" + ); + } if !primary_key_columns.is_empty() { crate::bail_parse_error!( "table \"{}\" has more than one primary key", @@ -1661,7 +1667,16 @@ pub fn create_table(tbl_name: &str, body: &CreateTableBody, root_page: i64) -> R is_primary_key: true, }); } - ast::ColumnConstraint::NotNull { nullable, .. } => { + ast::ColumnConstraint::NotNull { + nullable, + conflict_clause, + .. + } => { + if conflict_clause.is_some() { + crate::bail_parse_error!( + "ON CONFLICT not implemented for column definition" + ); + } notnull = !nullable; } ast::ColumnConstraint::Default(ref expr) => { @@ -1670,9 +1685,11 @@ pub fn create_table(tbl_name: &str, body: &CreateTableBody, root_page: i64) -> R ); } // TODO: for now we don't check Resolve type of unique - ast::ColumnConstraint::Unique(on_conflict) => { - if on_conflict.is_some() { - unimplemented!("ON CONFLICT not implemented"); + ast::ColumnConstraint::Unique(conflict) => { + if conflict.is_some() { + crate::bail_parse_error!( + "ON CONFLICT not implemented for column definition" + ); } unique = true; unique_sets.push(UniqueSet { diff --git a/core/translate/schema.rs b/core/translate/schema.rs index 120ad5ce9..0442b5542 100644 --- a/core/translate/schema.rs +++ b/core/translate/schema.rs @@ -48,6 +48,16 @@ fn validate(body: &ast::CreateTableBody, connection: &Connection) -> Result<()> ast::ColumnConstraint::Generated { .. } => { bail_parse_error!("GENERATED columns are not supported yet"); } + ast::ColumnConstraint::NotNull { + conflict_clause, .. + } + | ast::ColumnConstraint::PrimaryKey { + conflict_clause, .. + } if conflict_clause.is_some() => { + bail_parse_error!( + "ON CONFLICT clauses are not supported yet in column definitions" + ); + } _ => {} } }