Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ fn format_update(
));
}

if set_parts.is_empty() {
bail!("update has no SET assignments — would emit an empty SET clause");
}

let where_clause = primary_key_where_clause(&update.key, schema, injected_fields)?;

Ok(format!(
Expand Down Expand Up @@ -588,6 +592,28 @@ mod tests {
assert!(result.contains("INSERT INTO"));
}

#[test]
fn test_patch_to_sql_rejects_update_with_no_set_assignments() {
// A sparse update with empty `changed_indices` and empty `new_value`
// would render as `UPDATE "t" SET WHERE ...;` with an empty SET
// clause. Reject it instead of emitting malformed SQL.
let table_config = dummy_table(&[("id", true), ("name", false)]);
let config = dummy_config(HashMap::from([("test_table".to_string(), table_config)]));

let mut delta = dummy_delta(&["id", "name"]);
delta.updates.push(ProtoUpdate {
key: text_proto_values(&["1"]),
changed_indices: vec![],
old_value: vec![],
new_value: vec![],
});
let patch = dummy_patch(HashMap::from([("test_table".to_string(), delta)]));

let err = patch_to_sql(&config, &patch).unwrap_err();
let msg = format!("{:#}", err);
assert!(msg.contains("empty SET clause"), "got: {}", msg);
}

#[test]
fn test_patch_to_sql_rejects_out_of_range_changed_index() {
// Two-column table: id (PK) + name (subsidiary). An update whose
Expand Down
Loading