开发者

Strange behavior by using the keyword of HSQLDB

开发者 https://www.devze.com 2023-04-11 19:36 出处:网络
I have a strange result when creating a new table in HSQLDB. From the documentation of HSQLDB, \"user\" is a keyword, no开发者_如何学Gormally, we can\'t use this value for table name or column name, u

I have a strange result when creating a new table in HSQLDB. From the documentation of HSQLDB, "user" is a keyword, no开发者_如何学Gormally, we can't use this value for table name or column name, unless it is double quoted.

However, I can create a database table with name "USER", and a database table DATA_RESULT with one column name "user", without double quoting the keyword.

Problem occurs when reading the data from DB. For example, when I execute: "select * from DATA_RESULT" and read the value of "user" from the ResultSet, it works.

If I execute "select user from DATA_RESULT" or "SELECT * from DATA_RESULT where user = 1", an error occurs. The sql statement is not executed correctly, ResultSet.next() always return a false.

Besides, from Lists of Keywords for HSQLDB, it says HyperSQL has two modes of operation, which are selected with the SET DATABASE SQL NAMES { TRUE | FALSE } to allow or disallow the keywords as identifiers. The default mode is FALSE and allows the use of most keywords as identifiers, it doesn't state if "user" can be used as a identifier.

I am using HSQLDB 2.0.0.

It is quite confusing. Does anybody know what is going on here?

Thanks in advance! Any suggestion would be helpful.


USER is a function to get the name of the current user. For example:

CALL USER

You can certainly use USER as a table name or column name.

In the SELECT statement, use double quotes around the name.

CREATE TABLE DATA_RESULT ("USER" INT, DATA VARCHAR(100))
SELECT * FROM DATA_RESULT WHERE "USER" = 1

When double quotes are used, the cases must match.

Note the Guide on the web site is updated regularly and it currently corresponds to the latest version 2.2.5.

0

精彩评论

暂无评论...
验证码 换一张
取 消