mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-03 23:34:24 +01:00
don't allow duplicate col names in create table
This commit is contained in:
@@ -40,6 +40,19 @@ pub fn translate_create_table(
|
||||
bail_parse_error!("TEMPORARY table not supported yet");
|
||||
}
|
||||
|
||||
// maybe we can do better than this.
|
||||
if let ast::CreateTableBody::ColumnsAndConstraints { columns, .. } = &body {
|
||||
for i in 0..columns.len() {
|
||||
let name1 = normalize_ident(columns[i].col_name.as_str());
|
||||
for j in (i + 1)..columns.len() {
|
||||
let name2 = normalize_ident(columns[j].col_name.as_str());
|
||||
if name1 == name2 {
|
||||
bail_parse_error!("duplicate column name: {}", columns[i].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()
|
||||
|
||||
@@ -53,3 +53,8 @@ do_execsql_test_on_specific_db {:memory:} col-named-rowid {
|
||||
update t set rowid = 1; -- should allow regular update and not throw unique constraint
|
||||
select count(*) from t where rowid = 1;
|
||||
} {3}
|
||||
|
||||
# https://github.com/tursodatabase/turso/issues/3637
|
||||
do_execsql_test_in_memory_any_error create_table_duplicate_column_names {
|
||||
CREATE TABLE t(a, a);
|
||||
}
|
||||
Reference in New Issue
Block a user