tracker r2338 - in trunk: . data/dbus src/libtracker-db src/trackerd
- From: pvanhoof svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2338 - in trunk: . data/dbus src/libtracker-db src/trackerd
- Date: Thu, 9 Oct 2008 08:34:53 +0000 (UTC)
Author: pvanhoof
Date: Thu Oct 9 08:34:52 2008
New Revision: 2338
URL: http://svn.gnome.org/viewvc/tracker?rev=2338&view=rev
Log:
2008-10-09 Philip Van Hoof <philip codeminded be>
* src/libtracker-db/tracker-db-interface-sqlite.c
* src/libtracker-db/tracker-db-interface-sqlite.h
* src/libtracker-db/tracker-db-manager.c
* src/libtracker-db/tracker-db-manager.h
* src/trackerd/tracker-search.c
* src/trackerd/tracker-search.h
* data/dbus/tracker-search.xml: Added a method to access the database
using normal SQL queries. Please do not use this API in applications
unless you understand the consequences of the DB schema changing at
unannounced moments.
Modified:
trunk/ChangeLog
trunk/data/dbus/tracker-search.xml
trunk/src/libtracker-db/tracker-db-interface-sqlite.c
trunk/src/libtracker-db/tracker-db-interface-sqlite.h
trunk/src/libtracker-db/tracker-db-manager.c
trunk/src/libtracker-db/tracker-db-manager.h
trunk/src/trackerd/tracker-search.c
trunk/src/trackerd/tracker-search.h
Modified: trunk/data/dbus/tracker-search.xml
==============================================================================
--- trunk/data/dbus/tracker-search.xml (original)
+++ trunk/data/dbus/tracker-search.xml Thu Oct 9 08:34:52 2008
@@ -119,5 +119,20 @@
<arg type="i" name="maxdist" direction="in" />
<arg type="s" name="result" direction="out" />
</method>
+
+ <!-- This method is only to be used for prototyping and development
+ purposes. Please do not use it for actual applications as the
+ DB schema is not only not guaranteed not to change, it's also
+ guaranteed to change indeed. -->
+
+ <!-- Please do not use this in your applictions. You have been warned
+ twice now. -->
+
+ <method name="SqlQuery">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+ <arg type="s" name="query" direction="in" />
+ <arg type="aas" name="result" direction="out" />
+ </method>
+
</interface>
</node>
Modified: trunk/src/libtracker-db/tracker-db-interface-sqlite.c
==============================================================================
--- trunk/src/libtracker-db/tracker-db-interface-sqlite.c (original)
+++ trunk/src/libtracker-db/tracker-db-interface-sqlite.c Thu Oct 9 08:34:52 2008
@@ -35,6 +35,7 @@
GSList *function_data;
guint in_transaction : 1;
+ guint ro : 1;
};
struct SqliteFunctionData {
@@ -47,7 +48,8 @@
enum {
PROP_0,
PROP_FILENAME,
- PROP_IN_TRANSACTION
+ PROP_IN_TRANSACTION,
+ PROP_RO
};
G_DEFINE_TYPE_WITH_CODE (TrackerDBInterfaceSqlite, tracker_db_interface_sqlite, G_TYPE_OBJECT,
@@ -68,10 +70,18 @@
priv = TRACKER_DB_INTERFACE_SQLITE_GET_PRIVATE (object);
g_assert (priv->filename != NULL);
- if (sqlite3_open (priv->filename, &priv->db) != SQLITE_OK) {
- g_critical ("Could not open sqlite3 database:'%s'", priv->filename);
+ if (!priv->ro) {
+ if (sqlite3_open (priv->filename, &priv->db) != SQLITE_OK) {
+ g_critical ("Could not open sqlite3 database:'%s'", priv->filename);
+ } else {
+ g_message ("Opened sqlite3 database:'%s'", priv->filename);
+ }
} else {
- g_message ("Opened sqlite3 database:'%s'", priv->filename);
+ if (sqlite3_open_v2 (priv->filename, &priv->db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
+ g_critical ("Could not open sqlite3 database:'%s'", priv->filename);
+ } else {
+ g_message ("Opened sqlite3 database:'%s'", priv->filename);
+ }
}
sqlite3_extended_result_codes (priv->db, 0);
@@ -91,6 +101,9 @@
priv = TRACKER_DB_INTERFACE_SQLITE_GET_PRIVATE (object);
switch (prop_id) {
+ case PROP_RO:
+ priv->ro = g_value_get_boolean (value);
+ break;
case PROP_FILENAME:
priv->filename = g_value_dup_string (value);
break;
@@ -113,6 +126,9 @@
priv = TRACKER_DB_INTERFACE_SQLITE_GET_PRIVATE (object);
switch (prop_id) {
+ case PROP_RO:
+ g_value_set_boolean (value, priv->ro);
+ break;
case PROP_FILENAME:
g_value_set_string (value, priv->filename);
break;
@@ -170,6 +186,14 @@
PROP_IN_TRANSACTION,
"in-transaction");
+ g_object_class_install_property (object_class,
+ PROP_RO,
+ g_param_spec_boolean ("read-only",
+ "Read only",
+ "Whether the connection is read only",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
g_type_class_add_private (object_class,
sizeof (TrackerDBInterfaceSqlitePrivate));
}
@@ -181,6 +205,7 @@
priv = TRACKER_DB_INTERFACE_SQLITE_GET_PRIVATE (db_interface);
+ priv->ro = FALSE;
priv->statements = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) sqlite3_finalize);
@@ -562,6 +587,15 @@
NULL);
}
+TrackerDBInterface *
+tracker_db_interface_sqlite_new_ro (const gchar *filename)
+{
+ return g_object_new (TRACKER_TYPE_DB_INTERFACE_SQLITE,
+ "filename", filename,
+ "read-only", TRUE,
+ NULL);
+}
+
static gint
collation_function (gpointer data,
int len1,
Modified: trunk/src/libtracker-db/tracker-db-interface-sqlite.h
==============================================================================
--- trunk/src/libtracker-db/tracker-db-interface-sqlite.h (original)
+++ trunk/src/libtracker-db/tracker-db-interface-sqlite.h Thu Oct 9 08:34:52 2008
@@ -53,6 +53,7 @@
GType tracker_db_interface_sqlite_get_type (void);
TrackerDBInterface * tracker_db_interface_sqlite_new (const gchar *filename);
+TrackerDBInterface * tracker_db_interface_sqlite_new_ro (const gchar *filename);
void tracker_db_interface_sqlite_create_function (TrackerDBInterface *interface,
const gchar *name,
Modified: trunk/src/libtracker-db/tracker-db-manager.c
==============================================================================
--- trunk/src/libtracker-db/tracker-db-manager.c (original)
+++ trunk/src/libtracker-db/tracker-db-manager.c Thu Oct 9 08:34:52 2008
@@ -2682,6 +2682,39 @@
return connection;
}
+TrackerDBInterface *
+tracker_db_manager_get_db_interfaces_ro (gint num, ...)
+{
+ gint n_args;
+ va_list args;
+ TrackerDBInterface *connection = NULL;
+
+ g_return_val_if_fail (initialized != FALSE, NULL);
+
+ va_start (args, num);
+ for (n_args = 1; n_args <= num; n_args++) {
+ TrackerDB db = va_arg (args, TrackerDB);
+
+ if (!connection) {
+ connection = tracker_db_interface_sqlite_new_ro (dbs[db].abs_filename);
+ tracker_db_interface_set_procedure_table (connection,
+ prepared_queries);
+ db_set_params (connection,
+ dbs[db].cache_size,
+ dbs[db].page_size,
+ TRUE);
+ } else {
+ db_exec_no_reply (connection,
+ "ATTACH '%s' as '%s'",
+ dbs[db].abs_filename,
+ dbs[db].name);
+ }
+
+ }
+ va_end (args);
+
+ return connection;
+}
/**
Modified: trunk/src/libtracker-db/tracker-db-manager.h
==============================================================================
--- trunk/src/libtracker-db/tracker-db-manager.h (original)
+++ trunk/src/libtracker-db/tracker-db-manager.h Thu Oct 9 08:34:52 2008
@@ -71,6 +71,8 @@
TrackerDBInterface *
tracker_db_manager_get_db_interfaces (gint num, ...);
TrackerDBInterface *
+ tracker_db_manager_get_db_interfaces_ro (gint num, ...);
+TrackerDBInterface *
tracker_db_manager_get_db_interface_by_service (const gchar *service);
TrackerDBInterface *
tracker_db_manager_get_db_interface_by_type (const gchar *service,
Modified: trunk/src/trackerd/tracker-search.c
==============================================================================
--- trunk/src/trackerd/tracker-search.c (original)
+++ trunk/src/trackerd/tracker-search.c Thu Oct 9 08:34:52 2008
@@ -1249,3 +1249,53 @@
tracker_dbus_request_success (request_id);
}
+
+void
+tracker_search_sql_query (TrackerSearch *object,
+ gchar *query,
+ DBusGMethodInvocation *context,
+ GError **error)
+{
+ GError *actual_error = NULL;
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_async_return_if_fail (query != NULL, context);
+
+ tracker_dbus_request_new (request_id,
+ "DBus request for SQL Query, "
+ "query:'%s'",
+ query);
+
+ iface = tracker_db_manager_get_db_interfaces_ro (7,
+ TRACKER_DB_CACHE,
+ TRACKER_DB_COMMON,
+ TRACKER_DB_FILE_CONTENTS,
+ TRACKER_DB_FILE_METADATA,
+ TRACKER_DB_EMAIL_CONTENTS,
+ TRACKER_DB_EMAIL_METADATA,
+ TRACKER_DB_XESAM);
+
+ result_set = tracker_db_interface_execute_query (iface,
+ &actual_error,
+ query);
+
+ if (!result_set) {
+ dbus_g_method_return_error (context, actual_error);
+ g_error_free (actual_error);
+ } else {
+ GPtrArray *values;
+
+ values = tracker_dbus_query_result_multi_to_ptr_array (result_set);
+ dbus_g_method_return (context, values);
+ tracker_dbus_results_ptr_array_free (&values);
+ g_object_unref (result_set);
+ }
+
+ g_object_unref (iface);
+
+ tracker_dbus_request_success (request_id);
+}
Modified: trunk/src/trackerd/tracker-search.h
==============================================================================
--- trunk/src/trackerd/tracker-search.h (original)
+++ trunk/src/trackerd/tracker-search.h Thu Oct 9 08:34:52 2008
@@ -129,6 +129,10 @@
gint max_dist,
DBusGMethodInvocation *context,
GError **error);
+void tracker_search_sql_query (TrackerSearch *object,
+ gchar *query,
+ DBusGMethodInvocation *context,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]