Skip to content

Commit 6556c61

Browse files
committed
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.
1 parent e9cf5c1 commit 6556c61

11 files changed

+62
-62
lines changed

include/libmsi-types.h

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ typedef enum LibmsiResultError
4646
LIBMSI_RESULT_OPEN_FAILED,
4747
LIBMSI_RESULT_CALL_NOT_IMPLEMENTED,
4848
LIBMSI_RESULT_MORE_DATA,
49-
LIBMSI_RESULT_NO_MORE_ITEMS,
5049
LIBMSI_RESULT_NOT_FOUND,
5150
LIBMSI_RESULT_CONTINUE,
5251
LIBMSI_RESULT_UNKNOWN_PROPERTY,

libmsi/distinct.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static unsigned distinct_view_find_matching_rows( LibmsiView *view, unsigned col
240240
r = dv->table->ops->find_matching_rows( dv->table, col, val, row, handle );
241241

242242
if( *row > dv->row_count )
243-
return LIBMSI_RESULT_NO_MORE_ITEMS;
243+
return NO_MORE_ITEMS;
244244

245245
*row = dv->translation[ *row ];
246246

libmsi/libmsi-database.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ static unsigned merge_diff_row(LibmsiRecord *rec, void *param)
16961696
table->numconflicts++;
16971697
goto done;
16981698
}
1699-
else if (r != LIBMSI_RESULT_NO_MORE_ITEMS)
1699+
else if (r != NO_MORE_ITEMS)
17001700
goto done;
17011701

17021702
r = LIBMSI_RESULT_SUCCESS;

