我正在使用liquibase和hsqldb数据库。
我有一个.sql文件,其中带有“插入”指令,用于在引导程序中填充数据库,但是如果一个字符串包含彼此靠近的两个减号,它将被解释为注释而不是字符串。
这是我在liquibase加载的.sql文件中的sql指令:

INSERT INTO user (id,firstname,lastname,mystring) VALUES
(11,'Wendy','Salinas','this is my string--and it continues'),
(12,'Kirsten','Parker','this is the string of Kirsten')


而我的堆栈跟踪:

liquibase.exception.DatabaseException: Error executing SQL INSERT INTO user     (id,firstname,lastname,mystring) VALUES
(11,'Wendy','Salinas','this is my string
(12,'Kirsten','Parker','this is the string of Kristen')
Caused by: java.sql.SQLSyntaxErrorException: unexpected token: KIRSTEN required: ) : line: 12
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at liquibase.executor.jvm.JdbcExecutor$1ExecuteStatementCallback.doInStatement(JdbcExecutor.java:92)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)


有没有一种方法可以逃避liquibase使用的sql文件的字符串中的注释?
如何在liquibase使用的.sql文件的字符串中转义'-'?

最佳答案

HSQLDB允许您通过将字符串分为两部分来解决此限制:

INSERT INTO user (id,firstname,lastname,mystring) VALUES
(11,'Wendy','Salinas','this is my string-'  '-and it continues'),
(12,'Kirsten','Parker','this is the string of Kirsten')


在下一版本2.3.0中,您还可以将unicode字符串与用户定义的转义一起使用。

10-08 12:59