summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2012-12-17 15:31:31 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2013-01-09 13:56:07 +0100
commit3bddf664dc9c491660c2ab91630a9b50163214e5 (patch)
tree76d45e40af22508ac55cd41cb2ce8cef4286008e
parentb1efff0fdee6d986df33ec13d9d64808bf2619b6 (diff)
downloadmsitools-3bddf664dc9c491660c2ab91630a9b50163214e5.tar.gz
msitools-3bddf664dc9c491660c2ab91630a9b50163214e5.tar.xz
msitools-3bddf664dc9c491660c2ab91630a9b50163214e5.zip
database: make is_table_persistent() return a boolean
-rw-r--r--include/libmsi-database.h5
-rw-r--r--include/libmsi-types.h8
-rw-r--r--libmsi/libmsi-database.c21
-rw-r--r--libmsi/msipriv.h8
-rw-r--r--tests/testdatabase.c57
5 files changed, 56 insertions, 43 deletions
diff --git a/include/libmsi-database.h b/include/libmsi-database.h
index 2ea23bb..a933281 100644
--- a/include/libmsi-database.h
+++ b/include/libmsi-database.h
@@ -61,8 +61,9 @@ gboolean libmsi_database_import (LibmsiDatabase *db,
const char *folder,
const char *filename,
GError **error);
-LibmsiCondition libmsi_database_is_table_persistent (LibmsiDatabase *db,
- const char *table);
+gboolean libmsi_database_is_table_persistent (LibmsiDatabase *db,
+ const char *table,
+ GError **error);
gboolean libmsi_database_merge (LibmsiDatabase *db,
LibmsiDatabase *merge,
const char *table,
diff --git a/include/libmsi-types.h b/include/libmsi-types.h
index f23398e..b0ab310 100644
--- a/include/libmsi-types.h
+++ b/include/libmsi-types.h
@@ -34,14 +34,6 @@ typedef struct _LibmsiQuery LibmsiQuery;
typedef struct _LibmsiRecord LibmsiRecord;
typedef struct _LibmsiSummaryInfo LibmsiSummaryInfo;
-typedef enum LibmsiCondition
-{
- LIBMSI_CONDITION_FALSE = 0,
- LIBMSI_CONDITION_TRUE = 1,
- LIBMSI_CONDITION_NONE = 2,
- LIBMSI_CONDITION_ERROR = 3,
-} LibmsiCondition;
-
typedef enum LibmsiResultError
{
LIBMSI_RESULT_SUCCESS, // FIXME: remove me
diff --git a/libmsi/libmsi-database.c b/libmsi/libmsi-database.c
index 0720cc3..580cb7e 100644
--- a/libmsi/libmsi-database.c
+++ b/libmsi/libmsi-database.c
@@ -2443,20 +2443,29 @@ libmsi_database_get_primary_keys (LibmsiDatabase *db,
return rec;
}
-LibmsiCondition libmsi_database_is_table_persistent(
- LibmsiDatabase *db, const char *szTableName)
+gboolean
+libmsi_database_is_table_persistent (LibmsiDatabase *db, const char *table,
+ GError **error)
{
LibmsiCondition r;
- TRACE("%x %s\n", db, debugstr_a(szTableName));
+ TRACE("%p %s\n", db, debugstr_a(table));
- g_return_val_if_fail(LIBMSI_IS_DATABASE(db), LIBMSI_CONDITION_ERROR);
+ g_return_val_if_fail (LIBMSI_IS_DATABASE (db), LIBMSI_CONDITION_ERROR);
+ g_return_val_if_fail (table != NULL, NULL);
+ g_return_val_if_fail (!error || *error == NULL, NULL);
g_object_ref(db);
- r = _libmsi_database_is_table_persistent( db, szTableName );
+ r = _libmsi_database_is_table_persistent( db, table );
g_object_unref(db);
- return r;
+ if (r == LIBMSI_CONDITION_NONE)
+ g_set_error (error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_INVALID_TABLE,
+ "The table is unknown");
+ else if (r == LIBMSI_CONDITION_ERROR)
+ g_set_error (error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_FUNCTION_FAILED, "");
+
+ return r == LIBMSI_CONDITION_TRUE;
}
/* TODO: use GInitable */
diff --git a/libmsi/msipriv.h b/libmsi/msipriv.h
index 8ff0aee..a74f9a5 100644
--- a/libmsi/msipriv.h
+++ b/libmsi/msipriv.h
@@ -50,6 +50,14 @@
#define MAX_PATH PATH_MAX
#endif
+typedef enum LibmsiCondition
+{
+ LIBMSI_CONDITION_FALSE = 0,
+ LIBMSI_CONDITION_TRUE = 1,
+ LIBMSI_CONDITION_NONE = 2,
+ LIBMSI_CONDITION_ERROR = 3,
+} LibmsiCondition;
+
#define MSI_DATASIZEMASK 0x00ff
#define MSITYPE_VALID 0x0100
#define MSITYPE_LOCALIZABLE 0x200
diff --git a/tests/testdatabase.c b/tests/testdatabase.c
index 4a2812f..13180d1 100644
--- a/tests/testdatabase.c
+++ b/tests/testdatabase.c
@@ -3332,7 +3332,7 @@ static void test_join(void)
static void test_temporary_table(void)
{
GError *error = NULL;
- LibmsiCondition cond;
+ gboolean cond;
LibmsiDatabase *hdb = 0;
LibmsiQuery *query = 0;
LibmsiRecord *rec;
@@ -3344,41 +3344,42 @@ static void test_temporary_table(void)
hdb = create_db();
ok( hdb, "failed to create db\n");
- cond = libmsi_database_is_table_persistent(hdb, NULL);
- ok( cond == LIBMSI_CONDITION_ERROR, "wrong return condition\n");
-
- cond = libmsi_database_is_table_persistent(hdb, "_Tables");
- ok( cond == LIBMSI_CONDITION_NONE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "_Tables", &error);
+ g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_INVALID_TABLE);
+ g_clear_error(&error);
- cond = libmsi_database_is_table_persistent(hdb, "_Columns");
- ok( cond == LIBMSI_CONDITION_NONE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "_Columns", &error);
+ g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_INVALID_TABLE);
+ g_clear_error(&error);
- cond = libmsi_database_is_table_persistent(hdb, "_Storages");
- ok( cond == LIBMSI_CONDITION_NONE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "_Storages", &error);
+ g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_INVALID_TABLE);
+ g_clear_error(&error);
- cond = libmsi_database_is_table_persistent(hdb, "_Streams");
- ok( cond == LIBMSI_CONDITION_NONE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "_Streams", &error);
+ g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_INVALID_TABLE);
+ g_clear_error(&error);
sql = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
r = run_query(hdb, 0, sql);
ok(r == LIBMSI_RESULT_SUCCESS, "failed to add table\n");
- cond = libmsi_database_is_table_persistent(hdb, "P");
- ok( cond == LIBMSI_CONDITION_TRUE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "P", NULL);
+ ok(cond, "wrong return condition\n");
sql = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
r = run_query(hdb, 0, sql);
ok(r == LIBMSI_RESULT_SUCCESS, "failed to add table\n");
- cond = libmsi_database_is_table_persistent(hdb, "P2");
- ok( cond == LIBMSI_CONDITION_TRUE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "P2", NULL);
+ ok(cond, "wrong return condition\n");
sql = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
r = run_query(hdb, 0, sql);
ok(r == LIBMSI_RESULT_SUCCESS, "failed to add table\n");
- cond = libmsi_database_is_table_persistent(hdb, "T");
- ok( cond == LIBMSI_CONDITION_FALSE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "T", NULL);
+ ok(!cond, "wrong return condition\n");
sql = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
r = run_query(hdb, 0, sql);
@@ -3390,22 +3391,24 @@ static void test_temporary_table(void)
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_BAD_QUERY_SYNTAX);
g_clear_error(&error);
- cond = libmsi_database_is_table_persistent(hdb, "T2");
- ok( cond == LIBMSI_CONDITION_NONE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "T2", &error);
+ g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_INVALID_TABLE);
+ g_clear_error(&error);
sql = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
r = run_query(hdb, 0, sql);
ok(r == LIBMSI_RESULT_SUCCESS, "failed to add table\n");
- cond = libmsi_database_is_table_persistent(hdb, "T3");
- ok( cond == LIBMSI_CONDITION_TRUE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "T3", NULL);
+ ok(cond, "wrong return condition\n");
sql = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
r = run_query(hdb, 0, sql);
ok(r == LIBMSI_RESULT_FUNCTION_FAILED, "failed to add table\n");
- cond = libmsi_database_is_table_persistent(hdb, "T4");
- ok( cond == LIBMSI_CONDITION_NONE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "T4", &error);
+ g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_INVALID_TABLE);
+ g_clear_error(&error);
sql = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
r = run_query(hdb, 0, sql);
@@ -3448,7 +3451,7 @@ static void test_temporary_table(void)
static void test_alter(void)
{
- LibmsiCondition cond;
+ gboolean cond;
LibmsiDatabase *hdb = 0;
const char *sql;
unsigned r;
@@ -3460,8 +3463,8 @@ static void test_alter(void)
r = run_query(hdb, 0, sql);
ok(r == LIBMSI_RESULT_SUCCESS, "failed to add table\n");
- cond = libmsi_database_is_table_persistent(hdb, "T");
- ok( cond == LIBMSI_CONDITION_FALSE, "wrong return condition\n");
+ cond = libmsi_database_is_table_persistent(hdb, "T", NULL);
+ ok(!cond, "wrong return condition\n");
sql = "ALTER TABLE `T` HOLD";
r = run_query(hdb, 0, sql);