Writing Data to MSI Database

2019-08-16 23:51发布

I need to be able to update a binary table and i do it like so:

View v = session.Database.OpenView("SELECT `Data` FROM `Binary` WHERE `Name` = '{0}'", binaryKeyName);

            v.Execute();

            var IsReadOnly = session.Database.IsReadOnly;

            Record r = v.Fetch();

            StreamReader reader = new StreamReader(r.GetStream("Data"));
            string text = reader.ReadToEnd();
            text = text.Replace(@"Test12345", "TTTest");

            byte[] byteArray = Encoding.ASCII.GetBytes(text);
            MemoryStream stream = new MemoryStream(byteArray);

Once I have the stream I would like to update database table. How do i do it?

Thanks

1条回答
Animai°情兽
2楼-- · 2019-08-17 00:44

The dtf.chm documentation, which comes with WiX, contains the following sample on how to update the binary table:

Database db = null;
View view = null;
Record rec = null;
try
{
    db = new Database("product.msi", DatabaseOpenMode.Direct);
    view = db.OpenView("UPDATE `Binary` SET `Data` = ? WHERE `Name` = '{0}'", binName))
    rec = new Record(1);
    rec.SetStream(1, binFile);
    view.Execute(rec);
    db.Commit();
}
finally
{
    if (rec != null) rec.Close();
    if (view != null) view.Close();
    if (db != null) db.Close();
}
查看更多
登录 后发表回答