aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/insert_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/insert_builder.vala
parentb0456e13ed35e6ebf684b3a7f4d1cb4b6ec352cc (diff)
Move qlite into libdino
Diffstat (limited to 'qlite/src/insert_builder.vala')
-rw-r--r--qlite/src/insert_builder.vala84
1 files changed, 0 insertions, 84 deletions
diff --git a/qlite/src/insert_builder.vala b/qlite/src/insert_builder.vala
deleted file mode 100644
index 8b14b33f..00000000
--- a/qlite/src/insert_builder.vala
+++ /dev/null
@@ -1,84 +0,0 @@
-using Sqlite;
-
-namespace Qlite {
-
-public class InsertBuilder : StatementBuilder {
-
- // INSERT [OR ...]
- private bool replace_val;
- private string? or_val;
-
- // INTO [...]
- private Table table;
- private string table_name;
-
- // VALUES [...]
- private StatementBuilder.AbstractField[] fields = {};
-
- internal InsertBuilder(Database db) {
- base(db);
- }
-
- public InsertBuilder replace() {
- this.replace_val = true;
- return this;
- }
-
- public InsertBuilder or(string or) {
- this.or_val = or;
- return this;
- }
-
- public InsertBuilder into(Table table) {
- this.table = table;
- this.table_name = table.name;
- return this;
- }
-
- public InsertBuilder into_name(string table) {
- this.table_name = table;
- return this;
- }
-
- public InsertBuilder value<T>(Column<T> column, T value) {
- fields += new Field<T>(column, value);
- return this;
- }
-
- public InsertBuilder value_null<T>(Column<T> column) {
- if (column.not_null) error("Qlite Error: ILLEGAL QUERY: Can't set non-null column %s to null", column.name);
- fields += new NullField<T>(column);
- return this;
- }
-
- internal override Statement prepare() {
- string fields_text = "";
- string value_qs = "";
- for (int i = 0; i < fields.length; i++) {
- if (i != 0) {
- value_qs += ", ";
- fields_text += ", ";
- }
- fields_text += ((!)fields[i].column).name;
- value_qs += "?";
- }
- string sql = replace_val ? "REPLACE" : "INSERT";
- if (!replace_val && or_val != null) sql += @" OR $((!)or_val)";
- sql += @" INTO $table_name ( $fields_text ) VALUES ($value_qs)";
- Statement stmt = db.prepare(sql);
- for (int i = 0; i < fields.length; i++) {
- fields[i].bind(stmt, i+1);
- }
- return stmt;
- }
-
- public int64 perform() {
- if (prepare().step() != DONE) {
- critical(@"SQLite error: %d - %s", db.errcode(), db.errmsg());
- }
- return db.last_insert_rowid();
- }
-
-}
-
-}