我正在使用liquibase和hsqldb数据库
我有一个带有'insert'指令的.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文件中的字符串中转义“ - ”?
答案 0 :(得分:0)
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字符串与用户定义的转义符一起使用。