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

UPDATE SQL Statement Help Required


2 replies to this topic

Dave I

Dave I
  • Members
  • 195 posts

Posted 30 October 2001 - 12:11

Can somebody tell me whats wrong with the following SQL Update statement:

cscript wirunsql.vbs "C:\My.msi" "UPDATE Directory SET Directory='dIR202'  WHERE Directory='DIR202'"

It should simply do a "find and replace" on DIR202 with the entry
dIR202, but alas no joy.  I can do a "Find and Replace" on any other
column in the table but not the one I require, the directory key
column.  This one works:

cscript wirunsql.vbs "C:\My.msi" "UPDATE Directory SET
Directory.Directory_Parent='ThisWorks' WHERE
Directory=Directory_Parent'CommonFilesFolder'"

N.B. wirunsq.vbs is in the Platform SDK....Windows
Installer\Samples\Scripts, so just change to this directory to run it and create a dummy msi file in C:\

I have tried various possibilities Directory.Directory when specifiying the column, different quotes, all sorts.  
Could be a red herring but it seems to fail if the table has the same name as the column.

Any help would be greatly appreciated.
Dave


Dave I

Dave I
  • Members
  • 195 posts

Posted 31 October 2001 - 11:46

It appears that Update queries only work on non-primary key columns. The Directory column is
a primary key of the Directory table.  Not very well documented but there you go.  Heres the workaround if anyone else had this problem:

#include "Windows.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "Msi.h"
#include "MsiDefs.h"
#include "MsiQuery.h"


int main(int argc, char* argv[])
{
 PMSIHANDLE hMSI, hView;
 PMSIHANDLE hRec1;

 const int MAX_BUFFER=2000;

 MsiOpenDatabase("c:\\my.msi", MSIDBOPEN_TRANSACT, &hMSI);
 MsiDatabaseOpenView(hMSI, "SELECT * from Directory", &hView);
 MsiViewExecute(hView, 0);
 
 while (ERROR_SUCCESS == MsiViewFetch(hView, &hRec1))
 {
   PMSIHANDLE hVwComponent;
   TCHAR      szBuff[MAX_BUFFER];
   DWORD      dwSize = MAX_BUFFER;

   MsiRecordGetString(hRec1, 1, szBuff, &dwSize);
   
//    ...modify name of directory entry HERE
   //
   if (isdigit(szBuff[3]))
{
_strlwr(szBuff);
MsiRecordSetString(hRec1, 1, szBuff);
MsiViewModify(hView, MSIMODIFY_REPLACE, hRec1);
}
   
 }

 MsiDatabaseCommit(hMSI);
 return 0;
}

Obviously you have to do the save on Directory.Directory_Parent, CreateFolder and Component.Directory_

Dave.


sairam06

sairam06
  • Members
  • 7 posts

Posted 02 December 2001 - 21:24

Hello,


Is their and ODBC/OLEDB Driver for accessing the MSI Database Table directly from Visual Basic?

I need to write some application which query the msi database and obtain different information for validation/documentation purpose and writes to SQL Database before releasing the product. If any driver is available I can customize it for my requirements (Like Accessing Access database from Visual Basic)

I appreciate any feedback.

Thanks.