msi: Handle sorting an empty table.

This commit is contained in:
James Hawkins 2008-04-02 03:47:24 -05:00 committed by Alexandre Julliard
parent 9cd9023db6
commit bed661aef4
2 changed files with 19 additions and 0 deletions

View File

@ -2054,6 +2054,9 @@ static UINT TABLE_sort(struct tagMSIVIEW *view, column_info *columns)
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
return r; return r;
if (rows == 0)
return ERROR_SUCCESS;
order = msi_alloc_zero(sizeof(MSIORDERINFO) + sizeof(UINT) * cols); order = msi_alloc_zero(sizeof(MSIORDERINFO) + sizeof(UINT) * cols);
if (!order) if (!order)
return ERROR_OUTOFMEMORY; return ERROR_OUTOFMEMORY;

View File

@ -4777,6 +4777,10 @@ static void test_order(void)
hdb = create_db(); hdb = create_db();
ok(hdb, "failed to create db\n"); ok(hdb, "failed to create db\n");
query = "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
r = run_query(hdb, 0, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
query = "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)"; query = "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
r = run_query(hdb, 0, query); r = run_query(hdb, 0, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
@ -4962,6 +4966,18 @@ static void test_order(void)
r = MsiViewFetch(hview, &hrec); r = MsiViewFetch(hview, &hrec);
ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r); ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
MsiViewClose(hview);
MsiCloseHandle(hview);
query = "SELECT * FROM `Empty` ORDER BY `A`";
r = MsiDatabaseOpenView(hdb, query, &hview);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
r = MsiViewExecute(hview, 0);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
r = MsiViewFetch(hview, &hrec);
ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
MsiViewClose(hview); MsiViewClose(hview);
MsiCloseHandle(hview); MsiCloseHandle(hview);
MsiCloseHandle(hdb); MsiCloseHandle(hdb);