From 765c2605cd0abf2b4431051142f09e2676584222 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sun, 16 Apr 2017 15:11:00 +0200 Subject: qlite: cleanup, fix nullity issues --- qlite/src/delete_builder.vala | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'qlite/src/delete_builder.vala') 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(Column column, string comp, T value) { - if (selection == null) { - selection = @"$(column.name) $comp ?"; - selection_args = { new StatementBuilder.Field(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(column, value); - selection_args = selection_args_new; - } + selection_args += new Field(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); } -- cgit v1.2.3-54-g00ecf