3

私は次のことをしようとしています:

  1. インストール中にカスタムアクションを介してSQLファイルを開いて編集する
  2. 編集した変更を保存し、インストール中に実行します。

私のproduct.wxsには次のものがあります:

<Binary Id="SqlScriptSQLAuthentication"  SourceFile="$(sys.SOURCEFILEDIR)\MyDb.sql" />

        <Component Id='SqlComponent.SQLAuthentication' Guid='665D641C-3570-4b96-9CA5-2B4C12594A35' KeyPath='yes'>
            <Condition><![CDATA[USEINTEGRATEDSECURITY<>1]]></Condition>
            <sql:SqlDatabase Id='SqlDatabase.SQLAuthentication' Database='[DATABASE_NAME]' User='SQLUser' Server='[DATABASE_SERVER]' CreateOnInstall='yes' DropOnUninstall='yes' ContinueOnError='no' />
            <sql:SqlScript Id='SqlScriptSQLAuthentication' BinaryKey='SqlScriptSQLAuthentication' SqlDb='SqlDatabase.SQLAuthentication' ExecuteOnInstall='yes' />
        </Component>

セットアップ中に「MyDb.sql」を編集し、変更を書き込んで保存したいので、インストール中にwixを実行できます。

最善のアプローチは何ですか?ありがとう

編集:

MyDb.sql ファイル:

CREATE TABLE Test12345 (Value1 CHAR(50), Value2 INTEGER)

私のカスタムアクションには、次のものがあります。

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

        r.SetStream("Data", stream);

// ここまでは動作し、.sql ファイルから SQL テキストを読み取りました

    session.Database.ExecuteStringQuery("UPDATE `Binary` SET `Data` = '{0}' WHERE `Name` = '{1}')", text, binaryKeyName);

    v.Close();
    session.Database.Commit();

更新しようとすると(うまくいくかどうかわからない)、失敗します。

4

1 に答える 1

1

このカスタム アクションを使用して、バイナリ データを抽出できます。その後、変更を加えて再保存する必要があります。以前に行ったことがないので、バイナリに再保存する方法がわからない-一時データを使用許諾契約にストリーミングするために使用しました。これで良いスタートが切れるはずです。

HRESULT ExtractBinary(__in LPCWSTR wzBinaryId,
                      __out BYTE** pbData,
                      __out DWORD* pcbData)
{
    HRESULT hr = S_OK;
    LPWSTR pwzSql = NULL;
    PMSIHANDLE hView;
    PMSIHANDLE hRec;

    // make sure we're not horked from the get-go
    hr = WcaTableExists(L"Binary");
    if (S_OK != hr)
    {
        if (SUCCEEDED(hr))
        {
            hr = E_UNEXPECTED;
        }
        ExitOnFailure(hr, "There is no Binary table.");
    }

    ExitOnNull(wzBinaryId, hr, E_INVALIDARG, "Binary ID cannot be null");
    ExitOnNull(*wzBinaryId, hr, E_INVALIDARG, "Binary ID cannot be empty string");

    hr = StrAllocFormatted(&pwzSql, L"SELECT `Data` FROM `Binary` WHERE `Name`=\'%s\'", wzBinaryId);
    ExitOnFailure(hr, "Failed to allocate Binary table query.");

    hr = WcaOpenExecuteView(pwzSql, &hView);
    ExitOnFailure(hr, "Failed to open view on Binary table");

    hr = WcaFetchSingleRecord(hView, &hRec);
    ExitOnFailure(hr, "Failed to retrieve request from Binary table");

    hr = WcaGetRecordStream(hRec, 1, pbData, pcbData);
    ExitOnFailure(hr, "Failed to read Binary.Data.");

    LExit:
    ReleaseStr(pwzSql);

    return hr;
}
于 2013-01-25T09:35:17.237 に答える