[tracker/async-queries-cursor-review: 1/6] libtracker-data: Added cursor return in TrackerSparqlQuery
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/async-queries-cursor-review: 1/6] libtracker-data: Added cursor return in TrackerSparqlQuery
- Date: Wed, 21 Apr 2010 15:26:27 +0000 (UTC)
commit 46c9ec21d25be5a9c71988cb1d6324b79869d2de
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Apr 19 15:41:31 2010 +0200
libtracker-data: Added cursor return in TrackerSparqlQuery
src/libtracker-data/tracker-data-query.c | 19 +++++++
src/libtracker-data/tracker-data-query.h | 11 +++--
src/libtracker-data/tracker-sparql-query.vala | 68 ++++++++++++++++++++++--
src/libtracker-db/libtracker-db.vapi | 5 ++
4 files changed, 93 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index 7fd8434..ebf98c8 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -126,3 +126,22 @@ tracker_data_query_sparql (const gchar *query,
return result_set;
}
+
+TrackerDBCursor *
+tracker_data_query_sparql_cursor (const gchar *query,
+ GError **error)
+{
+ TrackerSparqlQuery *sparql_query;
+ TrackerDBCursor *cursor;
+
+ g_return_val_if_fail (query != NULL, NULL);
+
+ sparql_query = tracker_sparql_query_new (query);
+
+ cursor = tracker_sparql_query_execute_cursor (sparql_query, error);
+
+ g_object_unref (sparql_query);
+
+ return cursor;
+}
+
diff --git a/src/libtracker-data/tracker-data-query.h b/src/libtracker-data/tracker-data-query.h
index cb7d346..4a16fda 100644
--- a/src/libtracker-data/tracker-data-query.h
+++ b/src/libtracker-data/tracker-data-query.h
@@ -33,10 +33,13 @@ G_BEGIN_DECLS
#error "only <libtracker-data/tracker-data.h> must be included directly."
#endif
-gint tracker_data_query_resource_id (const gchar *uri);
-TrackerDBResultSet *tracker_data_query_sparql (const gchar *query,
- GError **error);
-GPtrArray* tracker_data_query_rdf_type (gint id);
+gint tracker_data_query_resource_id (const gchar *uri);
+TrackerDBResultSet *tracker_data_query_sparql (const gchar *query,
+ GError **error);
+TrackerDBCursor *tracker_data_query_sparql_cursor (const gchar *query,
+ GError **error);
+
+GPtrArray* tracker_data_query_rdf_type (gint id);
G_END_DECLS
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index ef688aa..0215d95 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -361,7 +361,7 @@ public class Tracker.Sparql.Query : Object {
}
}
- public DBResultSet? execute () throws DBInterfaceError, SparqlError, DateError {
+ void prepare_execute () throws DBInterfaceError, SparqlError, DateError {
assert (!update_extensions);
scanner = new SparqlScanner ((char*) query_string, (long) query_string.size ());
@@ -375,6 +375,11 @@ public class Tracker.Sparql.Query : Object {
}
parse_prologue ();
+ }
+
+ public DBResultSet? execute () throws DBInterfaceError, SparqlError, DateError {
+
+ prepare_execute ();
switch (current ()) {
case SparqlTokenType.SELECT:
@@ -394,6 +399,29 @@ public class Tracker.Sparql.Query : Object {
}
}
+
+ public DBCursor? execute_cursor () throws DBInterfaceError, SparqlError, DateError {
+
+ prepare_execute ();
+
+ switch (current ()) {
+ case SparqlTokenType.SELECT:
+ return execute_select_cursor ();
+ case SparqlTokenType.CONSTRUCT:
+ throw get_internal_error ("CONSTRUCT is not supported");
+ case SparqlTokenType.DESCRIBE:
+ throw get_internal_error ("DESCRIBE is not supported");
+ case SparqlTokenType.ASK:
+ return execute_ask_cursor ();
+ case SparqlTokenType.INSERT:
+ case SparqlTokenType.DELETE:
+ case SparqlTokenType.DROP:
+ throw get_error ("INSERT and DELETE are not supported in query mode");
+ default:
+ throw get_error ("expected SELECT or ASK");
+ }
+ }
+
public PtrArray? execute_update (bool blank) throws DataError, DBInterfaceError, SparqlError, DateError {
assert (update_extensions);
@@ -442,7 +470,7 @@ public class Tracker.Sparql.Query : Object {
return blank_nodes;
}
- DBResultSet? exec_sql (string sql) throws DBInterfaceError, SparqlError, DateError {
+ DBStatement prepare_for_exec (string sql) throws DBInterfaceError, SparqlError, DateError {
var iface = DBManager.get_db_interface ();
var stmt = iface.create_statement ("%s", sql);
@@ -467,10 +495,22 @@ public class Tracker.Sparql.Query : Object {
i++;
}
+ return stmt;
+ }
+
+ DBResultSet? exec_sql (string sql) throws DBInterfaceError, SparqlError, DateError {
+ var stmt = prepare_for_exec (sql);
+
return stmt.execute ();
}
- DBResultSet? execute_select () throws DBInterfaceError, SparqlError, DateError {
+ DBCursor? exec_sql_cursor (string sql) throws DBInterfaceError, SparqlError, DateError {
+ var stmt = prepare_for_exec (sql);
+
+ return stmt.start_cursor ();
+ }
+
+ string get_select_query () throws DBInterfaceError, SparqlError, DateError {
// SELECT query
context = new Context ();
@@ -483,10 +523,18 @@ public class Tracker.Sparql.Query : Object {
context = context.parent_context;
- return exec_sql (sql.str);
+ return sql.str;
}
- DBResultSet? execute_ask () throws DBInterfaceError, SparqlError, DateError {
+ DBResultSet? execute_select () throws DBInterfaceError, SparqlError, DateError {
+ return exec_sql (get_select_query ());
+ }
+
+ DBCursor? execute_select_cursor () throws DBInterfaceError, SparqlError, DateError {
+ return exec_sql_cursor (get_select_query ());
+ }
+
+ string get_ask_query () throws DBInterfaceError, SparqlError, DateError {
// ASK query
var pattern_sql = new StringBuilder ();
@@ -511,7 +559,15 @@ public class Tracker.Sparql.Query : Object {
context = context.parent_context;
- return exec_sql (sql.str);
+ return sql.str;
+ }
+
+ DBResultSet? execute_ask () throws DBInterfaceError, SparqlError, DateError {
+ return exec_sql (get_ask_query ());
+ }
+
+ DBCursor? execute_ask_cursor () throws DBInterfaceError, SparqlError, DateError {
+ return exec_sql_cursor (get_ask_query ());
}
private void parse_from_or_into_param () throws SparqlError {
diff --git a/src/libtracker-db/libtracker-db.vapi b/src/libtracker-db/libtracker-db.vapi
index d9a69e7..f320ab6 100644
--- a/src/libtracker-db/libtracker-db.vapi
+++ b/src/libtracker-db/libtracker-db.vapi
@@ -51,11 +51,16 @@ namespace Tracker {
}
[CCode (cheader_filename = "libtracker-db/tracker-db-interface.h")]
+ public class DBCursor : GLib.Object {
+ }
+
+ [CCode (cheader_filename = "libtracker-db/tracker-db-interface.h")]
public interface DBStatement : GLib.Object {
public abstract void bind_double (int index, double value);
public abstract void bind_int (int index, int value);
public abstract void bind_text (int index, string value);
public abstract DBResultSet execute () throws DBInterfaceError;
+ public abstract DBCursor start_cursor () throws DBInterfaceError;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]