aboutsummaryrefslogtreecommitdiff
path: root/qlite
diff options
context:
space:
mode:
Diffstat (limited to 'qlite')
-rw-r--r--qlite/src/query_builder.vala10
-rw-r--r--qlite/src/table.vala4
2 files changed, 11 insertions, 3 deletions
diff --git a/qlite/src/query_builder.vala b/qlite/src/query_builder.vala
index dbfdef2a..75fe0499 100644
--- a/qlite/src/query_builder.vala
+++ b/qlite/src/query_builder.vala
@@ -98,10 +98,16 @@ public class QueryBuilder : StatementBuilder {
}
public QueryBuilder limit(int limit) {
+ if (this.limit_val != 0 && limit > this.limit_val) error("tried to increase an existing limit");
this.limit_val = limit;
return this;
}
+ public QueryBuilder single() {
+ this.single_result = true;
+ return limit(1);
+ }
+
public int64 count() {
this.column_selector = @"COUNT($column_selector) AS count";
this.single_result = true;
@@ -117,8 +123,8 @@ public class QueryBuilder : StatementBuilder {
return new RowOption(row_());
}
- public T get<T>(Column<T> field) {
- return row()[field];
+ public T get<T>(Column<T> field, T def = null) {
+ return row().get(field, def);
}
internal override Statement prepare() {
diff --git a/qlite/src/table.vala b/qlite/src/table.vala
index 00b4ef00..7fa2fc62 100644
--- a/qlite/src/table.vala
+++ b/qlite/src/table.vala
@@ -95,10 +95,12 @@ public class Table {
public void create_table_at_version(long version) {
ensure_init();
string sql = @"CREATE TABLE IF NOT EXISTS $name (";
+ bool first = true;
for (int i = 0; i < columns.length; i++) {
Column c = columns[i];
if (c.min_version <= version && c.max_version >= version) {
- sql += @"$(i > 0 ? "," : "") $c";
+ sql += @"$(!first ? "," : "") $c";
+ first = false;
}
}
sql += @"$constraints)";