aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/delete_builder.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-04-16 15:11:00 +0200
committerMarvin W <git@larma.de>2017-04-18 20:20:41 +0200
commit765c2605cd0abf2b4431051142f09e2676584222 (patch)
treef01d7a6822adfc47c47f5a0e1ebd048d9dad00d4 /qlite/src/delete_builder.vala
parentc6ff3387fa7b23678bbfe644c9e1b668ac92a731 (diff)
downloaddino-765c2605cd0abf2b4431051142f09e2676584222.tar.gz
dino-765c2605cd0abf2b4431051142f09e2676584222.zip
qlite: cleanup, fix nullity issues
Diffstat (limited to 'qlite/src/delete_builder.vala')
-rw-r--r--qlite/src/delete_builder.vala31
1 files changed, 9 insertions, 22 deletions
diff --git a/qlite/src/delete_builder.vala b/qlite/src/delete_builder.vala
index 8e4afb06..5483b652 100644
--- a/qlite/src/delete_builder.vala
+++ b/qlite/src/delete_builder.vala
@@ -5,12 +5,12 @@ namespace Qlite {
public class DeleteBuilder : StatementBuilder {
// DELETE FROM [...]
- private Table table;
+ private Table? table;
private string table_name;
// WHERE [...]
- private string selection;
- private StatementBuilder.Field[] selection_args;
+ private string selection = "1";
+ private StatementBuilder.AbstractField[] selection_args = {};
internal DeleteBuilder(Database db) {
base(db);
@@ -29,35 +29,22 @@ public class DeleteBuilder : StatementBuilder {
}
public DeleteBuilder where(string selection, string[]? selection_args = null) throws DatabaseError {
- if (this.selection != null) throw new DatabaseError.ILLEGAL_QUERY("selection was already done, but where() was called.");
+ if (this.selection != "1") throw new DatabaseError.ILLEGAL_QUERY("selection was already done, but where() was called.");
this.selection = selection;
- if (selection_args != null) {
- this.selection_args = new StatementBuilder.Field[selection_args.length];
- for (int i = 0; i < selection_args.length; i++) {
- this.selection_args[i] = new StatementBuilder.StringField(selection_args[i]);
- }
+ 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) {
- if (selection == null) {
- selection = @"$(column.name) $comp ?";
- selection_args = { new StatementBuilder.Field<T>(column, value) };
- } else {
- selection = @"($selection) AND $(column.name) $comp ?";
- StatementBuilder.Field[] selection_args_new = new StatementBuilder.Field[selection_args.length+1];
- for (int i = 0; i < selection_args.length; i++) {
- selection_args_new[i] = selection_args[i];
- }
- selection_args_new[selection_args.length] = new Field<T>(column, value);
- selection_args = selection_args_new;
- }
+ selection_args += new Field<T>(column, value);
+ selection = @"($selection) AND $(column.name) $comp ?";
return this;
}
internal override Statement prepare() throws DatabaseError {
- Statement stmt = db.prepare(@"DELETE FROM $table_name $(selection != null ? @"WHERE $selection": "")");
+ 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);
}