diff --git a/core/vdbe/builder.rs b/core/vdbe/builder.rs index 7aad796b..0d8dea8d 100644 --- a/core/vdbe/builder.rs +++ b/core/vdbe/builder.rs @@ -611,10 +611,6 @@ impl ProgramBuilder { self.collation = None; } - // pub fn pop_collation(&mut self) -> Option { - // self.collations.pop() - // } - pub fn build( mut self, database_header: Arc>, diff --git a/core/vdbe/execute.rs b/core/vdbe/execute.rs index 8a153044..a05a9f73 100644 --- a/core/vdbe/execute.rs +++ b/core/vdbe/execute.rs @@ -934,15 +934,11 @@ pub fn op_open_read( .replace(Cursor::new_btree(cursor)); } CursorType::BTreeIndex(index) => { - let table = program.table_references.iter().find_map(|table_ref| { - table_ref.btree().and_then(|table| { - if table.name == index.table_name { - Some(table) - } else { - None - } - }) - }); + let conn = program.connection.upgrade().unwrap(); + let schema = conn.schema.try_read().ok_or(LimboError::SchemaLocked)?; + let table = schema + .get_table(&index.table_name) + .map_or(None, |table| table.btree()); let collations = table.map_or(Vec::new(), |table| { table .column_collations() @@ -4243,15 +4239,11 @@ pub fn op_open_write( None => None, }; if let Some(index) = maybe_index { - let table = program.table_references.iter().find_map(|table_ref| { - table_ref.btree().and_then(|table| { - if table.name == index.table_name { - Some(table) - } else { - None - } - }) - }); + let conn = program.connection.upgrade().unwrap(); + let schema = conn.schema.try_read().ok_or(LimboError::SchemaLocked)?; + let table = schema + .get_table(&index.table_name) + .map_or(None, |table| table.btree()); let collations = table.map_or(Vec::new(), |table| { table .column_collations() diff --git a/testing/collate.test b/testing/collate.test index 094e855a..f5067072 100755 --- a/testing/collate.test +++ b/testing/collate.test @@ -5,38 +5,43 @@ source $testdir/tester.tcl # SIMPLE SMOKE TESTS THAT DO NOT DEPEND ON SPECIFIC DATABASE ROWS -do_execsql_test collate-nocase { +do_execsql_test collate_nocase { SELECT 'hat' == 'hAt' COLLATE NOCASE; } {1} -do_execsql_test collate-binary-1 { +do_execsql_test collate_binary_1 { SELECT 'hat' == 'hAt' COLLATE BINARY; } {0} -do_execsql_test collate-binary-2 { +do_execsql_test collate_binary_2 { SELECT 'hat' == 'hat' COLLATE BINARY; } {1} -do_execsql_test collate-rtrim-1 { +do_execsql_test collate_rtrim_1 { SELECT 'hat' == 'hAt ' COLLATE RTRIM; } {0} -do_execsql_test collate-rtrim-2 { +do_execsql_test collate_rtrim_2 { SELECT 'hat' == 'hat ' COLLATE RTRIM; } {1} -do_execsql_test collate-rtrim-3 { +do_execsql_test collate_rtrim_3 { SELECT 'hat' == ' hAt ' COLLATE RTRIM; } {0} -do_execsql_test collate-rtrim-4 { +do_execsql_test collate_rtrim_4 { SELECT 'hat' == ' hat ' COLLATE RTRIM; } {0} -do_execsql_test collate-left-precedence { +do_execsql_test collate_left_precedence { SELECT 'hat' COLLATE BINARY == 'hAt' COLLATE NOCASE; } {0} -do_execsql_test collate-left-precedence-2 { +do_execsql_test collate_left_precedence_2 { SELECT 'hat' COLLATE NOCASE == 'hAt' COLLATE BINARY; } {1} + +do_execsql_test_in_memory_error_content collate_unique_constraint { + CREATE TABLE t(a TEXT COLLATE NOCASE PRIMARY KEY); + INSERT INTO t VALUES ('lol'), ('LOL'), ('lOl'); +} {Runtime error: UNIQUE constraint failed: t.a (19)} diff --git a/testing/tester.tcl b/testing/tester.tcl index d739b2a3..490a0f39 100644 --- a/testing/tester.tcl +++ b/testing/tester.tcl @@ -226,3 +226,13 @@ proc do_execsql_test_in_memory_any_error {test_name sql_statements} { set combined_sql [string trim $sql_statements] run_test_expecting_any_error $::sqlite_exec $db_name $combined_sql } + +proc do_execsql_test_in_memory_error_content {test_name sql_statements expected_error_text} { + test_put "Running error content test" in-memory $test_name + + # Use ":memory:" special filename for in-memory database + set db_name ":memory:" + + set combined_sql [string trim $sql_statements] + run_test_expecting_error_content $::sqlite_exec $db_name $combined_sql $expected_error_text +}