[tracker/return-types: 3/26] libtracker-data: Store types of query results
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/return-types: 3/26] libtracker-data: Store types of query results
- Date: Wed, 15 Sep 2010 13:55:39 +0000 (UTC)
commit 87b3f0d6d952e13d4adaabcad1ec36653a4fbb80
Author: Jürg Billeter <j bitron ch>
Date: Wed Sep 8 18:36:24 2010 +0200
libtracker-data: Store types of query results
src/libtracker-data/libtracker-data.vapi | 2 +-
src/libtracker-data/tracker-db-interface-sqlite.c | 49 ++++++++++++++++----
src/libtracker-data/tracker-db-interface.h | 6 +++
src/libtracker-data/tracker-sparql-pattern.vala | 2 +
src/libtracker-data/tracker-sparql-query.vala | 19 +++++---
5 files changed, 60 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index b74c3d5..4bdef4f 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -72,7 +72,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) throws DBInterfaceError;
}
[CCode (cheader_filename = "libtracker-data/tracker-class.h")]
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 48de5ec..b87aa78 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -71,6 +71,8 @@ struct TrackerDBCursor {
TrackerDBStatement *ref_stmt;
gboolean finished;
gchar **variable_names;
+ TrackerPropertyType *types;
+ gint n_types;
};
struct TrackerDBCursorClass {
@@ -88,14 +90,16 @@ struct TrackerDBStatementClass {
GObjectClass parent_class;
};
-static TrackerDBStatement * tracker_db_statement_sqlite_new (TrackerDBInterface *db_interface,
- sqlite3_stmt *sqlite_stmt);
-static TrackerDBCursor * tracker_db_cursor_sqlite_new (sqlite3_stmt *sqlite_stmt,
- TrackerDBStatement *ref_stmt);
-static void tracker_db_statement_sqlite_reset (TrackerDBStatement *stmt);
-static gboolean db_cursor_iter_next (TrackerDBCursor *cursor,
- GCancellable *cancellable,
- GError **error);
+static TrackerDBStatement *tracker_db_statement_sqlite_new (TrackerDBInterface *db_interface,
+ sqlite3_stmt *sqlite_stmt);
+static TrackerDBCursor *tracker_db_cursor_sqlite_new (sqlite3_stmt *sqlite_stmt,
+ TrackerDBStatement *ref_stmt,
+ TrackerPropertyType *types,
+ gint n_types);
+static void tracker_db_statement_sqlite_reset (TrackerDBStatement *stmt);
+static gboolean db_cursor_iter_next (TrackerDBCursor *cursor,
+ GCancellable *cancellable,
+ GError **error);
enum {
PROP_0,
@@ -1090,6 +1094,8 @@ tracker_db_cursor_finalize (GObject *object)
cursor = TRACKER_DB_CURSOR (object);
+ g_free (cursor->types);
+
g_strfreev (cursor->variable_names);
cursor->variable_names = NULL;
@@ -1188,7 +1194,9 @@ tracker_db_cursor_class_init (TrackerDBCursorClass *class)
static TrackerDBCursor *
tracker_db_cursor_sqlite_new (sqlite3_stmt *sqlite_stmt,
- TrackerDBStatement *ref_stmt)
+ TrackerDBStatement *ref_stmt,
+ TrackerPropertyType *types,
+ gint n_types)
{
TrackerDBCursor *cursor;
@@ -1204,6 +1212,16 @@ tracker_db_cursor_sqlite_new (sqlite3_stmt *sqlite_stmt,
cursor->ref_stmt = NULL;
}
+ if (types) {
+ gint i;
+
+ cursor->types = g_new (TrackerPropertyType, n_types);
+ cursor->n_types = n_types;
+ for (i = 0; i < n_types; i++) {
+ cursor->types[i] = types[i];
+ }
+ }
+
return cursor;
}
@@ -1427,7 +1445,18 @@ tracker_db_statement_start_cursor (TrackerDBStatement *stmt,
{
g_return_val_if_fail (!stmt->stmt_is_sunk, NULL);
- return tracker_db_cursor_sqlite_new (stmt->stmt, stmt);
+ return tracker_db_cursor_sqlite_new (stmt->stmt, stmt, NULL, 0);
+}
+
+TrackerDBCursor *
+tracker_db_statement_start_sparql_cursor (TrackerDBStatement *stmt,
+ TrackerPropertyType *types,
+ gint n_types,
+ GError **error)
+{
+ g_return_val_if_fail (!stmt->stmt_is_sunk, NULL);
+
+ return tracker_db_cursor_sqlite_new (stmt->stmt, stmt, types, n_types);
}
diff --git a/src/libtracker-data/tracker-db-interface.h b/src/libtracker-data/tracker-db-interface.h
index ecf1275..d63e1b1 100644
--- a/src/libtracker-data/tracker-db-interface.h
+++ b/src/libtracker-data/tracker-db-interface.h
@@ -25,6 +25,8 @@
#include <libtracker-sparql/tracker-sparql.h>
+#include "tracker-property.h"
+
G_BEGIN_DECLS
#if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
@@ -115,6 +117,10 @@ TrackerDBResultSet * tracker_db_statement_execute (TrackerDBStatem
GError **error);
TrackerDBCursor * tracker_db_statement_start_cursor (TrackerDBStatement *stmt,
GError **error);
+TrackerDBCursor * tracker_db_statement_start_sparql_cursor(TrackerDBStatement *stmt,
+ TrackerPropertyType *types,
+ gint n_types,
+ GError **error);
/* Semi private TrackerDBResultSet functions */
TrackerDBResultSet * _tracker_db_result_set_new (guint cols);
diff --git a/src/libtracker-data/tracker-sparql-pattern.vala b/src/libtracker-data/tracker-sparql-pattern.vala
index bbc5aeb..aef222f 100644
--- a/src/libtracker-data/tracker-sparql-pattern.vala
+++ b/src/libtracker-data/tracker-sparql-pattern.vala
@@ -296,6 +296,7 @@ class Tracker.Sparql.Pattern : Object {
} else {
Expression.append_expression_as_string (sql, variable.sql_expression, variable.binding.data_type);
}
+ result.types += variable.binding.data_type;
}
} else {
while (true) {
@@ -306,6 +307,7 @@ class Tracker.Sparql.Pattern : Object {
}
type = expression.translate_select_expression (sql, subquery);
+ result.types += type;
switch (current ()) {
case SparqlTokenType.FROM:
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index a68eba4..4238a10 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -158,6 +158,7 @@ namespace Tracker.Sparql {
class SelectContext : Context {
public PropertyType type;
+ public PropertyType[] types = {};
public SelectContext (Context? parent_context = null) {
base (parent_context);
@@ -517,18 +518,18 @@ public class Tracker.Sparql.Query : Object {
return stmt.execute ();
}
- DBCursor? exec_sql_cursor (string sql) throws DBInterfaceError, Sparql.Error, DateError {
+ DBCursor? exec_sql_cursor (string sql, PropertyType[] types) throws DBInterfaceError, Sparql.Error, DateError {
var stmt = prepare_for_exec (sql);
- return stmt.start_cursor ();
+ return stmt.start_sparql_cursor (types);
}
- string get_select_query () throws DBInterfaceError, Sparql.Error, DateError {
+ string get_select_query (out SelectContext context) throws DBInterfaceError, Sparql.Error, DateError {
// SELECT query
// build SQL
var sql = new StringBuilder ();
- pattern.translate_select (sql);
+ context = pattern.translate_select (sql);
expect (SparqlTokenType.EOF);
@@ -536,11 +537,15 @@ public class Tracker.Sparql.Query : Object {
}
DBResultSet? execute_select () throws DBInterfaceError, Sparql.Error, DateError {
- return exec_sql (get_select_query ());
+ SelectContext context;
+ return exec_sql (get_select_query (out context));
}
DBCursor? execute_select_cursor () throws DBInterfaceError, Sparql.Error, DateError {
- return exec_sql_cursor (get_select_query ());
+ SelectContext context;
+ string sql = get_select_query (out context);
+
+ return exec_sql_cursor (sql, context.types);
}
string get_ask_query () throws DBInterfaceError, Sparql.Error, DateError {
@@ -575,7 +580,7 @@ public class Tracker.Sparql.Query : Object {
}
DBCursor? execute_ask_cursor () throws DBInterfaceError, Sparql.Error, DateError {
- return exec_sql_cursor (get_ask_query ());
+ return exec_sql_cursor (get_ask_query (), new PropertyType[] { PropertyType.BOOLEAN });
}
private void parse_from_or_into_param () throws Sparql.Error {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]