How to support support SqlServer's “..” in HyperSQL?

老子叫甜甜 提交于 2019-12-12 04:28:41

问题


tl;dr: I am trying to unit test some SqlServer queries which state the db name but they do not seem to work in HyperSql.


We are using Sql Server in production and I am trying to use HyperSQL as my database for unit testing. I am trying to test a class that creates SQL queries so stubbing out the database is not an option as having the queries parsed by a real database is part of the test.

Queries are supposed to be created in the form of SELECT * FROM EntAsdfDb007..Data_Table, although we can use the schema name ( 'db' ) if we wish.

From what I understand about the SELECT format for SqlServer, it allows you to specify the name of database followed by the name of schema. Also, you can drop the name of the database and have it inferred.

In HyperSqlDb I have been able to create the schema 'db' and create the necessary tables within it, and have been able to create tables within that schema but I have not be able to query with the database name even after setting the DB name using .setDatabaseName(). The exception I get is:

Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: ENTASDFDB007

Just to be clear: I am unit-testing a class that uses SQL like SELECT * FROM EntAsdfDb007..Data_Table. I am trying to set up an instance of HyperSql for unit testing purposes but HyperSql seems to reject the syntax used.


回答1:


That won't be possible.

HyperSQL cannot be changed to accept non-standard naming schemes.




回答2:


It is possible. HSQLDB does have one catalog per database. The catalog name is PUBLIC by default, which you can change.

ALTER CATALOG PUBLIC RENAME TO EntAsdfDb007

You can then access your table with

SELECT * FROM EntAsdfDb007.db.Data_Table


来源:https://stackoverflow.com/questions/7432350/how-to-support-support-sqlservers-in-hypersql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!