diff options
| author | Marvin W <git@larma.de> | 2026-08-23 19:32:25 +0200 |
|---|---|---|
| committer | Marvin W <git@larma.de> | 2026-10-23 16:59:51 +0200 |
| commit | 98ef191bfb3cc5694b9d1001e46a9b00abbd7195 (patch) | |
| tree | b6d30b203266afe44f0b5ae8aaf479960e361273 /libdino/src/qlite/delete_builder.vala | |
| parent | b0456e13ed35e6ebf684b3a7f4d1cb4b6ec352cc (diff) | |
Move qlite into libdino
Diffstat (limited to 'libdino/src/qlite/delete_builder.vala')
| -rw-r--r-- | libdino/src/qlite/delete_builder.vala | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/libdino/src/qlite/delete_builder.vala b/libdino/src/qlite/delete_builder.vala new file mode 100644 index 00000000..df63bba6 --- /dev/null +++ b/libdino/src/qlite/delete_builder.vala @@ -0,0 +1,62 @@ +using Sqlite; + +namespace Dino.Qlite { + +public class DeleteBuilder : StatementBuilder { + + // DELETE FROM [...] + private Table? table; + private string table_name; + + // WHERE [...] + private string selection = "1"; + private StatementBuilder.AbstractField[] selection_args = {}; + + internal DeleteBuilder(Database db) { + base(db); + } + + public DeleteBuilder from(Table table) { + if (this.table != null) error("Qlite Error: ILLEGAL QUERY: cannot use from() multiple times."); + this.table = table; + this.table_name = table.name; + return this; + } + + public DeleteBuilder from_name(string table) { + this.table_name = table; + return this; + } + + public DeleteBuilder where(string selection, string[]? selection_args = null) { + if (this.selection != "1") error("selection was already done, but where() was called."); + this.selection = selection; + foreach (string arg in selection_args) { + this.selection_args += new StatementBuilder.StringField(arg); + } + return this; + } + + public DeleteBuilder with<T>(Column<T> column, string comp, T value) { + selection_args += new Field<T>(column, value); + selection = @"($selection) AND $(column.name) $comp ?"; + return this; + } + + internal override Statement prepare() { + Statement stmt = db.prepare(@"DELETE FROM $table_name WHERE $selection"); + for (int i = 0; i < selection_args.length; i++) { + selection_args[i].bind(stmt, i+1); + } + return stmt; + } + + public void perform() { + if (prepare().step() != DONE) { + critical(@"SQLite error: %d - %s", db.errcode(), db.errmsg()); + } + } + +} + +} |
