I am trying to use dbunit-express in my java project to create some tables and functions on postgress in Junit tests.
我试图在我的java项目中使用dbunit-express来在Junit测试中创建一些表和函数。
I use this driver :
我使用这个驱动程序:
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.2-1003-jdbc4</version>
The java class...
java类…
@Rule
public EmbeddedDbTesterRule testDb = new EmbeddedDbTesterRule(); // with this you don't neet to call onSetup
@Test
public void testIt() throws Exception {
try {
DatabaseCreator databaseCreator = new DatabaseCreator();
databaseCreator.setDdlFile("HistoryTables.ddl");
databaseCreator.doCreateDbSchemaFromDdl(testDb.getSqlConnection());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
But I get this error...
但是我得到了这个错误……
org.postgresql.util.PSQLException: ERROR: unterminated dollar-quoted string at or near "$BODY$
org.postgresql.util。PSQLException:错误:在“$BODY$ $”或“$BODY$”附近的未终止的以美元报价的字符串
The function looks like this.
函数是这样的。
CREATE OR REPLACE FUNCTION product_history()
RETURNS trigger AS
$BODY$
BEGIN
INSERT INTO product_history (id, product_id, edit_ts, name, print_provider_id, description)
VALUES (nextval('product_history_sequence'), OLD.id, now(), OLD.name, OLD.print_provider_id, OLD.description);
RETURN NULL;
END;
$BODY$
LANGUAGE plpgsql;
The create works fine in PGAdmin 1.14.3 and in DBVisualizer 9.0.8
create在PGAdmin 1.14.3和DBVisualizer 9.0.8中工作得很好
1 个解决方案
#1
1
Is the create function
code included in HistoryTables.ddl
? If yes the error might be caused by a limitation of DatabaseCreator
. It splits statements read from the ddl file at ;
(see line 127 of the source code. The function is therefore splitted into multiple statements disturbing the syntax.
create函数代码是否包含在historytable .ddl中?如果是,错误可能是由DatabaseCreator的限制引起的。它分割从ddl文件中读取的语句;(参见源代码的第127行。因此,函数被分割成多个语句,干扰语法。
Try to move the function code into an extra file and send this file as one statement to your server.
尝试将函数代码移动到一个额外的文件中,并将该文件作为一条语句发送到服务器。
#1
1
Is the create function
code included in HistoryTables.ddl
? If yes the error might be caused by a limitation of DatabaseCreator
. It splits statements read from the ddl file at ;
(see line 127 of the source code. The function is therefore splitted into multiple statements disturbing the syntax.
create函数代码是否包含在historytable .ddl中?如果是,错误可能是由DatabaseCreator的限制引起的。它分割从ddl文件中读取的语句;(参见源代码的第127行。因此,函数被分割成多个语句,干扰语法。
Try to move the function code into an extra file and send this file as one statement to your server.
尝试将函数代码移动到一个额外的文件中,并将该文件作为一条语句发送到服务器。