[msitools] Remove LIBMSI_RESULT_NO_MORE_ITEMS from API
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [msitools] Remove LIBMSI_RESULT_NO_MORE_ITEMS from API
- Date: Thu, 17 Jan 2013 19:19:13 +0000 (UTC)
commit 6556c61586d79ee0ae599248f25d591d99da8a97
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Thu Jan 17 20:16:15 2013 +0100
Remove LIBMSI_RESULT_NO_MORE_ITEMS from API
Raising an error for indicating the end of the results is really
inconvenient, it's like throwing an exception for something quite
normal... The user can still make a distinction when there is an error
if the GError is set.
include/libmsi-types.h | 1 -
libmsi/distinct.c | 2 +-
libmsi/libmsi-database.c | 2 +-
libmsi/libmsi-query.c | 15 ++++----
libmsi/msipriv.h | 2 +
libmsi/storages.c | 4 +-
libmsi/streams.c | 4 +-
libmsi/table.c | 4 +-
libmsi/where.c | 4 +-
tests/testdatabase.c | 81 ++++++++++++++++++++++-----------------------
tools/msiinfo.c | 5 +--
11 files changed, 62 insertions(+), 62 deletions(-)
---
diff --git a/include/libmsi-types.h b/include/libmsi-types.h
index 58eefe0..d46a5c2 100644
--- a/include/libmsi-types.h
+++ b/include/libmsi-types.h
@@ -46,7 +46,6 @@ typedef enum LibmsiResultError
LIBMSI_RESULT_OPEN_FAILED,
LIBMSI_RESULT_CALL_NOT_IMPLEMENTED,
LIBMSI_RESULT_MORE_DATA,
- LIBMSI_RESULT_NO_MORE_ITEMS,
LIBMSI_RESULT_NOT_FOUND,
LIBMSI_RESULT_CONTINUE,
LIBMSI_RESULT_UNKNOWN_PROPERTY,
diff --git a/libmsi/distinct.c b/libmsi/distinct.c
index d134b03..f47a289 100644
--- a/libmsi/distinct.c
+++ b/libmsi/distinct.c
@@ -240,7 +240,7 @@ static unsigned distinct_view_find_matching_rows( LibmsiView *view, unsigned col
r = dv->table->ops->find_matching_rows( dv->table, col, val, row, handle );
if( *row > dv->row_count )
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
*row = dv->translation[ *row ];
diff --git a/libmsi/libmsi-database.c b/libmsi/libmsi-database.c
index 158c9ff..a8185a6 100644
--- a/libmsi/libmsi-database.c
+++ b/libmsi/libmsi-database.c
@@ -1696,7 +1696,7 @@ static unsigned merge_diff_row(LibmsiRecord *rec, void *param)
table->numconflicts++;
goto done;
}
- else if (r != LIBMSI_RESULT_NO_MORE_ITEMS)
+ else if (r != NO_MORE_ITEMS)
goto done;
r = LIBMSI_RESULT_SUCCESS;
diff --git a/libmsi/libmsi-query.c b/libmsi/libmsi-query.c
index eacbb8c..c61c23c 100644
--- a/libmsi/libmsi-query.c
+++ b/libmsi/libmsi-query.c
@@ -251,7 +251,7 @@ unsigned _libmsi_query_iterate_records( LibmsiQuery *view, unsigned *count,
if( count )
*count = n;
- if( r == LIBMSI_RESULT_NO_MORE_ITEMS )
+ if( r == NO_MORE_ITEMS )
r = LIBMSI_RESULT_SUCCESS;
return r;
@@ -315,7 +315,7 @@ unsigned msi_view_get_row(LibmsiDatabase *db, LibmsiView *view, unsigned row, Li
return LIBMSI_RESULT_INVALID_PARAMETER;
if (row >= row_count)
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
*rec = libmsi_record_new (col_count);
if (!*rec)
@@ -402,11 +402,11 @@ LibmsiResult _libmsi_query_fetch(LibmsiQuery *query, LibmsiRecord **prec)
* @query: a #LibmsiQuery
* @error: (allow-none): return location for the error
*
- * Return the next query result. A %LIBMSI_RESULT_NO_MORE_ITEMS error
- * is returned when the query result set has reached the end.
+ * Return the next query result. %NULL is returned when there
+ * is no more results.
*
- * Returns: (transfer full): a newly allocated #LibmsiRecord
- * or %NULL when no results or failure.
+ * Returns: (transfer full) (allow-none): a newly allocated
+ * #LibmsiRecord or %NULL when no results or failure.
**/
LibmsiRecord *
libmsi_query_fetch (LibmsiQuery *query, GError **error)
@@ -424,7 +424,8 @@ libmsi_query_fetch (LibmsiQuery *query, GError **error)
g_object_unref(query);
/* FIXME: raise error when it happens */
- if (ret != LIBMSI_RESULT_SUCCESS)
+ if (ret != LIBMSI_RESULT_SUCCESS &&
+ ret != NO_MORE_ITEMS)
g_set_error_literal (error, LIBMSI_RESULT_ERROR, ret, G_STRFUNC);
return record;
diff --git a/libmsi/msipriv.h b/libmsi/msipriv.h
index 9929e51..5241f9f 100644
--- a/libmsi/msipriv.h
+++ b/libmsi/msipriv.h
@@ -72,6 +72,8 @@ typedef enum LibmsiCondition
#define MAX_STREAM_NAME_LEN 62
#define LONG_STR_BYTES 3
+#define NO_MORE_ITEMS G_MAXINT
+
#define MSITYPE_IS_BINARY(type) (((type) & ~MSITYPE_NULLABLE) == (MSITYPE_STRING|MSITYPE_VALID))
struct _LibmsiTable;
diff --git a/libmsi/storages.c b/libmsi/storages.c
index 6829849..7846e69 100644
--- a/libmsi/storages.c
+++ b/libmsi/storages.c
@@ -81,7 +81,7 @@ static unsigned storages_view_fetch_int(LibmsiView *view, unsigned row, unsigned
return LIBMSI_RESULT_INVALID_PARAMETER;
if (row >= sv->num_rows)
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
*val = sv->storages[row]->str_index;
@@ -291,7 +291,7 @@ static unsigned storages_view_find_matching_rows(LibmsiView *view, unsigned col,
*handle = (MSIITERHANDLE)(uintptr_t)++index;
if (index >= sv->num_rows)
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
return LIBMSI_RESULT_SUCCESS;
}
diff --git a/libmsi/streams.c b/libmsi/streams.c
index 93e05cc..4760e18 100644
--- a/libmsi/streams.c
+++ b/libmsi/streams.c
@@ -93,7 +93,7 @@ static unsigned streams_view_fetch_int(LibmsiView *view, unsigned row, unsigned
return LIBMSI_RESULT_INVALID_PARAMETER;
if (row >= sv->num_rows)
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
*val = sv->streams[row]->str_index;
@@ -332,7 +332,7 @@ static unsigned streams_view_find_matching_rows(LibmsiView *view, unsigned col,
*handle = (MSIITERHANDLE)(uintptr_t)++index;
if (index > sv->num_rows)
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
return LIBMSI_RESULT_SUCCESS;
}
diff --git a/libmsi/table.c b/libmsi/table.c
index 16057e3..b01943c 100644
--- a/libmsi/table.c
+++ b/libmsi/table.c
@@ -1025,7 +1025,7 @@ static unsigned table_view_fetch_int( LibmsiView *view, unsigned row, unsigned c
/* how many rows are there ? */
if( row >= tv->table->row_count )
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
if( tv->columns[col-1].offset >= tv->row_size )
{
@@ -1773,7 +1773,7 @@ static unsigned table_view_find_matching_rows( LibmsiView *view, unsigned col,
*handle = entry;
if (!entry)
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
*row = entry->row;
diff --git a/libmsi/where.c b/libmsi/where.c
index fac7fa1..f0403bf 100644
--- a/libmsi/where.c
+++ b/libmsi/where.c
@@ -107,7 +107,7 @@ static unsigned init_reorder(LibmsiWhereView *wv)
static inline unsigned find_row(LibmsiWhereView *wv, unsigned row, unsigned *(values[]))
{
if (row >= wv->row_count)
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
*values = wv->reorder[row]->values;
@@ -927,7 +927,7 @@ static unsigned where_view_find_matching_rows( LibmsiView *view, unsigned col,
}
}
- return LIBMSI_RESULT_NO_MORE_ITEMS;
+ return NO_MORE_ITEMS;
}
static unsigned where_view_sort(LibmsiView *view, column_info *columns)
diff --git a/tests/testdatabase.c b/tests/testdatabase.c
index 30c4d54..9912246 100644
--- a/tests/testdatabase.c
+++ b/tests/testdatabase.c
@@ -291,8 +291,7 @@ static void query_check_no_more(LibmsiQuery *query)
LibmsiRecord *hrec;
hrec = libmsi_query_fetch(query, &error);
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
ok(hrec == NULL, "hrec should be null\n");
}
@@ -379,24 +378,28 @@ static void test_msiinsert(void)
hrec = NULL;
sql = "SELECT * FROM `phone` WHERE `id` >= 10";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
+ ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
ok(hrec == NULL, "hrec should be null\n");
sql = "SELECT * FROM `phone` WHERE `id` < 0";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
+ ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
+ ok(hrec == NULL, "hrec should be null\n");
sql = "SELECT * FROM `phone` WHERE `id` <= 0";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
+ ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
+ ok(hrec == NULL, "hrec should be null\n");
sql = "SELECT * FROM `phone` WHERE `id` <> 1";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
+ ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
+ ok(hrec == NULL, "hrec should be null\n");
sql = "SELECT * FROM `phone` WHERE `id` > 10";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
+ ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
+ ok(hrec == NULL, "hrec should be null\n");
/* now try a few bad INSERT xqueries */
sql = "INSERT INTO `phone` ( `id`, `name`, `number` )"
@@ -1619,7 +1622,7 @@ static void test_where(void)
sql = "SELECT * FROM `Media` WHERE `DiskPrompt` = 'Cabinet'";
r = do_query(hdb, sql, &rec);
- ok( r == LIBMSI_RESULT_NO_MORE_ITEMS, "query failed: %d\n", r );
+ ok( r == LIBMSI_RESULT_SUCCESS, "query failed: %d\n", r );
ok(rec == NULL, "Must be null");
rec = libmsi_record_new(1);
@@ -2577,8 +2580,8 @@ static void test_try_transform(void)
hrec = 0;
sql = "select * from `MOO` where `NOO` = 3";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "select query failed\n");
- if (hrec) g_object_unref(hrec);
+ ok(r == LIBMSI_RESULT_SUCCESS, "select query failed\n");
+ ok(hrec == NULL);
/* check added stream */
hrec = 0;
@@ -2910,8 +2913,7 @@ static void test_join(void)
}
ok( i == 5, "Expected 5 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
@@ -2971,8 +2973,7 @@ static void test_join(void)
ok( data_correct, "data returned in the wrong order\n");
ok( i == 2, "Expected 2 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
@@ -3012,8 +3013,7 @@ static void test_join(void)
ok( data_correct, "data returned in the wrong order\n");
ok( i == 2, "Expected 2 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
@@ -3053,7 +3053,7 @@ static void test_join(void)
ok( data_correct, "data returned in the wrong order\n");
ok( i == 1, "Expected 1 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
+ g_assert_no_error(error);
g_clear_error(&error);
libmsi_query_close(hquery, NULL);
@@ -3095,8 +3095,7 @@ static void test_join(void)
ok( data_correct, "data returned in the wrong order\n");
ok( i == 1, "Expected 1 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
@@ -3136,8 +3135,7 @@ static void test_join(void)
ok( data_correct, "data returned in the wrong order\n");
ok( i == 6, "Expected 6 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
@@ -3178,8 +3176,7 @@ static void test_join(void)
ok( data_correct, "data returned in the wrong order\n");
ok( i == 3, "Expected 3 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
@@ -3217,8 +3214,7 @@ static void test_join(void)
ok( data_correct, "data returned in the wrong order\n");
ok( i == 6, "Expected 6 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
@@ -3267,8 +3263,7 @@ static void test_join(void)
ok( data_correct, "data returned in the wrong order\n");
ok( i == 6, "Expected 6 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
@@ -3317,8 +3312,7 @@ static void test_join(void)
ok( data_correct, "data returned in the wrong order\n");
ok( i == 6, "Expected 6 rows, got %d\n", i );
- g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
- g_clear_error(&error);
+ g_assert_no_error(error);
libmsi_query_close(hquery, NULL);
g_object_unref(hquery);
@@ -3451,12 +3445,12 @@ static void test_temporary_table(void)
/* query the column data */
rec = 0;
r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
- ok( r == LIBMSI_RESULT_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
- if (rec) g_object_unref( rec );
+ ok( r == LIBMSI_RESULT_SUCCESS, "temporary table exists in _Columns\n");
+ g_assert(rec == NULL);
r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
- ok( r == LIBMSI_RESULT_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
- if (rec) g_object_unref( rec );
+ ok( r == LIBMSI_RESULT_SUCCESS, "temporary table exists in _Columns\n");
+ g_assert(rec == NULL);
g_object_unref( hdb );
@@ -3716,8 +3710,7 @@ static void test_integers(void)
sql = "SELECT * FROM `integers`";
r = do_query(hdb, sql, &rec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
-
+ ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
ok(rec == NULL, "Must be null");
/* insert legitimate values into it */
@@ -5897,7 +5890,8 @@ static void test_droptable(void)
sql = "SELECT * FROM `One`";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ g_assert(hrec == NULL);
sql = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
hquery = libmsi_query_new(hdb, sql, NULL);
@@ -5984,11 +5978,13 @@ static void test_droptable(void)
sql = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ g_assert(hrec == NULL);
sql = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ g_assert(hrec == NULL);
sql = "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
r = run_query(hdb, 0, sql);
@@ -5996,7 +5992,8 @@ static void test_droptable(void)
sql = "SELECT * FROM `One`";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ g_assert(hrec == NULL);
sql = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
hquery = libmsi_query_new(hdb, sql, NULL);
@@ -6057,11 +6054,13 @@ static void test_droptable(void)
sql = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ g_assert(hrec == NULL);
sql = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
r = do_query(hdb, sql, &hrec);
- ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
+ g_assert(hrec == NULL);
g_object_unref(hdb);
unlink(msifile);
diff --git a/tools/msiinfo.c b/tools/msiinfo.c
index 4dcaeca..55bf8ca 100644
--- a/tools/msiinfo.c
+++ b/tools/msiinfo.c
@@ -122,7 +122,6 @@ static void print_libmsi_error(LibmsiResultError r)
case LIBMSI_RESULT_CALL_NOT_IMPLEMENTED:
fprintf(stderr, "%s: not implemented\n", program_name);
exit(1);
- case LIBMSI_RESULT_NO_MORE_ITEMS:
case LIBMSI_RESULT_NOT_FOUND:
fprintf(stderr, "%s: not found\n", program_name);
exit(1);
@@ -180,7 +179,7 @@ static void print_strings_from_query(LibmsiQuery *query, GError **error)
g_object_unref(rec);
}
- if (!g_error_matches(err, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS))
+ if (err)
g_propagate_error(error, err);
g_clear_error(&err);
@@ -640,7 +639,7 @@ static gboolean export_sql( LibmsiDatabase *db, const char *table, GError **erro
}
}
- if (!g_error_matches(err, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS)) {
+ if (err) {
g_propagate_error(error, err);
success = FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]