diff --git a/core/schema.rs b/core/schema.rs index d92c6e612..b744a99a5 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -1632,6 +1632,9 @@ pub fn create_table(tbl_name: &str, body: &CreateTableBody, root_page: i64) -> R let mut collation = None; for c_def in constraints { match &c_def.constraint { + ast::ColumnConstraint::Check { .. } => { + crate::bail_parse_error!("CHECK constraints are not yet supported"); + } ast::ColumnConstraint::PrimaryKey { order: o, auto_increment, diff --git a/core/translate/schema.rs b/core/translate/schema.rs index 5bf0e3682..152cca652 100644 --- a/core/translate/schema.rs +++ b/core/translate/schema.rs @@ -26,6 +26,39 @@ use crate::{bail_parse_error, Result}; use turso_ext::VTabKind; +fn validate(body: &ast::CreateTableBody, connection: &Connection) -> Result<()> { + if let ast::CreateTableBody::ColumnsAndConstraints { + options, columns, .. + } = &body + { + if options.contains(ast::TableOptions::STRICT) && !connection.experimental_strict_enabled() + { + bail_parse_error!( + "STRICT tables are an experimental feature. Enable them with --experimental-strict flag" + ); + } + for i in 0..columns.len() { + let col_i = &columns[i]; + for constraint in &col_i.constraints { + // don't silently ignore CHECK constraints, throw parse error for now + if let ast::ColumnConstraint::Check { .. } = constraint.constraint { + bail_parse_error!("CHECK constraints are not supported yet"); + } + } + for j in &columns[(i + 1)..] { + if col_i + .col_name + .as_str() + .eq_ignore_ascii_case(j.col_name.as_str()) + { + bail_parse_error!("duplicate column name: {}", j.col_name.as_str()); + } + } + } + } + Ok(()) +} + pub fn translate_create_table( tbl_name: ast::QualifiedName, resolver: &Resolver, @@ -39,32 +72,8 @@ pub fn translate_create_table( if temporary { bail_parse_error!("TEMPORARY table not supported yet"); } + validate(&body, connection)?; - if let ast::CreateTableBody::ColumnsAndConstraints { columns, .. } = &body { - for i in 0..columns.len() { - let col_i = &columns[i]; - - for j in &columns[(i + 1)..] { - if col_i - .col_name - .as_str() - .eq_ignore_ascii_case(j.col_name.as_str()) - { - bail_parse_error!("duplicate column name: {}", j.col_name.as_str()); - } - } - } - } - - // Check for STRICT mode without experimental flag - if let ast::CreateTableBody::ColumnsAndConstraints { options, .. } = &body { - if options.contains(ast::TableOptions::STRICT) && !connection.experimental_strict_enabled() - { - bail_parse_error!( - "STRICT tables are an experimental feature. Enable them with --experimental-strict flag" - ); - } - } let opts = ProgramBuilderOpts { num_cursors: 1, approx_num_insns: 30,