From 8dc485e5f7970cd8f2e9316a773ba113ab1fe7ad Mon Sep 17 00:00:00 2001 From: Pavan-Nambi Date: Mon, 22 Sep 2025 16:24:22 +0530 Subject: [PATCH 1/3] don't allow duplicate columns and get column type more precisely --- core/schema.rs | 2 +- core/translate/alter.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/schema.rs b/core/schema.rs index 71cbb4932..05546a5e2 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -1294,7 +1294,7 @@ impl From<&ColumnDefinition> for Column { let ty_str = value .col_type .as_ref() - .map(|t| t.name.to_string()) + .map(|t| t.to_string()) .unwrap_or_default(); let hidden = ty_str.contains("HIDDEN"); diff --git a/core/translate/alter.rs b/core/translate/alter.rs index d3170fdbe..c07781f35 100644 --- a/core/translate/alter.rs +++ b/core/translate/alter.rs @@ -207,6 +207,13 @@ pub fn translate_alter_table( } } + let new_column_name = column.name.as_ref().unwrap(); + if btree.get_column(new_column_name).is_some() { + return Err(LimboError::ParseError( + "duplicate column name: ".to_string() + new_column_name, + )); + } + // TODO: All quoted ids will be quoted with `[]`, we should store some info from the parsed AST btree.columns.push(column.clone()); From cd1f1ce46efa3c3cd2acd78d760941365c7fc65e Mon Sep 17 00:00:00 2001 From: Pavan-Nambi Date: Mon, 22 Sep 2025 19:07:09 +0530 Subject: [PATCH 2/3] add tests for duplicate columns and column type fmt correct expected values spaces --- testing/alter_table.test | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/testing/alter_table.test b/testing/alter_table.test index e9e83c403..c7eac8c9f 100755 --- a/testing/alter_table.test +++ b/testing/alter_table.test @@ -133,6 +133,29 @@ do_execsql_test_in_memory_any_error fail-alter-table-drop-unique-column-constrai ALTER TABLE t DROP b; } + +# refer https://github.com/tursodatabase/turso/issues/3231 +do_execsql_test_in_memory_any_error fail-alter-table-add-duplicate-column { + CREATE TABLE t1 (a); + ALTER TABLE t1 ADD COLUMN a; +} +do_execsql_test_in_memory_any_error fail-alter-table-add-duplicate-column-case-insensitive { + CREATE TABLE t1 (a); + ALTER TABLE t1 ADD COLUMN A; +} +do_execsql_test_on_specific_db {:memory:} alter-table-add-column-type-should-be-same { + CREATE TABLE t1 (id integer); + ALTER TABLE t1 ADD COLUMN name varchar(255); + SELECT sql FROM sqlite_schema WHERE name = 't1'; +} { "CREATE TABLE t1 (id integer, name varchar (255))" } + +do_execsql_test_on_specific_db {:memory:} alter-table-add-column-type-should-be-same-2 { + CREATE TABLE t1 (a); + ALTER TABLE t1 ADD COLUMN price DECIMAL(10, 2); + SELECT sql FROM sqlite_schema WHERE name = 't1'; +} { "CREATE TABLE t1 (a, price DECIMAL (10, 2))" } + + do_execsql_test_in_memory_any_error fail-alter-table-drop-primary-key-column { CREATE TABLE t (a PRIMARY KEY, b); ALTER TABLE t DROP a; From 59660f0c2548bba67ee0d2b1060c45c96254df5b Mon Sep 17 00:00:00 2001 From: Pavan-Nambi Date: Tue, 23 Sep 2025 12:48:35 +0530 Subject: [PATCH 3/3] remove tests for column type spaces --- core/schema.rs | 2 +- testing/alter_table.test | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/core/schema.rs b/core/schema.rs index 05546a5e2..71cbb4932 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -1294,7 +1294,7 @@ impl From<&ColumnDefinition> for Column { let ty_str = value .col_type .as_ref() - .map(|t| t.to_string()) + .map(|t| t.name.to_string()) .unwrap_or_default(); let hidden = ty_str.contains("HIDDEN"); diff --git a/testing/alter_table.test b/testing/alter_table.test index c7eac8c9f..26f79cd67 100755 --- a/testing/alter_table.test +++ b/testing/alter_table.test @@ -143,18 +143,6 @@ do_execsql_test_in_memory_any_error fail-alter-table-add-duplicate-column-case-i CREATE TABLE t1 (a); ALTER TABLE t1 ADD COLUMN A; } -do_execsql_test_on_specific_db {:memory:} alter-table-add-column-type-should-be-same { - CREATE TABLE t1 (id integer); - ALTER TABLE t1 ADD COLUMN name varchar(255); - SELECT sql FROM sqlite_schema WHERE name = 't1'; -} { "CREATE TABLE t1 (id integer, name varchar (255))" } - -do_execsql_test_on_specific_db {:memory:} alter-table-add-column-type-should-be-same-2 { - CREATE TABLE t1 (a); - ALTER TABLE t1 ADD COLUMN price DECIMAL(10, 2); - SELECT sql FROM sqlite_schema WHERE name = 't1'; -} { "CREATE TABLE t1 (a, price DECIMAL (10, 2))" } - do_execsql_test_in_memory_any_error fail-alter-table-drop-primary-key-column { CREATE TABLE t (a PRIMARY KEY, b);