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/row.vala | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'qlite/src/row.vala') diff --git a/qlite/src/row.vala b/qlite/src/row.vala index 96762be3..8854656f 100644 --- a/qlite/src/row.vala +++ b/qlite/src/row.vala @@ -4,7 +4,7 @@ using Sqlite; namespace Qlite { public class Row { - private Map text_map = new HashMap(); + private Map text_map = new HashMap(); private Map int_map = new HashMap(); private Map real_map = new HashMap(); @@ -43,8 +43,8 @@ public class Row { return int_map.has_key(field); } - public double get_real(string field) { - return real_map[field]; + public double get_real(string field, double def = 0) { + return real_map[field] ?? def; } public bool has_real(string field) { @@ -71,11 +71,21 @@ public class RowIterator { } } - public Row? next_value() throws DatabaseError { + public bool next() { int r = stmt.step(); - if (r == Sqlite.ROW) return new Row(stmt); - if (r == Sqlite.DONE) return null; - throw new DatabaseError.EXEC_ERROR(@"SQLite error: $(db.errcode()) - $(db.errmsg())"); + if (r == Sqlite.ROW) return true; + if (r == Sqlite.DONE) return false; + print(@"SQLite error: $(db.errcode()) - $(db.errmsg())\n"); + return false; + } + + public Row get() { + return new Row(stmt); + } + + public Row? get_next() { + if (next()) return get(); + return null; } } @@ -91,8 +101,13 @@ public class RowOption { } public T get(Column field, T def = null) { - if (inner == null || field.is_null(inner)) return def; - return field[inner]; + if (inner == null || field.is_null((!)inner)) return def; + return field[(!)inner]; + } + + internal long get_integer(string field, long def = 0) { + if (inner == null || !((!)inner).has_integer(field)) return def; + return ((!)inner).get_integer(field); } } -- cgit v1.2.3-54-g00ecf