aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/database.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-03-12 19:33:31 +0100
committerMarvin W <git@larma.de>2017-03-12 20:55:11 +0100
commitc2643a45b0dc05c4fd82ec7d32577700dae7450e (patch)
treed8a52d8eeee351f8279f9827b7e6d1b8024e7beb /qlite/src/database.vala
parent4f34e431163ac49e2c41079d44c5dd4a71b362d1 (diff)
downloaddino-c2643a45b0dc05c4fd82ec7d32577700dae7450e.tar.gz
dino-c2643a45b0dc05c4fd82ec7d32577700dae7450e.zip
Qlite: Return OptionalRow instead of Row?, add ability to remove columns on version upgrade
Diffstat (limited to 'qlite/src/database.vala')
-rw-r--r--qlite/src/database.vala20
1 files changed, 12 insertions, 8 deletions
diff --git a/qlite/src/database.vala b/qlite/src/database.vala
index 6d26b2b4..9fea7708 100644
--- a/qlite/src/database.vala
+++ b/qlite/src/database.vala
@@ -51,15 +51,19 @@ public class Database {
meta_table.create_table_at_version(expected_version);
long old_version = 0;
try {
- Row? row = meta_table.row_with(meta_name, "version");
- old_version = row == null ? -1 : (long) row[meta_int_val];
+ old_version = meta_table.row_with(meta_name, "version")[meta_int_val, -1];
} catch (DatabaseError e) {
old_version = -1;
}
- foreach (Table t in tables) {
- t.create_table_at_version(old_version);
- }
- if (expected_version != old_version) {
+ if (old_version == -1) {
+ foreach (Table t in tables) {
+ t.create_table_at_version(expected_version);
+ }
+ meta_table.insert().value(meta_name, "version").value(meta_int_val, expected_version).perform();
+ } else if (expected_version != old_version) {
+ foreach (Table t in tables) {
+ t.create_table_at_version(old_version);
+ }
foreach (Table t in tables) {
t.add_columns_for_version(old_version, expected_version);
}
@@ -117,9 +121,9 @@ public class Database {
return new DeleteBuilder(this);
}
- public Row.RowIterator query_sql(string sql, string[]? args = null) throws DatabaseError {
+ public RowIterator query_sql(string sql, string[]? args = null) throws DatabaseError {
ensure_init();
- return new Row.RowIterator(this, sql, args);
+ return new RowIterator(this, sql, args);
}
public Statement prepare(string sql) throws DatabaseError {