aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2018-07-12 20:27:50 +0200
committerMarvin W <git@larma.de>2018-07-12 20:27:50 +0200
commit063d0146f922b1ed6388f40e05ae8eb0c547083d (patch)
treeb1c76ce96971daacc3f7618df5bc2e58a8f7e4d9
parent0ceaaadb201a710baa2b6f358c3b29b4fcc192d6 (diff)
downloaddino-063d0146f922b1ed6388f40e05ae8eb0c547083d.tar.gz
dino-063d0146f922b1ed6388f40e05ae8eb0c547083d.zip
QLite: Add OFFSET statement
-rw-r--r--qlite/src/query_builder.vala11
1 files changed, 9 insertions, 2 deletions
diff --git a/qlite/src/query_builder.vala b/qlite/src/query_builder.vala
index 75fe0499..915e2d2d 100644
--- a/qlite/src/query_builder.vala
+++ b/qlite/src/query_builder.vala
@@ -20,8 +20,9 @@ public class QueryBuilder : StatementBuilder {
// ORDER BY [...]
private OrderingTerm[]? order_by_terms = {};
- // LIMIT [...]
+ // LIMIT [...] OFFSET [...]
private int limit_val;
+ private int offset_val;
internal QueryBuilder(Database db) {
base(db);
@@ -103,6 +104,12 @@ public class QueryBuilder : StatementBuilder {
return this;
}
+ public QueryBuilder offset(int offset) {
+ if (this.limit_val == 0) error("limit required before offset");
+ this.offset_val = offset;
+ return this;
+ }
+
public QueryBuilder single() {
this.single_result = true;
return limit(1);
@@ -128,7 +135,7 @@ public class QueryBuilder : StatementBuilder {
}
internal override Statement prepare() {
- Statement stmt = db.prepare(@"SELECT $column_selector $(table_name == null ? "" : @"FROM $((!) table_name)") WHERE $selection $(OrderingTerm.all_to_string(order_by_terms)) $(limit_val > 0 ? @" LIMIT $limit_val" : "")");
+ Statement stmt = db.prepare(@"SELECT $column_selector $(table_name == null ? "" : @"FROM $((!) table_name)") WHERE $selection $(OrderingTerm.all_to_string(order_by_terms)) $(limit_val > 0 ? @" LIMIT $limit_val OFFSET $offset_val" : "")");
for (int i = 0; i < selection_args.length; i++) {
selection_args[i].bind(stmt, i+1);
}