[tracker/tracker-0.6] Updated utils/sqlite/query to take multiple queries
- From: Martyn James Russell <mr src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-0.6] Updated utils/sqlite/query to take multiple queries
- Date: Mon, 8 Jun 2009 06:33:00 -0400 (EDT)
commit 3067c892d7ef25326268c33a592667bf776e9485
Author: Martyn Russell <martyn imendio com>
Date: Mon Jun 8 11:32:44 2009 +0100
Updated utils/sqlite/query to take multiple queries
---
utils/sqlite/query.c | 30 +++++++++++++++++-------------
1 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/utils/sqlite/query.c b/utils/sqlite/query.c
index 19e8a5f..de80fc0 100644
--- a/utils/sqlite/query.c
+++ b/utils/sqlite/query.c
@@ -34,12 +34,12 @@ static void query_run (sqlite3 *db,
sqlite3_stmt *stmt);
static void query_close (sqlite3_stmt *stmt);
-static gchar *query;
+static gchar **queries;
static gchar **attach_dbs;
static GOptionEntry entries[] = {
- { "query", 'q', 0, G_OPTION_ARG_STRING, &query,
- N_("SQL query to use"),
+ { "query", 'q', 0, G_OPTION_ARG_STRING_ARRAY, &queries,
+ N_("SQL query to use (can be used multiple times)"),
N_("SQL")
},
{ G_OPTION_REMAINING, 0, 0,
@@ -227,6 +227,8 @@ main (int argc, char *argv[])
{
GOptionContext *context;
gchar *summary;
+ gchar **query;
+ gint failures;
sqlite3 *db;
sqlite3_stmt *stmt;
@@ -264,7 +266,7 @@ main (int argc, char *argv[])
g_option_context_parse (context, &argc, &argv, NULL);
g_free (summary);
- if (!query || !*query) {
+ if (!queries || g_strv_length (queries) < 1) {
gchar *help;
g_printerr ("%s\n\n",
@@ -301,17 +303,19 @@ main (int argc, char *argv[])
return EXIT_FAILURE;
}
- stmt = query_prepare (db, query);
+ for (query = queries, failures = 0; *query; query++) {
+ stmt = query_prepare (db, *query);
- if (!stmt) {
- connection_close (db);
- return EXIT_FAILURE;
- }
+ if (!stmt) {
+ failures++;
+ continue;
+ }
- query_run (db, stmt);
-
- query_close (stmt);
+ query_run (db, stmt);
+ query_close (stmt);
+ }
+
connection_close (db);
- return EXIT_SUCCESS;
+ return failures > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]