mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-06 00:34:23 +01:00
Throw parse error on CHECK constraint in create table
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user