libmsi/libmsi-query.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ unsigned _libmsi_query_iterate_records( LibmsiQuery *view, unsigned *count,
251251
if( count )
252252
*count = n;
253253

254-
if( r == LIBMSI_RESULT_NO_MORE_ITEMS )
254+
if( r == NO_MORE_ITEMS )
255255
r = LIBMSI_RESULT_SUCCESS;
256256

257257
return r;
@@ -315,7 +315,7 @@ unsigned msi_view_get_row(LibmsiDatabase *db, LibmsiView *view, unsigned row, Li
315315
return LIBMSI_RESULT_INVALID_PARAMETER;
316316

317317
if (row >= row_count)
318-
return LIBMSI_RESULT_NO_MORE_ITEMS;
318+
return NO_MORE_ITEMS;
319319

320320
*rec = libmsi_record_new (col_count);
321321
if (!*rec)
@@ -402,11 +402,11 @@ LibmsiResult _libmsi_query_fetch(LibmsiQuery *query, LibmsiRecord **prec)
402402
* @query: a #LibmsiQuery
403403
* @error: (allow-none): return location for the error
404404
*
405-
* Return the next query result. A %LIBMSI_RESULT_NO_MORE_ITEMS error
406-
* is returned when the query result set has reached the end.
405+
* Return the next query result. %NULL is returned when there
406+
* is no more results.
407407
*
408-
* Returns: (transfer full): a newly allocated #LibmsiRecord
409-
* or %NULL when no results or failure.
408+
* Returns: (transfer full) (allow-none): a newly allocated
409+
* #LibmsiRecord or %NULL when no results or failure.
410410
**/
411411
LibmsiRecord *
412412
libmsi_query_fetch (LibmsiQuery *query, GError **error)
@@ -424,7 +424,8 @@ libmsi_query_fetch (LibmsiQuery *query, GError **error)
424424
g_object_unref(query);
425425

426426
/* FIXME: raise error when it happens */
427-
if (ret != LIBMSI_RESULT_SUCCESS)
427+
if (ret != LIBMSI_RESULT_SUCCESS &&
428+
ret != NO_MORE_ITEMS)
428429
g_set_error_literal (error, LIBMSI_RESULT_ERROR, ret, G_STRFUNC);
429430

430431
return record;

libmsi/msipriv.h

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ typedef enum LibmsiCondition
7272
#define MAX_STREAM_NAME_LEN 62
7373
#define LONG_STR_BYTES 3
7474

75+
#define NO_MORE_ITEMS G_MAXINT
76+
7577
#define MSITYPE_IS_BINARY(type) (((type) & ~MSITYPE_NULLABLE) == (MSITYPE_STRING|MSITYPE_VALID))
7678

7779
struct _LibmsiTable;

libmsi/storages.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static unsigned storages_view_fetch_int(LibmsiView *view, unsigned row, unsigned
8181
return LIBMSI_RESULT_INVALID_PARAMETER;
8282

8383
if (row >= sv->num_rows)
84-
return LIBMSI_RESULT_NO_MORE_ITEMS;
84+
return NO_MORE_ITEMS;
8585

8686
*val = sv->storages[row]->str_index;
8787

@@ -291,7 +291,7 @@ static unsigned storages_view_find_matching_rows(LibmsiView *view, unsigned col,
291291

292292
*handle = (MSIITERHANDLE)(uintptr_t)++index;
293293
if (index >= sv->num_rows)
294-
return LIBMSI_RESULT_NO_MORE_ITEMS;
294+
return NO_MORE_ITEMS;
295295

296296
return LIBMSI_RESULT_SUCCESS;
297297
}

libmsi/streams.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static unsigned streams_view_fetch_int(LibmsiView *view, unsigned row, unsigned
9393
return LIBMSI_RESULT_INVALID_PARAMETER;
9494

9595
if (row >= sv->num_rows)
96-
return LIBMSI_RESULT_NO_MORE_ITEMS;
96+
return NO_MORE_ITEMS;
9797

9898
*val = sv->streams[row]->str_index;
9999

@@ -332,7 +332,7 @@ static unsigned streams_view_find_matching_rows(LibmsiView *view, unsigned col,
332332
*handle = (MSIITERHANDLE)(uintptr_t)++index;
333333

334334
if (index > sv->num_rows)
335-
return LIBMSI_RESULT_NO_MORE_ITEMS;
335+
return NO_MORE_ITEMS;
336336

337337
return LIBMSI_RESULT_SUCCESS;
338338
}

libmsi/table.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ static unsigned table_view_fetch_int( LibmsiView *view, unsigned row, unsigned c
10251025

10261026
/* how many rows are there ? */
10271027
if( row >= tv->table->row_count )
1028-
return LIBMSI_RESULT_NO_MORE_ITEMS;
1028+
return NO_MORE_ITEMS;
10291029

10301030
if( tv->columns[col-1].offset >= tv->row_size )
10311031
{
@@ -1773,7 +1773,7 @@ static unsigned table_view_find_matching_rows( LibmsiView *view, unsigned col,
17731773

17741774
*handle = entry;
17751775
if (!entry)
1776-
return LIBMSI_RESULT_NO_MORE_ITEMS;
1776+
return NO_MORE_ITEMS;
17771777

17781778
*row = entry->row;
17791779

libmsi/where.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static unsigned init_reorder(LibmsiWhereView *wv)
107107
static inline unsigned find_row(LibmsiWhereView *wv, unsigned row, unsigned *(values[]))
108108
{
109109
if (row >= wv->row_count)
110-
return LIBMSI_RESULT_NO_MORE_ITEMS;
110+
return NO_MORE_ITEMS;
111111

112112
*values = wv->reorder[row]->values;
113113

@@ -927,7 +927,7 @@ static unsigned where_view_find_matching_rows( LibmsiView *view, unsigned col,
927927
}
928928
}
929929

930-
return LIBMSI_RESULT_NO_MORE_ITEMS;
930+
return NO_MORE_ITEMS;
931931
}
932932

933933
static unsigned where_view_sort(LibmsiView *view, column_info *columns)

tests/testdatabase.c

+40-41
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ static void query_check_no_more(LibmsiQuery *query)
291291
LibmsiRecord *hrec;
292292

293293
hrec = libmsi_query_fetch(query, &error);
294-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
295-
g_clear_error(&error);
294+
g_assert_no_error(error);
296295
ok(hrec == NULL, "hrec should be null\n");
297296
}
298297

@@ -379,24 +378,28 @@ static void test_msiinsert(void)
379378
hrec = NULL;
380379
sql = "SELECT * FROM `phone` WHERE `id` >= 10";
381380
r = do_query(hdb, sql, &hrec);
382-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
381+
ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
383382
ok(hrec == NULL, "hrec should be null\n");
384383

385384
sql = "SELECT * FROM `phone` WHERE `id` < 0";
386385
r = do_query(hdb, sql, &hrec);
387-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
386+
ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
387+
ok(hrec == NULL, "hrec should be null\n");
388388

389389
sql = "SELECT * FROM `phone` WHERE `id` <= 0";
390390
r = do_query(hdb, sql, &hrec);
391-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
391+
ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
392+
ok(hrec == NULL, "hrec should be null\n");
392393

393394
sql = "SELECT * FROM `phone` WHERE `id` <> 1";
394395
r = do_query(hdb, sql, &hrec);
395-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
396+
ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
397+
ok(hrec == NULL, "hrec should be null\n");
396398

397399
sql = "SELECT * FROM `phone` WHERE `id` > 10";
398400
r = do_query(hdb, sql, &hrec);
399-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "libmsi_query_fetch failed\n");
401+
ok(r == LIBMSI_RESULT_SUCCESS, "libmsi_query_fetch failed\n");
402+
ok(hrec == NULL, "hrec should be null\n");
400403

401404
/* now try a few bad INSERT xqueries */
402405
sql = "INSERT INTO `phone` ( `id`, `name`, `number` )"
@@ -1619,7 +1622,7 @@ static void test_where(void)
16191622

16201623
sql = "SELECT * FROM `Media` WHERE `DiskPrompt` = 'Cabinet'";
16211624
r = do_query(hdb, sql, &rec);
1622-
ok( r == LIBMSI_RESULT_NO_MORE_ITEMS, "query failed: %d\n", r );
1625+
ok( r == LIBMSI_RESULT_SUCCESS, "query failed: %d\n", r );
16231626
ok(rec == NULL, "Must be null");
16241627

16251628
rec = libmsi_record_new(1);
@@ -2577,8 +2580,8 @@ static void test_try_transform(void)
25772580
hrec = 0;
25782581
sql = "select * from `MOO` where `NOO` = 3";
25792582
r = do_query(hdb, sql, &hrec);
2580-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "select query failed\n");
2581-
if (hrec) g_object_unref(hrec);
2583+
ok(r == LIBMSI_RESULT_SUCCESS, "select query failed\n");
2584+
ok(hrec == NULL);
25822585

25832586
/* check added stream */
25842587
hrec = 0;
@@ -2910,8 +2913,7 @@ static void test_join(void)
29102913
}
29112914

29122915
ok( i == 5, "Expected 5 rows, got %d\n", i );
2913-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
2914-
g_clear_error(&error);
2916+
g_assert_no_error(error);
29152917

29162918
libmsi_query_close(hquery, NULL);
29172919
g_object_unref(hquery);
@@ -2971,8 +2973,7 @@ static void test_join(void)
29712973
ok( data_correct, "data returned in the wrong order\n");
29722974

29732975
ok( i == 2, "Expected 2 rows, got %d\n", i );
2974-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
2975-
g_clear_error(&error);
2976+
g_assert_no_error(error);
29762977

29772978
libmsi_query_close(hquery, NULL);
29782979
g_object_unref(hquery);
@@ -3012,8 +3013,7 @@ static void test_join(void)
30123013
ok( data_correct, "data returned in the wrong order\n");
30133014

30143015
ok( i == 2, "Expected 2 rows, got %d\n", i );
3015-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
3016-
g_clear_error(&error);
3016+
g_assert_no_error(error);
30173017

30183018
libmsi_query_close(hquery, NULL);
30193019
g_object_unref(hquery);
@@ -3053,7 +3053,7 @@ static void test_join(void)
30533053
ok( data_correct, "data returned in the wrong order\n");
30543054

30553055
ok( i == 1, "Expected 1 rows, got %d\n", i );
3056-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
3056+
g_assert_no_error(error);
30573057
g_clear_error(&error);
30583058

30593059
libmsi_query_close(hquery, NULL);
@@ -3095,8 +3095,7 @@ static void test_join(void)
30953095
ok( data_correct, "data returned in the wrong order\n");
30963096

30973097
ok( i == 1, "Expected 1 rows, got %d\n", i );
3098-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
3099-
g_clear_error(&error);
3098+
g_assert_no_error(error);
31003099

31013100
libmsi_query_close(hquery, NULL);
31023101
g_object_unref(hquery);
@@ -3136,8 +3135,7 @@ static void test_join(void)
31363135
ok( data_correct, "data returned in the wrong order\n");
31373136

31383137
ok( i == 6, "Expected 6 rows, got %d\n", i );
3139-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
3140-
g_clear_error(&error);
3138+
g_assert_no_error(error);
31413139

31423140
libmsi_query_close(hquery, NULL);
31433141
g_object_unref(hquery);
@@ -3178,8 +3176,7 @@ static void test_join(void)
31783176

31793177
ok( data_correct, "data returned in the wrong order\n");
31803178
ok( i == 3, "Expected 3 rows, got %d\n", i );
3181-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
3182-
g_clear_error(&error);
3179+
g_assert_no_error(error);
31833180

31843181
libmsi_query_close(hquery, NULL);
31853182
g_object_unref(hquery);
@@ -3217,8 +3214,7 @@ static void test_join(void)
32173214

32183215
ok( data_correct, "data returned in the wrong order\n");
32193216
ok( i == 6, "Expected 6 rows, got %d\n", i );
3220-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
3221-
g_clear_error(&error);
3217+
g_assert_no_error(error);
32223218

32233219
libmsi_query_close(hquery, NULL);
32243220
g_object_unref(hquery);
@@ -3267,8 +3263,7 @@ static void test_join(void)
32673263
ok( data_correct, "data returned in the wrong order\n");
32683264

32693265
ok( i == 6, "Expected 6 rows, got %d\n", i );
3270-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
3271-
g_clear_error(&error);
3266+
g_assert_no_error(error);
32723267

32733268
libmsi_query_close(hquery, NULL);
32743269
g_object_unref(hquery);
@@ -3317,8 +3312,7 @@ static void test_join(void)
33173312
ok( data_correct, "data returned in the wrong order\n");
33183313

33193314
ok( i == 6, "Expected 6 rows, got %d\n", i );
3320-
g_assert_error(error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS);
3321-
g_clear_error(&error);
3315+
g_assert_no_error(error);
33223316

33233317
libmsi_query_close(hquery, NULL);
33243318
g_object_unref(hquery);
@@ -3451,12 +3445,12 @@ static void test_temporary_table(void)
34513445
/* query the column data */
34523446
rec = 0;
34533447
r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
3454-
ok( r == LIBMSI_RESULT_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3455-
if (rec) g_object_unref( rec );
3448+
ok( r == LIBMSI_RESULT_SUCCESS, "temporary table exists in _Columns\n");
3449+
g_assert(rec == NULL);
34563450

34573451
r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
3458-
ok( r == LIBMSI_RESULT_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3459-
if (rec) g_object_unref( rec );
3452+
ok( r == LIBMSI_RESULT_SUCCESS, "temporary table exists in _Columns\n");
3453+
g_assert(rec == NULL);
34603454

34613455
g_object_unref( hdb );
34623456

@@ -3716,8 +3710,7 @@ static void test_integers(void)
37163710

37173711
sql = "SELECT * FROM `integers`";
37183712
r = do_query(hdb, sql, &rec);
3719-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
3720-
3713+
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
37213714
ok(rec == NULL, "Must be null");
37223715

37233716
/* insert legitimate values into it */
@@ -5897,7 +5890,8 @@ static void test_droptable(void)
58975890

58985891
sql = "SELECT * FROM `One`";
58995892
r = do_query(hdb, sql, &hrec);
5900-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
5893+
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
5894+
g_assert(hrec == NULL);
59015895

59025896
sql = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
59035897
hquery = libmsi_query_new(hdb, sql, NULL);
@@ -5984,19 +5978,22 @@ static void test_droptable(void)
59845978

59855979
sql = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
59865980
r = do_query(hdb, sql, &hrec);
5987-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
5981+
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
5982+
g_assert(hrec == NULL);
59885983

59895984
sql = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
59905985
r = do_query(hdb, sql, &hrec);
5991-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
5986+
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
5987+
g_assert(hrec == NULL);
59925988

59935989
sql = "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
59945990
r = run_query(hdb, 0, sql);
59955991
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_SUCCESS, got %d\n", r);
59965992

59975993
sql = "SELECT * FROM `One`";
59985994
r = do_query(hdb, sql, &hrec);
5999-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
5995+
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
5996+
g_assert(hrec == NULL);
60005997

60015998
sql = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
60025999
hquery = libmsi_query_new(hdb, sql, NULL);
@@ -6057,11 +6054,13 @@ static void test_droptable(void)
60576054

60586055
sql = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
60596056
r = do_query(hdb, sql, &hrec);
6060-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
6057+
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
6058+
g_assert(hrec == NULL);
60616059

60626060
sql = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
60636061
r = do_query(hdb, sql, &hrec);
6064-
ok(r == LIBMSI_RESULT_NO_MORE_ITEMS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
6062+
ok(r == LIBMSI_RESULT_SUCCESS, "Expected LIBMSI_RESULT_NO_MORE_ITEMS, got %d\n", r);
6063+
g_assert(hrec == NULL);
60656064

60666065
g_object_unref(hdb);
60676066
unlink(msifile);

0 commit comments

Comments
 (0)