views:

62

answers:

4

I recently modified a MYSQL query using the keyword RLIKE however when I ran the unit test which uses HSQLDB in order to mock a database it throws an unknown SQL token exception.

In order to resolve this currently I have commented out these tests, but would like to find a work around so I can actually test my code.

My google-fu failed to result in a solution as HSQLDB documentation seems lacking, any help would be appreciated.

+2  A: 

I think the moral of this story is: Run your tests with the same software stack as you intend to deploy.

If you test in a different environment, your tests might pass but your app fail in production - this is bad.

MarkR
I think this depends. In staging build concepts sometimes it is necessary that your test-setup differs from production (e.g. speed reasons, or no external prod-integration sandboxes). The art is to find a good compromise between convenient test-setup and testing the "right thing".
manuel aldana
It wouldn't be the first time a customer decides they want to change their database. I try to stay away from non-standard features in my queries as much as possible.
jackrabbit
A customer does not "decide they want to change the database". The choice of database is something that the application designer is responsible for and cannot be changed by the customer except for a very good reason with significant associated costs to them. If the application is used by more than one customer, one customer may not be able to mandate a change of database at all. Database applications are completely tied to the vendor they were tested against, no sane person wants to support one on >1 vendor.
MarkR
+1  A: 

RLIKE is a non-standard operator and HSQL does not support it. If you want to continue your testing with HSQL, you will have to rewrite your query using LIKE statements or some other standard method. Alternatively, you could mock the database interaction using e.g. dbunit.

jackrabbit
A: 

The equivalent in HSQLDB 2.0 is the function

REGEXP_MATCHES ( , )

and the usage is

SELECT ... WHERE REGEXP_MATCHES( mystring, regexpr)

The latest Hibernate 3.5.5 supports HSLQDB 2.0

fredt
A: 

One of our guys used "count" as a field name, and we hushed Hibernate by putting backticks around the field name:

@Column(name="`count`", nullable=false)
public byte getCount() {
    return this.count;
}
opyate