可以在替换MSSQL的测试环境中使用HSQLDB

时间:2022-06-05 23:18:37

I am using the HSQLDB in the testing envoirnment providing scripts to create tables then importing the test data to be inserted in the mocked database. In the production level we have Microsoft SQL server database. Still the HSQLDB giving me errors like:

我在测试环境中使用HSQLDB,提供脚本来创建表,然后导入要插入到模拟数据库中的测试数据。在生产级别,我们有Microsoft SQL Server数据库。 HSQLDB仍然给我错误,如:

java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: GETDATE
20:17:48,283 ERROR [Appeal] [proceessAppeal] [Error] 
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
    at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)

2 个解决方案

#1


1  

different databases support different built-in functions. hsqldb doesnt have a GETDATE() function like in mssql. it does have an equivalent function, CURRENT_TIMESTAMP(), but you cant just reuse the same SQL code between them.

不同的数据库支持不同的内置函数。 hsqldb没有像mssql那样的GETDATE()函数。它确实有一个等效函数CURRENT_TIMESTAMP(),但你不能在它们之间重用相同的SQL代码。

if you want to do this, you will need to maintain 2 versions of your schema/queries, or (if its trivial enough, depending on what you use) just do a find-and-replace.

如果你想这样做,你需要维护2个版本的模式/查询,或者(如果它足够小,取决于你使用的是什么)只需要进行查找和替换。

#2


0  

Maybe you could write a custom function getDATE(), see this question

也许你可以写一个自定义函数getDATE(),看看这个问题

I use hsqldb in integration tests and oracle in production. Still some SQLs are not supported although hsqldb has a "SET DATABASE SQL SYNTAX ORA true" feature. Hence I avoid use unstandard sql functions as few as possible and just use HSQLDB for some insert/update/query tests(therefore some SQL scripts are not needed).

我在集成测试中使用hsqldb,在生产中使用oracle。尽管hsqldb具有“SET DATABASE SQL SYNTAX ORA true”功能,但仍然不支持某些SQL。因此,我尽量避免使用不标准的sql函数,只使用HSQLDB进行一些插入/更新/查询测试(因此不需要一些SQL脚本)。

#1


1  

different databases support different built-in functions. hsqldb doesnt have a GETDATE() function like in mssql. it does have an equivalent function, CURRENT_TIMESTAMP(), but you cant just reuse the same SQL code between them.

不同的数据库支持不同的内置函数。 hsqldb没有像mssql那样的GETDATE()函数。它确实有一个等效函数CURRENT_TIMESTAMP(),但你不能在它们之间重用相同的SQL代码。

if you want to do this, you will need to maintain 2 versions of your schema/queries, or (if its trivial enough, depending on what you use) just do a find-and-replace.

如果你想这样做,你需要维护2个版本的模式/查询,或者(如果它足够小,取决于你使用的是什么)只需要进行查找和替换。

#2


0  

Maybe you could write a custom function getDATE(), see this question

也许你可以写一个自定义函数getDATE(),看看这个问题

I use hsqldb in integration tests and oracle in production. Still some SQLs are not supported although hsqldb has a "SET DATABASE SQL SYNTAX ORA true" feature. Hence I avoid use unstandard sql functions as few as possible and just use HSQLDB for some insert/update/query tests(therefore some SQL scripts are not needed).

我在集成测试中使用hsqldb,在生产中使用oracle。尽管hsqldb具有“SET DATABASE SQL SYNTAX ORA true”功能,但仍然不支持某些SQL。因此,我尽量避免使用不标准的sql函数,只使用HSQLDB进行一些插入/更新/查询测试(因此不需要一些SQL脚本)。