如何在带有loadData更改的MSSQL的Liquibase 3.5中将'GETDATE()'字符串输出到字符串列中?

时间:2019-02-08 13:41:40

标签: java sql-server liquibase

我有liquibase loadData更改:

<changeSet author="author" id="13">
        <sql>SET IDENTITY_INSERT M_Conversion ON</sql>
        <loadData tableName="M_Conversion" separator="~" file="data/13-M_Conversion.csv">
            <column name="MconID" type="NUMERIC" />
            <column name="MdbtID" type="NUMERIC" />
            <column name="MlokID" type="NUMERIC" />
            <column name="MconKeyword" type="STRING" />
            <column name="MconExtra" type="STRING" />
        </loadData>
        <sql>SET IDENTITY_INSERT M_Conversion OFF</sql>
        <rollback>
            <sql>SET IDENTITY_INSERTM_Conversion OFF</sql>
        </rollback>
</changeSet> 

在13-M_Conversion.csv文件中,有一个值会引起MSSQL问题:201~2~200~GETDATE()~ MconKeyword列的GETDATE()值在生成的sql中未用字符串引用

liquibase为此数据生成的sql是: INSERT INTO [pd].[M_Conversion] ([MconID], [MdbtID], [MlokID], [MconKeyword], [MconExtra]) VALUES (201, 2, 200, GETDATE());,但应为(201, 2, 200, 'GETDATE()')

问题是,在方法liquibase.sqlgenerator.core.InsertGenerator#generateValues中,对于字符串值,存在调用以检查字符串是否类似于函数调用

public boolean looksLikeFunctionCall(String value, Database database) {
        return value.startsWith("\"SYSIBM\"") || value.startsWith("to_date(") || value.equalsIgnoreCase(database.getCurrentDateTimeFunction());
    }

,对于MSSQLDatabase,GETDATE()完全是currentDateTimeFunction

问题是,如何通过loadData更改正确地转义此特定值?

0 个答案:

没有答案