cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
andyamstrad
Level 6

Steps for inserting a record into a msi database?

Basic Installshield project using Installscript:

Hi Im trying to insert a row into a custom table of another msi database, all functions succeed and I use a SetupDumpView to ensure the records have been written to the table. However when I open the MSI with the proposed changes they have not been committed.

Here is the sequence of code I use - note no params included.

MsiOpenDatabase - using MSIDBOPEN_TRANSACT flag - another msi database
MsiDatabaseOpenView
MsiViewExecute
MsiViewClose
MsiDatabaseCommit
MsiCloseHandle - Database
MsiCloseHandle - View


Am I missing something?
Labels (1)
0 Kudos
(9) Replies
RobertDickau
Flexera Alumni

The MSI help topic "Functions Not for Use in Custom Actions" mentions MsiOpenDatabase, so that might have a bearing on the issue...
0 Kudos
andyamstrad
Level 6

Hi Robert, yes just checked that.

Im using a custom action which in turn calls another function which calls those functions.

How else am I supposed to call them, if I cant call them from a custom action and why are they there then?

EDIT:

I dont think that is strictly true because I have used a sample project before to peform a replace/update on a different database using the MSIMODIFY_REPLACE flag. Only difference this time is my query is an INSERT instead of a SELECT???
0 Kudos
andyamstrad
Level 6

Perhaps if I use the WindowsInstaller COM interface that may work? Cant see why if the COM interface works why the API's wont??
0 Kudos
RobertDickau
Flexera Alumni

From memory, I can't speak to why the COM methods would work where the C-callable APIs wouldn't, but the reason the functions exist at all is that MSI authoring-type tools (including InstallShield) need those APIs to construct and populate an MSI database...
0 Kudos
andyamstrad
Level 6

So how do I get round the problem then?

Any ideas
0 Kudos
RobertDickau
Flexera Alumni

Are you using InstallShield 2008? What is the specific InstallScript code (and SQL query) that fails?
0 Kudos
andyamstrad
Level 6

Hi Robert

Yes Installshield 2008.

I got the functionality working before but it was bascially and find and replace e.g. an update (not an UPDATE SQL squery).

Im trying to use an INSERT SQL query. The newly inserted record appears when I dump the table contents to the console using a function called setupdumpview.

The code doesnt fail!! It just doesnt save/commit the record to the target msi database.

These are the steps :
- MsiOpenDatabase
- MsiDatabaseOpenView - using the SQL INSERT statement
- MsiViewExecute -
- MsiDatabaseCommit

The close all relevant handles and views.
0 Kudos
Not applicable

What is the return value of MsiDatabaseCommit and all the other APIs?

Also, are you verifying that the handle you're using is greater than 0? You may want to ensure that.
0 Kudos
andyamstrad
Level 6

Hi Bryan

MsiDatabaseCommit I check for ERROR_SUCCESS else raise the approriate error.

Something Ive just noticed that may shed a clue.

I have managed to get the COM (WindowsInstaller.Installer) interface to work 9using INSERT SQL statement) and NOT the MSI API's, however when I ran the code on a VMWARE it could only open the cached database in ready only mode, but on my physical machine I could open it in read/write mode. Is there a Windows security setting to prevent modication of the cached MSI database? This is obviously an additional problem.

I thought if the COM interface works then so should the MSI API's?
0 Kudos