QLite: Add OFFSET statement
This commit is contained in:
parent
0ceaaadb20
commit
063d0146f9
|
@ -20,8 +20,9 @@ public class QueryBuilder : StatementBuilder {
|
||||||
// ORDER BY [...]
|
// ORDER BY [...]
|
||||||
private OrderingTerm[]? order_by_terms = {};
|
private OrderingTerm[]? order_by_terms = {};
|
||||||
|
|
||||||
// LIMIT [...]
|
// LIMIT [...] OFFSET [...]
|
||||||
private int limit_val;
|
private int limit_val;
|
||||||
|
private int offset_val;
|
||||||
|
|
||||||
internal QueryBuilder(Database db) {
|
internal QueryBuilder(Database db) {
|
||||||
base(db);
|
base(db);
|
||||||
|
@ -103,6 +104,12 @@ public class QueryBuilder : StatementBuilder {
|
||||||
return this;
|
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() {
|
public QueryBuilder single() {
|
||||||
this.single_result = true;
|
this.single_result = true;
|
||||||
return limit(1);
|
return limit(1);
|
||||||
|
@ -128,7 +135,7 @@ public class QueryBuilder : StatementBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override Statement prepare() {
|
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++) {
|
for (int i = 0; i < selection_args.length; i++) {
|
||||||
selection_args[i].bind(stmt, i+1);
|
selection_args[i].bind(stmt, i+1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue