Hi,

I have a question regarding the following test code:

Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:db1", "SA", "");
conn.createStatement().execute("CREATE TABLE A (B TIMESTAMP)");
PreparedStatement ps = conn.prepareStatement("SELECT  B FROM A WHERE 
(TIMESTAMPDIFF(?, B, B) > ?)");
ps.setString(1, "HOUR");
ps.setInt(2, 99999);

With version 1.4.197 this works.

With version 1.4.200 I get the exception:
org.h2.jdbc.JdbcSQLDataException: 
Invalid value "2" for parameter "parameterIndex" [90008-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:590)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.getInvalidValueException(DbException.java:280)
at 
org.h2.jdbc.JdbcPreparedStatement.setParameter(JdbcPreparedStatement.java:1503)
at org.h2.jdbc.JdbcPreparedStatement.setInt(JdbcPreparedStatement.java:394)

With the current master branch I get:
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement 
"SELECT  B FROM A WHERE (TIMESTAMPDIFF(?[*], B, B) > ?)"; expected 
"date-time field"; SQL statement:
SELECT  B FROM A WHERE (TIMESTAMPDIFF(?, B, B) > ?) [42001-201]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:459)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:435)
at org.h2.message.DbException.getSyntaxError(DbException.java:238)
at org.h2.command.Parser.getSyntaxError(Parser.java:1260)
at org.h2.command.Parser.readDateTimeField(Parser.java:4858)
at org.h2.command.Parser.readBuiltinFunctionIf(Parser.java:4385)
at org.h2.command.Parser.readFunction(Parser.java:4059)

Was this a cosncious decision to not support these kind of parameters, or 
did this just break along the way?

My problem is, that the "real" use case comes from a query generated by 
eclipselink using a expression dimilar to "function('TIMESTAMPDIFF', 
'HOUR', B, B)" in JPQL. And there does not seem to be any way to prevent 
eclipselink from using a query parameter for 'HOUR'.

Has anybody faced similar issues?

Thanks & best regards,
  Niklas
 

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/b5212086-ad3d-41fc-b4cf-05a0367b807bn%40googlegroups.com.

Reply via email to