[tracker/tracker-sql] Added tracker-sql util to run sql directly for testing
- From: Mikael Ottela <mottela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-sql] Added tracker-sql util to run sql directly for testing
- Date: Thu, 25 Mar 2010 15:23:13 +0000 (UTC)
commit 9e340a0950aa98ebede88a9aa2da2c62d9353b9b
Author: Mikael Ottela <mikael ottela ixonos com>
Date: Thu Mar 25 17:14:53 2010 +0200
Added tracker-sql util to run sql directly for testing
configure.ac | 3 +-
utils/Makefile.am | 3 +-
utils/tracker-sql/Makefile.am | 29 ++++++++++
utils/tracker-sql/tracker-sql.c | 115 +++++++++++++++++++++++++++++++++++++++
4 files changed, 148 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 05d6d9c..ac295fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -207,7 +207,7 @@ AC_SUBST(UUID_LIBS)
# Check for enca, detects defect Russian or Cyrillic language specifics in mp3s
AC_ARG_WITH(enca,
- AS_HELP_STRING([--with-enca],
+ AS_HELP_STRING([--with-enca],
[enable libenca for Cyrillic language detection in MP3s [[default=auto]]]),,
[enable_enca=auto])
@@ -1738,6 +1738,7 @@ AC_CONFIG_FILES([
utils/lyrics/Makefile
utils/playlists/Makefile
utils/services/Makefile
+ utils/tracker-sql/Makefile
examples/Makefile
examples/libtracker-extract/Makefile
examples/libtracker-miner/Makefile
diff --git a/utils/Makefile.am b/utils/Makefile.am
index bec1ba2..aee4030 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -4,4 +4,5 @@ SUBDIRS = \
gtk-sparql \
lyrics \
services \
- playlists
+ playlists \
+ tracker-sql
diff --git a/utils/tracker-sql/Makefile.am b/utils/tracker-sql/Makefile.am
new file mode 100644
index 0000000..25d1319
--- /dev/null
+++ b/utils/tracker-sql/Makefile.am
@@ -0,0 +1,29 @@
+include $(top_srcdir)/Makefile.decl
+
+noinst_PROGRAMS = tracker-sql
+
+INCLUDES = \
+ -DTRACKER_COMPILATION \
+ -DTOP_SRCDIR=\"$(top_srcdir)\" \
+ -DTOP_BUILDDIR=\"$(top_builddir)\" \
+ -DG_LOG_DOMAIN=\"Tracker\" \
+ -I$(top_srcdir)/src \
+ $(WARN_CFLAGS) \
+ $(GCOV_CFLAGS) \
+ $(DBUS_CFLAGS) \
+ $(SQLITE3_CFLAGS) \
+ $(GMODULE_CFLAGS) \
+ $(GTHREAD_CFLAGS) \
+ $(GLIB2_CFLAGS)
+
+tracker_sql_SOURCES = \
+ tracker-sql.c
+
+tracker_sql_LDADD = \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(top_builddir)/src/libtracker-db/libtracker-db.la \
+ $(top_builddir)/src/libtracker-data/libtracker-data.la \
+ $(GCOV_LIBS) \
+ $(GMODULE_LIBS) \
+ $(GTHREAD_LIBS) \
+ $(GLIB2_LIBS)
diff --git a/utils/tracker-sql/tracker-sql.c b/utils/tracker-sql/tracker-sql.c
new file mode 100644
index 0000000..c186b13
--- /dev/null
+++ b/utils/tracker-sql/tracker-sql.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <libtracker-common/tracker-ontologies.h>
+
+#include <libtracker-db/tracker-db.h>
+
+#include <libtracker-data/tracker-data-manager.h>
+#include <libtracker-data/tracker-data-query.h>
+#include <libtracker-data/tracker-data-update.h>
+#include <libtracker-data/tracker-sparql-query.h>
+
+int
+main (int argc, char **argv)
+{
+ GError *error = NULL;
+ gchar *query = NULL;
+ TrackerDBResultSet *result_set;
+ TrackerDBInterface *iface;
+ gboolean first_time = FALSE;
+
+ g_type_init ();
+
+ if (!g_thread_supported ()) {
+ g_thread_init (NULL);
+ }
+
+ if (argc != 2) {
+ g_printerr ("Usage: %s sql-file\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ g_assert_no_error (error);
+
+ g_file_get_contents (argv[1], &query, NULL, &error);
+
+
+ if (!tracker_data_manager_init (0,
+ NULL,
+ &first_time,
+ FALSE)) {
+ g_printerr ("Failed to initialize data manager\n");
+ return EXIT_FAILURE;
+
+ }
+
+ iface = tracker_db_manager_get_db_interface ();
+
+ result_set = tracker_db_interface_execute_query (iface, &error, "%s", query);
+
+ g_assert_no_error (error);
+
+ if (result_set) {
+ gboolean valid = TRUE;
+ guint columns;
+
+ columns = tracker_db_result_set_get_n_columns (result_set);
+
+ while (valid) {
+ guint i;
+
+ for (i = 0; i < columns; i++) {
+ GValue value = {0, };
+ GValue transform = {0, };
+
+ g_value_init (&transform, G_TYPE_STRING);
+
+ _tracker_db_result_set_get_value (result_set, i, &value);
+ if (G_IS_VALUE (&value) && g_value_transform (&value, &transform)) {
+ gchar *str;
+
+ str = g_value_dup_string (&transform);
+
+ g_message ("Value: %s", str);
+
+ g_value_unset (&value);
+ }
+ g_value_unset (&transform);
+ }
+
+ g_message ("--\n");
+
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+ } else {
+ g_message ("Empty result set");
+ }
+
+ return EXIT_SUCCESS;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]