aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/insert_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/insert_builder.vala
parentc6ff3387fa7b23678bbfe644c9e1b668ac92a731 (diff)
downloaddino-765c2605cd0abf2b4431051142f09e2676584222.tar.gz
dino-765c2605cd0abf2b4431051142f09e2676584222.zip
qlite: cleanup, fix nullity issues
Diffstat (limited to 'qlite/src/insert_builder.vala')
-rw-r--r--qlite/src/insert_builder.vala30
1 files changed, 6 insertions, 24 deletions
diff --git a/qlite/src/insert_builder.vala b/qlite/src/insert_builder.vala
index 51030294..91388f69 100644
--- a/qlite/src/insert_builder.vala
+++ b/qlite/src/insert_builder.vala
@@ -6,14 +6,14 @@ public class InsertBuilder : StatementBuilder {
// INSERT [OR ...]
private bool replace_val;
- private string or_val;
+ private string? or_val;
// INTO [...]
private Table table;
private string table_name;
// VALUES [...]
- private StatementBuilder.Field[] fields;
+ private StatementBuilder.AbstractField[] fields = {};
internal InsertBuilder(Database db) {
base(db);
@@ -41,31 +41,13 @@ public class InsertBuilder : StatementBuilder {
}
public InsertBuilder value<T>(Column<T> column, T value) {
- if (fields == null) {
- fields = { new StatementBuilder.Field<T>(column, value) };
- } else {
- StatementBuilder.Field[] fields_new = new StatementBuilder.Field[fields.length+1];
- for (int i = 0; i < fields.length; i++) {
- fields_new[i] = fields[i];
- }
- fields_new[fields.length] = new Field<T>(column, value);
- fields = fields_new;
- }
+ fields += new Field<T>(column, value);
return this;
}
public InsertBuilder value_null<T>(Column<T> column) throws DatabaseError {
if (column.not_null) throw new DatabaseError.ILLEGAL_QUERY(@"Can't set non-null column $(column.name) to null");
- if (fields == null) {
- fields = { new NullField<T>(column) };
- } else {
- StatementBuilder.Field[] fields_new = new StatementBuilder.Field[fields.length+1];
- for (int i = 0; i < fields.length; i++) {
- fields_new[i] = fields[i];
- }
- fields_new[fields.length] = new NullField<T>(column);
- fields = fields_new;
- }
+ fields += new NullField<T>(column);
return this;
}
@@ -77,11 +59,11 @@ public class InsertBuilder : StatementBuilder {
value_qs += ", ";
fields_text += ", ";
}
- fields_text += fields[i].column.name;
+ fields_text += ((!)fields[i].column).name;
value_qs += "?";
}
string sql = replace_val ? "REPLACE" : "INSERT";
- if (!replace_val && or_val != null) sql += @" OR $or_val";
+ 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++) {