If I execute the following query, I get ERROR_BAD_SYNTAX:
INSERT INTO RegLocator (RegLocator.Key) VALUES ('A')"
However, if I try to update any other RegLocator fields, I get ERROR_SUCCESS. What is up with RegLocator.Key ?
Posted 21 January 2002 - 18:47
If I execute the following query, I get ERROR_BAD_SYNTAX:
INSERT INTO RegLocator (RegLocator.Key) VALUES ('A')"
However, if I try to update any other RegLocator fields, I get ERROR_SUCCESS. What is up with RegLocator.Key ?
Posted 22 January 2002 - 11:03
WCHAR wszMsiPath[_MAX_PATH];
wcscpy(wszMsiPath, L"");
dwSize = _MAX_PATH;
if(MsiGetProductInfo(wszProductCode,
INSTALLPROPERTY_LOCALPACKAGE,
wszMsiPath,
&dwSize)==ERROR_SUCCESS)
{
// Open the database with read/write access
MSIHANDLE hDatabase, hView;
if(MsiOpenDatabase(wszMsiPath, MSIDBOPEN_DIRECT, &hDatabase) ==ERROR_SUCCESS)
{
if(hDatabase)
{
// Check the database has been opened with read/write access
if(MsiGetDatabaseState(hDatabase)==MSIDBSTATE_WRITE)
{
WCHAR wszSQLQuery[512];
PMSIHANDLE hRec;
// Update RegLocator table
wcscpy(wszSQLQuery, L"INSERT INTO RegLocator (RegLocator.Key) VALUES ('A')");
UINT nRes = MsiDatabaseOpenView(hDatabase, wszSQLQuery, &hView);
if( nRes == ERROR_BAD_QUERY_SYNTAX )
TRACE(L"Bad query");
else if( nRes == ERROR_INVALID_HANDLE )
TRACE(L"Invalid Handle");
else if( nRes == ERROR_SUCCESS)
TRACE(L"Success");
// Close all handles in use
MsiViewClose( hView );
MsiCloseHandle( hView );
}
}
}
}
Posted 22 January 2002 - 14:24
^(*!"£ !!!!!!!!
Posted 22 January 2002 - 15:13
Posted 22 January 2002 - 15:47
Weird.....and very annoying....
Posted 24 January 2002 - 01:19
I would definitely suggest using MsiViewModify to add records to a table. If you use MsiViewModify with the MSIMODIFY_VALIDATE_NEW flag, you can check for invalid data before you try to insert the row - good for checking primary key violations, etc.
If your data checks out, use MSIMODIFY_INSERT to add the new row.
e.g. adding a new record to the AppSearch table
void Example(MSIHANDLE hDatabase)
{
PMSIHANDLE hView, hRecord;
MsiDatabaseOpenView( hDatabase, "SELECT * FROM AppSearch", &hView );
hRecord = MsiCreateRecord(2);
MsiRecordSetString( hRecord, 1, "MyProperty" );
MsiRecordSetString( hRecord, 2, "MySignature" );
switch( MsiViewModify( hView, MSIMODIFY_VALIDATE_NEW, hRecord ) )
{
case ERROR_SUCCESS:
MsiModifyView( hView, MSIMODIFY_INSERT, hRecord );
break;
case MSIDBERROR_DUPLICATEKEY:
// ...
// other cases go here
}
}