From b3351dc709feb08b7ca34178f09b113cdce6689d Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Sat, 14 Jun 2025 15:43:47 -0300 Subject: [PATCH] tests + adjustment to halt error message --- core/translate/emitter.rs | 24 ++++++++++++------------ core/translate/main_loop.rs | 4 ++-- testing/update.test | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/core/translate/emitter.rs b/core/translate/emitter.rs index 19d9fb05a..576d0a0a1 100644 --- a/core/translate/emitter.rs +++ b/core/translate/emitter.rs @@ -22,9 +22,9 @@ use super::select::emit_simple_count; use super::subquery::emit_subqueries; use crate::error::SQLITE_CONSTRAINT_PRIMARYKEY; use crate::function::Func; -use crate::schema::{Index, IndexColumn, Schema}; -use crate::translate::main_loop::EphemeralCtx; +use crate::schema::Schema; use crate::translate::compound_select::emit_program_for_compound_select; +use crate::translate::main_loop::EphemeralCtx; use crate::translate::plan::{DeletePlan, Plan, Search}; use crate::translate::values::emit_values; use crate::util::exprs_are_equivalent; @@ -852,20 +852,20 @@ fn emit_update_insns( // Check if rowid was provided (through INTEGER PRIMARY KEY as a rowid alias) - let rowid_alias_index = { - let rowid_alias_index = table_ref.columns().iter().position(|c| c.is_rowid_alias); - if let Some(index) = rowid_alias_index { - plan.set_clauses.iter().position(|(idx, _)| *idx == index) - } else { - None - } - }; - let rowid_set_clause_reg = if rowid_alias_index.is_some() { + let rowid_alias_index = table_ref.columns().iter().position(|c| c.is_rowid_alias); + + let has_user_provided_rowid = if let Some(index) = rowid_alias_index { + plan.set_clauses.iter().position(|(idx, _)| *idx == index) + } else { + None + } + .is_some(); + + let rowid_set_clause_reg = if has_user_provided_rowid { Some(program.alloc_register()) } else { None }; - let has_user_provided_rowid = rowid_alias_index.is_some(); let check_rowid_not_exists_label = if has_user_provided_rowid { Some(program.allocate_label()) diff --git a/core/translate/main_loop.rs b/core/translate/main_loop.rs index e5cd8b899..d44f3d5d8 100644 --- a/core/translate/main_loop.rs +++ b/core/translate/main_loop.rs @@ -130,9 +130,9 @@ impl<'a> EphemeralCtx<'a> { name: Some("rowid".to_string()), ty: Type::Integer, ty_str: "INTEGER".to_string(), - primary_key: false, + primary_key: true, is_rowid_alias: false, - notnull: false, + notnull: true, default: None, unique: false, collation: None, diff --git a/testing/update.test b/testing/update.test index bf64a196b..c07cf5aa9 100755 --- a/testing/update.test +++ b/testing/update.test @@ -221,3 +221,35 @@ do_execsql_test_in_memory_any_error update_primary_key_constraint_error { INSERT INTO eye VALUES (78255586.9204539, x'651061e8', 'World perhaps.', -5815764.49018679, 1917); UPDATE eye SET election = 6150; } + +do_execsql_test_in_memory_any_error update_primary_key_constraint_error_2 { + CREATE TABLE eye (study REAL, spring BLOB, save TEXT, thank REAL, election INTEGER, PRIMARY KEY (election)); + INSERT INTO eye VALUES (183559032.521585, x'6625d092', 'Trial six should.', 2606132742.43174, 2817); + INSERT INTO eye VALUES (78255586.9204539, x'651061e8', 'World perhaps.', -5815764.49018679, 1917); + INSERT INTO eye VALUES (53.3274327094467, x'f574c507', 'Senior wish degree.', -423.432750526747, 2650); + INSERT INTO eye VALUES (-908148213048.983, x'6d812051', 'Possible able.', 101.171781837336, 4100); + INSERT INTO eye VALUES (-572332773760.924, x'd7a4d9fb', 'Money catch expect.', -271065488.756746, 4667); + UPDATE eye SET election = 6150 WHERE election != 1917; +} + +do_execsql_test_in_memory_any_error update_primary_key_constraint_error_3 { + CREATE TABLE eye (study REAL, spring BLOB, save TEXT, thank REAL, election INTEGER, PRIMARY KEY (election)); + INSERT INTO eye VALUES (183559032.521585, x'6625d092', 'Trial six should.', 2606132742.43174, 2817); + INSERT INTO eye VALUES (78255586.9204539, x'651061e8', 'World perhaps.', -5815764.49018679, 1917); + INSERT INTO eye VALUES (53.3274327094467, x'f574c507', 'Senior wish degree.', -423.432750526747, 2650); + INSERT INTO eye VALUES (-908148213048.983, x'6d812051', 'Possible able.', 101.171781837336, 4100); + INSERT INTO eye VALUES (-572332773760.924, x'd7a4d9fb', 'Money catch expect.', -271065488.756746, 4667); + UPDATE eye SET election = 6150 WHERE election > 1000 AND study > 1; +} + +do_execsql_test_in_memory_any_error update_primary_key_constraint_error_4 { + CREATE TABLE t(a PRIMARY KEY INTEGER, b UNIQUE); + INSERT INTO t(b) VALUES (100), (200), (300); + UPDATE t SET a = 1; +} + +do_execsql_test_in_memory_any_error update_primary_key_unique_constraint_error { + CREATE TABLE t(a PRIMARY KEY INTEGER, b UNIQUE); + INSERT INTO t(b) VALUES (100), (200), (300); + UPDATE t SET b = 2; +}