数据库更改管理安装程序更新

时间:2015-05-25 08:04:37

标签: sql wix windows-installer wix3.8

如何根据某些条件运行一系列数据库脚本?

基本上我想检查安装在用户计算机上的构建,然后想要运行所有脚本,直到安装程序中构建。

假设用户已安装内部版本号4.10,如果他去安装版本4.15,那么我想运行版本4.111到4.15的SQL脚本。

我试过这个但是它说条件元素不能嵌套在SQL脚本元素中。

<sql:SqlScript Id="ScriptV11" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV11"  ContinueOnError="no" Sequence="11">
             <Condition>INSTALLED_BUILD < 4.11 </Condition>
 </sql:SqlScript>

任何帮助都将受到高度赞赏。

注意:使用注册表搜索设置INSTALLED_BUILD属性。

1 个答案:

答案 0 :(得分:2)

条件可以应用于组件,但是使用多个组件的问题是您不能依赖以任何特定顺序安装的组件。但是,您可以控制脚本的顺序。请参阅此相关问题:Can I ensure components installation order?

考虑到这一点,您真的想在安装程序中进行升级,您可以尝试以下方法:

<Component Id="UpgradeFromV410" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.10)</Condition>
    <sql:SqlScript Id="ScriptV10V11" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV11" ContinueOnError="no" Sequence="11"/>
    <sql:SqlScript Id="ScriptV10V12" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV12" ContinueOnError="no" Sequence="12"/>
    <sql:SqlScript Id="ScriptV10V13" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV13" ContinueOnError="no" Sequence="13"/>
    <sql:SqlScript Id="ScriptV10V14" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV14" ContinueOnError="no" Sequence="14"/>
    <sql:SqlScript Id="ScriptV10V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

<Component Id="UpgradeFromV411" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.11)</Condition>
    <sql:SqlScript Id="ScriptV11V12" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV12" ContinueOnError="no" Sequence="12"/>
    <sql:SqlScript Id="ScriptV11V13" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV13" ContinueOnError="no" Sequence="13"/>
    <sql:SqlScript Id="ScriptV11V14" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV14" ContinueOnError="no" Sequence="14"/>
    <sql:SqlScript Id="ScriptV11V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

<Component Id="UpgradeFromV412" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.12)</Condition>
    <sql:SqlScript Id="ScriptV12V13" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV13" ContinueOnError="no" Sequence="13"/>
    <sql:SqlScript Id="ScriptV12V14" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV14" ContinueOnError="no" Sequence="14"/>
    <sql:SqlScript Id="ScriptV12V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

<Component Id="UpgradeFromV413" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.13)</Condition>
    <sql:SqlScript Id="ScriptV13V14" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV14" ContinueOnError="no" Sequence="14"/>
    <sql:SqlScript Id="ScriptV13V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

<Component Id="UpgradeFromV414" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.14)</Condition>
    <sql:SqlScript Id="ScriptV13V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

作为一种解决方案,如果您的发布版本相对较少且很远,那么就可以了。如果您有频繁的发布计划,这个解决方案很快就会变得无法维护。

@Stein关于在开始时运行升级脚本的评论将为您提供更多控制,并且从长远来看更容易维护。