Merge 'Prevent on conflict column definitions on CREATE TABLE or opening DB' from Preston Thorpe

more parse errors!

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3760
This commit is contained in:
Preston Thorpe
2025-10-16 16:22:40 -04:00
committed by GitHub
2 changed files with 31 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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"
);
}
_ => {}
}
}