[tracker/parser] SPARQL: Split ASK query out
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/parser] SPARQL: Split ASK query out
- Date: Fri, 7 Aug 2009 11:42:59 +0000 (UTC)
commit cc3ff0e96b84802b76a312c4f95b04071b6c26b3
Author: Jürg Billeter <j bitron ch>
Date: Fri Aug 7 13:42:29 2009 +0200
SPARQL: Split ASK query out
src/libtracker-data/tracker-sparql-query.vala | 47 ++++++++++++++++++-------
1 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 27af521..bb76114 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -432,7 +432,7 @@ public class Tracker.SparqlQuery : Object {
} else if (current () == SparqlTokenType.DESCRIBE) {
throw new SparqlError.INTERNAL ("DESCRIBE is not supported");
} else if (current () == SparqlTokenType.ASK) {
- return execute_select ();
+ return execute_ask ();
} else {
throw new SparqlError.PARSE ("DELETE and INSERT are not supported in query mode");
}
@@ -507,9 +507,7 @@ public class Tracker.SparqlQuery : Object {
}
DBResultSet? execute_select () throws Error {
- bool is_ask = false;
-
- // SELECT or ASK query
+ // SELECT query
pattern_sql = new StringBuilder ();
var_map = new HashTable<string,VariableBinding>.full (str_hash, str_equal, g_free, g_object_unref);
@@ -521,21 +519,13 @@ public class Tracker.SparqlQuery : Object {
var sql = new StringBuilder ();
sql.append ("SELECT ");
- if (accept (SparqlTokenType.ASK)) {
- is_ask = true;
- } else {
- expect (SparqlTokenType.SELECT);
- }
+ expect (SparqlTokenType.SELECT);
if (accept (SparqlTokenType.DISTINCT)) {
sql.append ("DISTINCT ");
} else if (accept (SparqlTokenType.REDUCED)) {
}
- if (is_ask) {
- sql.append ("COUNT(1) > 0");
- }
-
if (accept (SparqlTokenType.STAR)) {
// TODO
} else {
@@ -658,6 +648,37 @@ public class Tracker.SparqlQuery : Object {
return exec_sql (sql.str);
}
+ DBResultSet? execute_ask () throws Error {
+ // ASK query
+
+ pattern_sql = new StringBuilder ();
+ var_map = new HashTable<string,VariableBinding>.full (str_hash, str_equal, g_free, g_object_unref);
+ predicate_variable_map = new HashTable<string,PredicateVariable>.full (str_hash, str_equal, g_free, g_object_unref);
+
+ var select_variables = new List<string> ();
+
+ // build SQL
+ var sql = new StringBuilder ();
+ sql.append ("SELECT ");
+
+ expect (SparqlTokenType.ASK);
+
+ sql.append ("COUNT(1) > 0");
+
+ accept (SparqlTokenType.WHERE);
+
+ visit_group_graph_pattern ();
+
+ // select from results of WHERE clause
+ sql.append (" FROM (");
+ sql.append (pattern_sql.str);
+ sql.append (")");
+
+ pattern_sql.truncate (0);
+
+ return exec_sql (sql.str);
+ }
+
void execute_insert () throws Error {
expect (SparqlTokenType.INSERT);
execute_update (false);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]