aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/update_builder.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2026-08-23 19:32:25 +0200
committerMarvin W <git@larma.de>2026-10-23 16:59:51 +0200
commit98ef191bfb3cc5694b9d1001e46a9b00abbd7195 (patch)
treeb6d30b203266afe44f0b5ae8aaf479960e361273 /qlite/src/update_builder.vala
parentb0456e13ed35e6ebf684b3a7f4d1cb4b6ec352cc (diff)
Move qlite into libdino
Diffstat (limited to 'qlite/src/update_builder.vala')
-rw-r--r--qlite/src/update_builder.vala103
1 files changed, 0 insertions, 103 deletions
diff --git a/qlite/src/update_builder.vala b/qlite/src/update_builder.vala
deleted file mode 100644
index 0bf83aee..00000000
--- a/qlite/src/update_builder.vala
+++ /dev/null
@@ -1,103 +0,0 @@
-using Sqlite;
-
-namespace Qlite {
-
-public class UpdateBuilder : StatementBuilder {
-
- // UPDATE [OR ...]
- private string? or_val;
-
- // [...]
- private Table? table;
- private string table_name;
-
- // SET [...]
- private StatementBuilder.AbstractField[] fields = {};
-
- // WHERE [...]
- private string selection = "1";
- private StatementBuilder.AbstractField[] selection_args = {};
-
- internal UpdateBuilder(Database db, Table table) {
- base(db);
- this.table = table;
- this.table_name = table.name;
- }
-
- internal UpdateBuilder.for_name(Database db, string table) {
- base(db);
- this.table_name = table;
- }
-
- public UpdateBuilder or(string or) {
- this.or_val = or;
- return this;
- }
-
- public UpdateBuilder set<T>(Column<T> column, T value) {
- fields += new Field<T>(column, value);
- return this;
- }
-
- public UpdateBuilder set_null<T>(Column<T> column) {
- if (column.not_null) error("Can't set non-null column %s to null", column.name);
- fields += new NullField<T>(column);
- return this;
- }
-
- public UpdateBuilder where(string selection, string[] selection_args = {}) {
- 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 UpdateBuilder with<T>(Column<T> column, string comp, T value) {
- selection_args += new Field<T>(column, value);
- selection = @"($selection) AND $(column.name) $comp ?";
- return this;
- }
-
- public UpdateBuilder with_null<T>(Column<T> column) {
- selection = @"($selection) AND $(column.name) ISNULL";
- return this;
- }
-
- public UpdateBuilder without_null<T>(Column<T> column) {
- selection = @"($selection) AND $(column.name) NOT NULL";
- return this;
- }
-
- internal override Statement prepare() {
- string sql = "UPDATE";
- if (or_val != null) sql += @" OR $((!)or_val)";
- sql += @" $table_name SET ";
- for (int i = 0; i < fields.length; i++) {
- if (i != 0) {
- sql += ", ";
- }
- sql += @"$(((!)fields[i].column).name) = ?";
- }
- sql += @" WHERE $selection";
- Statement stmt = db.prepare(sql);
- for (int i = 0; i < fields.length; i++) {
- fields[i].bind(stmt, i+1);
- }
- for (int i = 0; i < selection_args.length; i++) {
- selection_args[i].bind(stmt, i + fields.length + 1);
- }
- return stmt;
- }
-
- public void perform() {
- if (fields.length == 0) return;
- if (prepare().step() != DONE) {
- critical("SQLite error: %d - %s", db.errcode(), db.errmsg());
- }
- }
-
-}
-
-}