diff --git a/core/translate/index.rs b/core/translate/index.rs index 1100aa27e..b79d9d834 100644 --- a/core/translate/index.rs +++ b/core/translate/index.rs @@ -353,6 +353,15 @@ pub fn translate_drop_index( ))); } } + // Return an error if the index is associated with a unique or primary key constraint. + if let Some(idx) = maybe_index { + if idx.unique { + return Err(crate::error::LimboError::InvalidArgument( + "index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped" + .to_string(), + )); + } + } let cdc_table = prepare_cdc_if_necessary(&mut program, schema, SQLITE_TABLEID)?; diff --git a/testing/drop_index.test b/testing/drop_index.test index 4edbfc2bc..7ddc21a45 100755 --- a/testing/drop_index.test +++ b/testing/drop_index.test @@ -44,3 +44,15 @@ do_execsql_test_on_specific_db {:memory:} drop-index-after-ops-1 { DROP INDEX t_idx6; SELECT count(*) FROM sqlite_schema WHERE type='index' AND name='t_idx6'; } {0} + +# Test dropping of indices associated with unique or primary contraint indices produces an error +do_execsql_test_in_memory_error_content drop-index-primary-key-index { + CREATE TABLE t15a (id TEXT PRIMARY KEY ); + DROP INDEX sqlite_autoindex_t15a_1; +} {"index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped"} + + +do_execsql_test_in_memory_error_content drop-index-unique-index { + CREATE TABLE t15b (id INT UNIQUE ); + DROP INDEX sqlite_autoindex_t15b_1; +} {"index associated with UNIQUE or PRIMARY KEY constraint cannot be dropped"} \ No newline at end of file diff --git a/testing/tester.tcl b/testing/tester.tcl index 98d06f26f..6fbfa2dd5 100644 --- a/testing/tester.tcl +++ b/testing/tester.tcl @@ -191,9 +191,13 @@ proc run_test_expecting_error_content {sqlite_exec db_name sql expected_error_te exit 1 } + # Remove box-drawing characters, multiplication signs, and other non-ASCII junk + set cleaned_result [regsub -all {[\u2500-\u257F\u00D7]} $result ""] + #TODO any other possible cleanups? + # Normalize both the actual and expected error messages # Remove all whitespace, newlines, and special characters for comparison - set normalized_actual [regsub -all {[[:space:]]|[[:punct:]]} $result ""] + set normalized_actual [regsub -all {[[:space:]]|[[:punct:]]} $cleaned_result ""] set normalized_expected [regsub -all {[[:space:]]|[[:punct:]]} $expected_error_text ""] # Convert to lowercase for case-insensitive comparison