aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/insert_builder.vala
diff options
context:
space:
mode:
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++) {