This line here is merely doing a String.Format to build the query string:
        database.OpenView("Insert into Binary (`Name`,`Data`) VALUES ({0}, 
{1})", record.GetString(1),  record.GetStream(2));
Calling ToString() on a RecordStream instance happens to result in the literal 
string "[Binary Data]".

What you want is record field binding, like this:
        view = database.OpenView("Insert into Binary (`Name`,`Data`) VALUES (?, 
?)");
        view.Execute(record);

DTF provides both String.Format style parameter substitution and record field 
binding because each is very useful in its own different way.. The difference 
is subtle but important.

By the way, for inserts I recommend using one of the Database.Execute() 
shortcut method overloads, which will manage creation of the view for you.


-----Original Message-----
From: Lewis99 [mailto:[email protected]] 
Sent: Thursday, May 14, 2009 11:24 AM
To: [email protected]
Subject: [WiX-devs] Insert to the Binary table failing


Hi all,

I am trying to insert a custom action dll programatically into an MSI database 
using the following code:

private void InsertCustomActionDll(string msiLocation)
    {
      //get the records in memory
      Database database = new Database(msiLocation, DatabaseOpenMode.Direct);

      Record record = new Record(2);
      record.FormatString = "Name = [1], Data = [Binary Data]";
      record.SetString(1, "TyrellTest");
      record.SetStream(2, @"TestCustomActions.CA.dll");
      

      Microsoft.Deployment.WindowsInstaller.View view =
        database.OpenView("Insert into Binary (`Name`,`Data`) VALUES ({0}, 
{1})", record.GetString(1),  record.GetStream(2));

      view.Execute();
      view.Close();

      database.Close();
    }

However, it fails with the following InstallerException: Message = "SQL query 
syntax invalid or unsupported. Database: MyMSI.msi. Invalid identifier 
'[Binary' in SQL query: Insert into Binary (`Name`,`Data`) VALUES ('Test', 
[Binary data])"

Does anyone have any idea why? I would have thought using
record.GetStream(2) would ensure that it was attempting to insert a stream type.

Thanks in advance.
Lewis
--
View this message in context: 
http://n2.nabble.com/Insert-to-the-Binary-table-failing-tp2897616p2897616.html
Sent from the wix-devs mailing list archive at Nabble.com.


------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
WiX-devs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wix-devs


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
WiX-devs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wix-devs

Reply via email to