summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2012-12-17 11:59:23 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2013-01-09 13:56:06 +0100
commit51796fda08d36dfc38848c429d8cabd48e3484a9 (patch)
treebf53054d65f1d9720e2008d89b224bf951586c01 /tools
parent4509fd0a9f3b17e0c099efa6c235c4e80bf6a97d (diff)
downloadmsitools-51796fda08d36dfc38848c429d8cabd48e3484a9.tar.gz
msitools-51796fda08d36dfc38848c429d8cabd48e3484a9.tar.xz
msitools-51796fda08d36dfc38848c429d8cabd48e3484a9.zip
Remove libmsi_database_open_query()
It does the same job as libmsi_query_new()
Diffstat (limited to 'tools')
-rw-r--r--tools/msibuild.c64
-rw-r--r--tools/msiinfo.c67
2 files changed, 78 insertions, 53 deletions
diff --git a/tools/msibuild.c b/tools/msibuild.c
index 4a1f0e2..51e27be 100644
--- a/tools/msibuild.c
+++ b/tools/msibuild.c
@@ -168,48 +168,67 @@ static gboolean add_summary_info(const char *name, const char *author,
return TRUE;
}
-static int add_stream(const char *stream, const char *file, GError **error)
+static gboolean add_stream(const char *stream, const char *file, GError **error)
{
- LibmsiResult r;
- LibmsiRecord *rec;
- LibmsiQuery *query;
+ gboolean r = FALSE;
+ LibmsiRecord *rec = NULL;
+ LibmsiQuery *query = NULL;
rec = libmsi_record_new(2);
libmsi_record_set_string(rec, 1, stream);
- if (!libmsi_record_load_stream(rec, 2, file))
+ if (!libmsi_record_load_stream(rec, 2, file)) {
fprintf(stderr, "failed to load stream (%u)\n", r);
+ goto end;
+ }
- r = libmsi_database_open_query(db,
- "INSERT INTO `_Streams` (`Name`, `Data`) VALUES (?, ?)", &query);
- if (r != LIBMSI_RESULT_SUCCESS)
- fprintf(stderr, "failed to open query (%u)\n", r);
+ query = libmsi_query_new(db,
+ "INSERT INTO `_Streams` (`Name`, `Data`) VALUES (?, ?)", error);
+ if (!query)
+ goto end;
- if (!libmsi_query_execute(query, rec, error))
+ if (!libmsi_query_execute(query, rec, error)) {
fprintf(stderr, "failed to execute query\n");
+ goto end;
+ }
+
+ r = TRUE;
+
+end:
+ if (rec)
+ g_object_unref(rec);
+ if (query) {
+ libmsi_query_close(query, error);
+ g_object_unref(query);
+ }
- g_object_unref(rec);
- libmsi_query_close(query, error);
- g_object_unref(query);
return r;
}
static int do_query(const char *sql, void *opaque)
{
GError **error = opaque;
- LibmsiResult r;
+ LibmsiResult r = LIBMSI_RESULT_FUNCTION_FAILED;
LibmsiQuery *query;
- r = libmsi_database_open_query(db, sql, &query);
- if (r != LIBMSI_RESULT_SUCCESS) {
- fprintf(stderr, "failed to open query (%u)\n", r);
- return r;
+ query = libmsi_query_new(db, sql, error);
+ if (!query) {
+ fprintf(stderr, "failed to open query\n");
+ goto end;
}
- if (!libmsi_query_execute(query, NULL, error))
+ if (!libmsi_query_execute(query, NULL, error)) {
fprintf(stderr, "failed to execute query\n");
+ goto end;
+ }
+
+ r = LIBMSI_RESULT_SUCCESS;
+
+end:
+ if (query) {
+ libmsi_query_close(query, error);
+ g_object_unref(query);
+ }
- libmsi_query_close(query, error);
- g_object_unref(query);
return r;
}
@@ -297,7 +316,8 @@ int main(int argc, char *argv[])
break;
case 'a':
if (argc < 3) break;
- ret = add_stream(argv[1], argv[2], &error);
+ if (!add_stream(argv[1], argv[2], &error))
+ goto end;
argc -= 3, argv += 3;
break;
default:
diff --git a/tools/msiinfo.c b/tools/msiinfo.c
index 71fcba3..645c456 100644
--- a/tools/msiinfo.c
+++ b/tools/msiinfo.c
@@ -190,7 +190,7 @@ static int cmd_streams(struct Command *cmd, int argc, char **argv, GError **erro
{
LibmsiDatabase *db = NULL;
LibmsiQuery *query = NULL;
- LibmsiResult r;
+ int r = 1;
if (argc != 2) {
cmd_usage(stderr, cmd);
@@ -198,31 +198,33 @@ static int cmd_streams(struct Command *cmd, int argc, char **argv, GError **erro
db = libmsi_database_new(argv[1], LIBMSI_DB_OPEN_READONLY, error);
if (!db)
- return 1;
+ goto end;
- r = libmsi_database_open_query(db, "SELECT `Name` FROM `_Streams`", &query);
- if (r) {
- print_libmsi_error(r);
- }
+ query = libmsi_query_new(db, "SELECT `Name` FROM `_Streams`", error);
+ if (!query)
+ goto end;
- r = libmsi_query_execute(query, NULL, error);
+ libmsi_query_execute(query, NULL, error);
if (*error)
goto end;
print_strings_from_query(query, error);
+ r = 0;
end:
- g_object_unref(query);
- g_object_unref(db);
+ if (query)
+ g_object_unref(query);
+ if (db)
+ g_object_unref(db);
- return 0;
+ return r;
}
static int cmd_tables(struct Command *cmd, int argc, char **argv, GError **error)
{
LibmsiDatabase *db = NULL;
LibmsiQuery *query = NULL;
- LibmsiResult r;
+ int r = 1;
if (argc != 2) {
cmd_usage(stderr, cmd);
@@ -230,24 +232,26 @@ static int cmd_tables(struct Command *cmd, int argc, char **argv, GError **error
db = libmsi_database_new(argv[1], LIBMSI_DB_OPEN_READONLY, error);
if (!db)
- return 1;
+ goto end;
- r = libmsi_database_open_query(db, "SELECT `Name` FROM `_Tables`", &query);
- if (r) {
- print_libmsi_error(r);
- }
+ query = libmsi_query_new(db, "SELECT `Name` FROM `_Tables`", error);
+ if (!query)
+ goto end;
r = libmsi_query_execute(query, NULL, error);
if (*error)
goto end;
print_strings_from_query(query, error);
+ r = 0;
end:
- g_object_unref(query);
- g_object_unref(db);
+ if (query)
+ g_object_unref(query);
+ if (db)
+ g_object_unref(db);
- return 0;
+ return r;
}
static void print_suminfo(LibmsiSummaryInfo *si, int prop, const char *name)
@@ -365,7 +369,7 @@ static int cmd_extract(struct Command *cmd, int argc, char **argv, GError **erro
LibmsiDatabase *db = NULL;
LibmsiQuery *query = NULL;
LibmsiRecord *rec = NULL;
- LibmsiResult r;
+ int r = 1;
char *buf;
unsigned size, bufsize;
@@ -375,12 +379,11 @@ static int cmd_extract(struct Command *cmd, int argc, char **argv, GError **erro
db = libmsi_database_new(argv[1], LIBMSI_DB_OPEN_READONLY, error);
if (!db)
- return 1;
+ goto end;
- r = libmsi_database_open_query(db, "SELECT `Data` FROM `_Streams` WHERE `Name` = ?", &query);
- if (r) {
- print_libmsi_error(r);
- }
+ query = libmsi_query_new(db, "SELECT `Data` FROM `_Streams` WHERE `Name` = ?", error);
+ if (*error)
+ goto end;
rec = libmsi_record_new(1);
libmsi_record_set_string(rec, 1, argv[2]);
@@ -410,6 +413,8 @@ static int cmd_extract(struct Command *cmd, int argc, char **argv, GError **erro
size -= bufsize;
}
+ r = 0;
+
end:
if (rec)
g_object_unref(rec);
@@ -418,7 +423,7 @@ end:
if (db)
g_object_unref(db);
- return 0;
+ return r;
}
static unsigned export_create_table(const char *table,
@@ -598,20 +603,20 @@ static unsigned export_sql( LibmsiDatabase *db, const char *table, GError **erro
char *sql;
sql = g_strdup_printf("select * from `%s`", table);
- r = libmsi_database_open_query(db, sql, &query);
- if (r) {
- return r;
+ query = libmsi_query_new(db, sql, error);
+ if (*error) {
+ goto done;
}
/* write out row 1, the column names */
name = libmsi_query_get_column_info(query, LIBMSI_COL_INFO_NAMES, error);
- if (error) {
+ if (*error) {
goto done;
}
/* write out row 2, the column types */
type = libmsi_query_get_column_info(query, LIBMSI_COL_INFO_TYPES, error);
- if (error) {
+ if (*error) {
goto done;
}