Reputation: 81
MSI has table - 'FeatureComponents' with two columns: 'Feature_' and 'Component_'. What I'm trying to do is to change all values in 'Feature_' column at once.
IntPtr hDb = IntPtr.Zero;
int res = MsiInvoke.MsiOpenDatabase(PathToMsi, MsiInvoke.MSIDBOPEN_TRANSACT, out hDb);
string FFF = "SELECT `Feature_` FROM `FeatureComponents`"; <- sql string
IntPtr hView2 = IntPtr.Zero;
res = MsiInvoke.MsiDatabaseOpenView(hDb, FFF, out hView2);
res = MsiInvoke.MsiViewExecute(hView2, IntPtr.Zero);
IntPtr hRec2 = IntPtr.Zero;
res = MsiInvoke.MsiViewFetch(hView2, out hRec2);
res = MsiInvoke.MsiRecordSetString(hRec2, 1, "DUMMY");
res = MsiInvoke.MsiViewModify(hView2, 4, hRec2);
res = MsiInvoke.MsiViewClose(hView2);
res = MsiInvoke.MsiDatabaseCommit(hDb);
However, this only changes first entry in table. So, I'm wondering, how to iterate over all entries in table and change all column values? As right now, I can only do this to one entry and have no idea how to apply this to all entries.
Upvotes: 0
Views: 169
Reputation: 20780
Basically you just turn that fetching code into a loop, and you keep calling MsiViewFetch until you get the ERROR_NO_MORE_ITEMS result, each call returning the next record until you get that error. Simple old example in C++ but the principle is the same:
while ( (errorI = MsiViewFetch (hViewSELECT, &hRecord)) != ERROR_NO_MORE_ITEMS)
nBuffer = (DWORD)256;
MsiRecordGetString(hRecord, 1, svPropname, &nBuffer);
nBuffer = (DWORD)256;
MsiRecordGetString(hRecord, 2, svPropvalue, nBuffer);
}
Upvotes: 1