Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Problem with RegLocator Update


5 replies to this topic

JasonAtkins2001

JasonAtkins2001
  • Members
  • 14 posts

Posted 21 January 2002 - 18:47

I am attempting to update the RegLocator table via a C++ app using the MsiDatabaseOpenView API.

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 ?


JasonAtkins2001

JasonAtkins2001
  • Members
  • 14 posts

Posted 22 January 2002 - 11:03

The full snippet of code is below. I really would appreciate some help on this....

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 );
                  }
           }
    }
}


JasonAtkins2001

JasonAtkins2001
  • Members
  • 14 posts

Posted 22 January 2002 - 14:24

It seems that INSERT INTO doesn't always work. Therefore, I've found that you can also use MsiViewModify by using SELECT * FROM RegLocator
to get the recordset and then MsiViewModify's MSIMODIFY_INSERT flag instead.

^(*!"£ !!!!!!!!


Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 22 January 2002 - 15:13

Wouldn't INSERT INTO require that you specify data for all columns in the new row?

JasonAtkins2001

JasonAtkins2001
  • Members
  • 14 posts

Posted 22 January 2002 - 15:47

That's right. I did start by attempting to use INSERT INTO with values for all fields of the RegLocator. It seems MsiDatabaseOpenView is fine with all fields, except for RegLocator.Key.

Weird.....and very annoying....


KiwiGeek

KiwiGeek
  • Members
  • 19 posts

Posted 24 January 2002 - 01:19

I'm not surprised that the SQL queries are a little buggy, especially when MS decided to only implement a small subset of the query language.

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
 }
}