support sqlite's OR clauses in update statements (#1530)

This commit is contained in:
Ophir LOJKINE 2024-11-18 13:30:53 +01:00 committed by GitHub
parent a67a4f3cbe
commit 4c629e8520
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 59 additions and 26 deletions

View file

@ -443,6 +443,7 @@ fn parse_update_set_from() {
])),
}),
returning: None,
or: None,
}
);
}
@ -457,6 +458,7 @@ fn parse_update_with_table_alias() {
from: _from,
selection,
returning,
or: None,
} => {
assert_eq!(
TableWithJoins {
@ -505,6 +507,25 @@ fn parse_update_with_table_alias() {
}
}
#[test]
fn parse_update_or() {
let expect_or_clause = |sql: &str, expected_action: SqliteOnConflict| match verified_stmt(sql) {
Statement::Update { or, .. } => assert_eq!(or, Some(expected_action)),
other => unreachable!("Expected update with or, got {:?}", other),
};
expect_or_clause(
"UPDATE OR REPLACE t SET n = n + 1",
SqliteOnConflict::Replace,
);
expect_or_clause(
"UPDATE OR ROLLBACK t SET n = n + 1",
SqliteOnConflict::Rollback,
);
expect_or_clause("UPDATE OR ABORT t SET n = n + 1", SqliteOnConflict::Abort);
expect_or_clause("UPDATE OR FAIL t SET n = n + 1", SqliteOnConflict::Fail);
expect_or_clause("UPDATE OR IGNORE t SET n = n + 1", SqliteOnConflict::Ignore);
}
#[test]
fn parse_select_with_table_alias_as() {
// AS is optional