Commit 4d9c17da authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

msi: Don't execute the view again when modifying a WHERE query.

parent bcba82dc
......@@ -5887,6 +5887,107 @@ static void test_viewmodify_refresh(void)
DeleteFileA(msifile);
}
static void test_where_viewmodify(void)
{
MSIHANDLE hdb, hview, hrec;
const char *query;
UINT r;
DeleteFile(msifile);
r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
query = "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
r = run_query(hdb, 0, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
r = run_query(hdb, 0, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
r = run_query(hdb, 0, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
r = run_query(hdb, 0, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
/* `B` = 3 doesn't match, but the view shouldn't be executed */
query = "SELECT * FROM `Table` WHERE `B` = 3";
r = MsiDatabaseOpenView(hdb, query, &hview);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
hrec = MsiCreateRecord(2);
MsiRecordSetInteger(hrec, 1, 7);
MsiRecordSetInteger(hrec, 2, 8);
r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
MsiCloseHandle(hrec);
MsiViewClose(hview);
MsiCloseHandle(hview);
query = "SELECT * FROM `Table` WHERE `A` = 7";
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_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
r = MsiRecordGetInteger(hrec, 1);
ok(r == 7, "Expected 7, got %d\n", r);
r = MsiRecordGetInteger(hrec, 2);
ok(r == 8, "Expected 8, got %d\n", r);
MsiRecordSetInteger(hrec, 2, 9);
r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
MsiCloseHandle(hrec);
MsiViewClose(hview);
MsiCloseHandle(hview);
query = "SELECT * FROM `Table` WHERE `A` = 7";
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_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
r = MsiRecordGetInteger(hrec, 1);
ok(r == 7, "Expected 7, got %d\n", r);
r = MsiRecordGetInteger(hrec, 2);
ok(r == 9, "Expected 9, got %d\n", r);
query = "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
r = run_query(hdb, 0, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
r = MsiRecordGetInteger(hrec, 1);
ok(r == 7, "Expected 7, got %d\n", r);
r = MsiRecordGetInteger(hrec, 2);
ok(r == 10, "Expected 10, got %d\n", r);
MsiCloseHandle(hrec);
MsiViewClose(hview);
MsiCloseHandle(hview);
MsiCloseHandle(hdb);
}
START_TEST(db)
{
test_msidatabase();
......@@ -5923,4 +6024,5 @@ START_TEST(db)
test_noquotes();
test_forcecodepage();
test_viewmodify_refresh();
test_where_viewmodify();
}
......@@ -86,6 +86,9 @@ static UINT find_entry_in_hash(MSIHASHENTRY **table, UINT row, UINT *val)
{
MSIHASHENTRY *entry;
if (!table)
return ERROR_SUCCESS;
if (!(entry = table[row % MSI_HASH_TABLE_SIZE]))
{
WARN("Row not found in hash table!\n");
......@@ -503,15 +506,12 @@ static UINT WHERE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
MSIRECORD *rec, UINT row )
{
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
UINT r;
TRACE("%p %d %p\n", wv, eModifyMode, rec);
r = WHERE_execute(view, NULL);
if (r != ERROR_SUCCESS)
return r;
find_entry_in_hash(wv->reorder, row - 1, &row);
row++;
return wv->table->ops->modify( wv->table, eModifyMode, rec, row );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment