I would like to be able to support the following Sybase 15 ASE syntax in my unit/integration tests that use HSQL…
create table #myTable (value varchar(12) NULL)
HSQL won’t recognise how the temp table is named, and baulks at the # character. Instead HSQL would like to use something like this…
create temporary table myTable (value varchar(12) NULL)
or, HSQL also supports most of ANSI-92 SQL according to their docs, however Sybase ASE 15 doesn’t have great support for ANSI-92 SQL including how temporary tables are created so the following won’t work in Sybase but does in HSQL…
DECLARE LOCAL TEMPORARY TABLE mytable (value varchar(12) NULL)
From everything I have tried I cannot come up with a common syntax that will work with both Sybase and HSQL. Does anyone know of a clean way around this?
The only option I think I have is to create separate DAO’s for each database dialect, and control which one is used in the Spring Application Context XML files.
I don’t use Hibernate for my datasource, only Spring’s JdbcTemplate.
I chose to resolve this issue by implementing a couple of dialect helper classes for my DAO. My goals were to
RowMapper and various SELECT/INSERT statements against the database schema as used in production (but implemented in HSQL)
My DAO ended up looking like this (note the DialectHelper being injected) …
… my production Spring configuration (spring-db.xml) looks like this and injects the Sybase dialect
… and my Test Spring configuration (spring-db-test.xml) looks like this and injects the HSQL dialect
The DialectHelper classes provide a way of separating out the incompatible database syntax from the DAO …
The Test class itself initialises Spring with the HSQL dialectHelper by loading the file spring-db-test.xml