[tracker/cursor: 12/15] libtracker-data: Use Cursor instead of ResultSet in sparql-pattern
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/cursor: 12/15] libtracker-data: Use Cursor instead of ResultSet in sparql-pattern
- Date: Tue, 18 Jan 2011 16:35:32 +0000 (UTC)
commit 38bb6026d4493ef9e680febbc17b44c51cb06eed
Author: Jürg Billeter <j bitron ch>
Date: Tue Jan 18 16:34:43 2011 +0100
libtracker-data: Use Cursor instead of ResultSet in sparql-pattern
src/libtracker-data/libtracker-data.vapi | 1 +
src/libtracker-data/tracker-sparql-pattern.vala | 28 +++++++++-------------
2 files changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 82af4dc..e850da4 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -82,6 +82,7 @@ namespace Tracker {
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;
public abstract DBCursor start_sparql_cursor (PropertyType[] types, string[] variable_names, bool threadsafe) throws DBInterfaceError;
}
diff --git a/src/libtracker-data/tracker-sparql-pattern.vala b/src/libtracker-data/tracker-sparql-pattern.vala
index 9080678..cf6ea2a 100644
--- a/src/libtracker-data/tracker-sparql-pattern.vala
+++ b/src/libtracker-data/tracker-sparql-pattern.vala
@@ -34,22 +34,20 @@ namespace Tracker.Sparql {
// single subject
var subject_id = Data.query_resource_id (subject);
- DBResultSet result_set = null;
+ DBCursor cursor = null;
if (subject_id > 0) {
var iface = DBManager.get_db_interface ();
var stmt = iface.create_statement (DBStatementCacheType.SELECT,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") " +
"FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
stmt.bind_int (0, subject_id);
- result_set = stmt.execute ();
+ cursor = stmt.start_cursor ();
}
- if (result_set != null) {
+ if (cursor != null) {
bool first = true;
- do {
- Value value;
- result_set._get_value (0, out value);
- var domain = Ontologies.get_class_by_uri (value.get_string ());
+ while (cursor.next ()) {
+ var domain = Ontologies.get_class_by_uri (cursor.get_string (0));
foreach (Property prop in Ontologies.get_properties ()) {
if (prop.domain == domain) {
@@ -76,7 +74,7 @@ namespace Tracker.Sparql {
query.bindings.append (binding);
}
}
- } while (result_set.iter_next ());
+ }
} else {
/* no match */
sql.append ("SELECT NULL AS ID, NULL AS \"predicate\", NULL AS \"object\", NULL AS \"graph\"");
@@ -90,14 +88,12 @@ namespace Tracker.Sparql {
"SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") " +
"FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
stmt.bind_int (0, object_id);
- var result_set = stmt.execute ();
+ var cursor = stmt.start_cursor ();
bool first = true;
- if (result_set != null) {
- do {
- Value value;
- result_set._get_value (0, out value);
- var range = Ontologies.get_class_by_uri (value.get_string ());
+ if (cursor != null) {
+ while (cursor.next ()) {
+ var range = Ontologies.get_class_by_uri (cursor.get_string (0));
foreach (Property prop in Ontologies.get_properties ()) {
if (prop.range == range) {
@@ -117,7 +113,7 @@ namespace Tracker.Sparql {
sql.append_printf (" FROM \"%s\"", prop.table_name);
}
}
- } while (result_set.iter_next ());
+ }
} else {
/* no match */
sql.append ("SELECT NULL AS ID, NULL AS \"predicate\", NULL AS \"object\", NULL AS \"graph\"");
@@ -148,7 +144,7 @@ namespace Tracker.Sparql {
throw query.get_internal_error ("Unrestricted predicate variables not supported");
}
return sql.str;
- } catch (DBInterfaceError e) {
+ } catch (GLib.Error e) {
throw new Sparql.Error.INTERNAL (e.message);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]