impl ToSqlString for BEGIN stmt

This commit is contained in:
pedrocarlo
2025-05-27 20:39:37 -03:00
parent 2a2132e479
commit 4f736daa7c

View File

@@ -35,6 +35,16 @@ impl ToSqlString for ast::Stmt {
db_name.to_sql_string(context)
)
}
// TODO: not sure where name is applied here
// https://www.sqlite.org/lang_transaction.html
Self::Begin(transaction_type, _) => {
let t_type = transaction_type.map_or("", |t_type| match t_type {
ast::TransactionType::Deferred => "DEFERRED ",
ast::TransactionType::Exclusive => "EXCLUSIVE ",
ast::TransactionType::Immediate => "IMMEDIATE ",
});
format!("BEGIN {}TRANSACTION", t_type)
}
Self::Select(select) => select.to_sql_string(context),
_ => todo!(),
}
@@ -110,4 +120,12 @@ mod tests {
);
to_sql_string_test!(test_attach, "ATTACH './test.db' AS test_db");
to_sql_string_test!(test_transaction, "BEGIN TRANSACTION");
to_sql_string_test!(test_transaction_deferred, "BEGIN DEFERRED TRANSACTION");
to_sql_string_test!(test_transaction_immediate, "BEGIN IMMEDIATE TRANSACTION");
to_sql_string_test!(test_transaction_exclusive, "BEGIN EXCLUSIVE TRANSACTION");
}