【问题标题】:org.postgresql.util.PSQLException: ERROR: unterminated dollar-quoted string at or near "$BODY$org.postgresql.util.PSQLException:错误:在“$BODY$”或附近未终止的美元引号字符串
【发布时间】:2013-09-26 12:02:23
【问题描述】:

我正在尝试在我的 java 项目中使用 dbunit-express 在 Junit 测试中的 postgress 上创建一些表和函数。

我用这个驱动:

<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.2-1003-jdbc4</version>

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());
    }
}

但是我得到了这个错误......

org.postgresql.util.PSQLException: 错误: "$BODY$

处或附近未终止的美元引号字符串

函数如下所示。

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;

在 PGAdmin 1.14.3 和 DBVisualizer 9.0.8 中创建工作正常

【问题讨论】:

  • 听起来好像有什么东西在你的代码到达后端之前改变了它。您能否在您的 postgresql 日志中查看它报告的错误取决于您的配置,它将包括它实际收到的查询,以便我们可以看到发生了什么变化。作为一种解决方法,您可以尝试将美元引用的字符串转换为普通字符串。

标签: postgresql dbunit


【解决方案1】:

create function 代码是否包含在 HistoryTables.ddl 中?如果是,则错误可能是由DatabaseCreator 的限制引起的。它拆分从 ; 的 ddl 文件读取的语句(请参阅 line 127 of the source code。因此,该函数被拆分为多个语句,从而干扰了语法。

尝试将函数代码移动到一个额外的文件中,并将该文件作为一个语句发送到您的服务器。

【讨论】:

  • 是的,这就是问题所在。我分叉了项目并将分隔符更改为哈希并将哈希放入文件中..它工作了
猜你喜欢
  • 1970-01-01
  • 2016-06-14
  • 1970-01-01
  • 2015-12-14
  • 2019-04-13
  • 1970-01-01
  • 2011-03-30
  • 1970-01-01
  • 2013-12-10
相关资源
最近更新 更多