aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/query_builder.vala
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-10-28 23:48:07 +0200
committerfiaxh <git@mx.ax.lt>2017-10-31 15:41:45 +0100
commitb9df78e4494879752e9e68dcc5d54e03fffe9467 (patch)
treed1c74fde4aedea42773bc411c557f2184003defa /qlite/src/query_builder.vala
parentd9b91206c0291fa8aa58df572292784a4f8ff878 (diff)
downloaddino-b9df78e4494879752e9e68dcc5d54e03fffe9467.tar.gz
dino-b9df78e4494879752e9e68dcc5d54e03fffe9467.zip
Move DatabaseError handling into Qlite
Diffstat (limited to 'qlite/src/query_builder.vala')
-rw-r--r--qlite/src/query_builder.vala24
1 files changed, 12 insertions, 12 deletions
diff --git a/qlite/src/query_builder.vala b/qlite/src/query_builder.vala
index f46fe98c..dbfdef2a 100644
--- a/qlite/src/query_builder.vala
+++ b/qlite/src/query_builder.vala
@@ -49,8 +49,8 @@ public class QueryBuilder : StatementBuilder {
return this;
}
- public QueryBuilder from(Table table) throws DatabaseError {
- if (this.table_name != null) throw new DatabaseError.ILLEGAL_QUERY("cannot use from() multiple times.");
+ public QueryBuilder from(Table table) {
+ if (this.table_name != null) error("cannot use from() multiple times.");
this.table = table;
this.table_name = table.name;
return this;
@@ -61,8 +61,8 @@ public class QueryBuilder : StatementBuilder {
return this;
}
- public QueryBuilder where(string selection, string[] selection_args = {}) throws DatabaseError {
- if (this.selection != "1") throw new DatabaseError.ILLEGAL_QUERY("selection was already done, but where() was called.");
+ public QueryBuilder where(string selection, string[] selection_args = {}) {
+ if (this.selection != "1") error("selection was already done, but where() was called.");
this.selection = selection;
foreach (string arg in selection_args) {
this.selection_args += new StatementBuilder.StringField(arg);
@@ -102,26 +102,26 @@ public class QueryBuilder : StatementBuilder {
return this;
}
- public int64 count() throws DatabaseError {
+ public int64 count() {
this.column_selector = @"COUNT($column_selector) AS count";
this.single_result = true;
return row().get_integer("count");
}
- private Row? row_() throws DatabaseError {
- if (!single_result) throw new DatabaseError.NON_UNIQUE("query is not suited to return a single row, but row() was called.");
+ private Row? row_() {
+ if (!single_result) error("query is not suited to return a single row, but row() was called.");
return iterator().get_next();
}
- public RowOption row() throws DatabaseError {
+ public RowOption row() {
return new RowOption(row_());
}
- public T get<T>(Column<T> field) throws DatabaseError {
+ public T get<T>(Column<T> field) {
return row()[field];
}
- internal override Statement prepare() throws DatabaseError {
+ 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" : "")");
for (int i = 0; i < selection_args.length; i++) {
selection_args[i].bind(stmt, i+1);
@@ -129,7 +129,7 @@ public class QueryBuilder : StatementBuilder {
return stmt;
}
- public RowIterator iterator() throws DatabaseError {
+ public RowIterator iterator() {
return new RowIterator.from_query_builder(db, this);
}
@@ -164,4 +164,4 @@ public class QueryBuilder : StatementBuilder {
}
}
-} \ No newline at end of file
+}