google-code-export / h2database

Automatically exported from code.google.com/p/h2database
0 stars 1 forks source link

ArrayIndexOutOfBoundsException when selecting current_timestamp() + ? without casting the bind variable #331

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This works:
-----------

PreparedStatement stmt = connection.prepareStatement(
  "select current_timestamp() + 1 from dual");
stmt.executeQuery();

So does this:
-------------
PreparedStatement stmt = connection.prepareStatement(
  "select current_timestamp() + cast(? as int) from dual");
stmt.setInt(1, 1);
stmt.executeQuery();

This doesn't:
-------------
PreparedStatement stmt = connection.prepareStatement(
  "select current_timestamp() + ? from dual");
stmt.setInt(1, 1);
stmt.executeQuery();

org.h2.jdbc.JdbcSQLException: Allgemeiner Fehler: 
"java.lang.ArrayIndexOutOfBoundsException: -1"
General error: "java.lang.ArrayIndexOutOfBoundsException: -1" [50000-155]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
    at org.h2.message.DbException.get(DbException.java:156)
    at org.h2.message.DbException.convert(DbException.java:279)
    at org.h2.message.DbException.toSQLException(DbException.java:252)
    at org.h2.message.TraceObject.logAndConvert(TraceObject.java:368)
    at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:243)

Original issue reported on code.google.com by lukas.eder@gmail.com on 13 Jul 2011 at 5:26

GoogleCodeExporter commented 9 years ago
The data type needs to be known at compile time in this case, as timestamp 
potentially add works with multiple data types. However, the exception is 
incorrect, I will change it to "Unknown data type: "?""

Original comment by thomas.t...@gmail.com on 20 Aug 2011 at 10:44

GoogleCodeExporter commented 9 years ago
Thank you

Original comment by lukas.eder@gmail.com on 22 Aug 2011 at 8:13

GoogleCodeExporter commented 9 years ago
I will keep the current behavior for now. Patches are always welcome of course.

Original comment by thomas.t...@gmail.com on 22 Sep 2011 at 4:32