Hi,

( I'm new to the mailing-list, sorry if I do not follow the expectations. )

I'm using H2 1.3.176 together with Hibernate 4.3.6.Final.
I'm having a bug with a particular Hibernate query involving IN with an
enum list. [1]

I thought Hibernate was involved in this issue, but it seems that it comes
from H2.

You will find attached two tests in tests.java.

The first one (testColumnMetaDataWithEquals) works fine.
It creates a PreparedStatement ( "SELECT ... WHERE someColumn = ?" ) then
uses "preparedStmt.getParameterMetaData().getParameterType(1)" which
returns the expected value.

The second one (testColumnMetaDataWithIn) is doing exactly the same thing
except the WHERE clause is using IN ( "SELECT ... WHERE someColumn IN ( ? ,
? ) ").
Then "preparedStmt.getParameterMetaData().getParameterType(1)" does not
return the expected value.

I wrote a patch for "ConditionIn" based on the "Comparison" source code.
This patch proposal is attached, please let me know if it is acceptable.

Best regards,
Arnaud


[1] Is it off topic, but the Hibernate query looks like " FROM SomeEntity
WHERE someColumn IN ( :enum0 , :enum1 ) "

-- 
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 h2-database+unsubscr...@googlegroups.com.
To post to this group, send email to h2-database@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
    @Test
    public void testColumnMetaDataWithEquals() throws SQLException {

        Connection conn1 = null;
        try {
            DriverManager.registerDriver(new org.h2.Driver());
            conn1 = DriverManager.getConnection("jdbc:h2:mem:toto", "sa", "");

            Statement statement = conn1.createStatement();
            statement.execute(" CREATE TABLE testColumnMetaDataWithEquals ( id INTEGER(10), someColumn INTEGER(10) ) ");

            PreparedStatement insert = conn1.prepareStatement(" INSERT INTO testColumnMetaDataWithEquals VALUES( ? , ? ) ");
            insert.setInt(1, 0);
            insert.setInt(2, 999);
            insert.execute();

            PreparedStatement select = conn1.prepareStatement(" SELECT * FROM testColumnMetaDataWithEquals WHERE someColumn = ? ");
            int parameterType = select.getParameterMetaData().getParameterType(1);
            Assert.assertEquals(Types.INTEGER, parameterType);

        } finally {
            if (conn1 != null && !conn1.isClosed()) {
                conn1.close();
            }
        }

    }

    @Test
    public void testColumnMetaDataWithIn() throws SQLException {

        Connection conn1 = null;
        try {
            DriverManager.registerDriver(new org.h2.Driver());
            conn1 = DriverManager.getConnection("jdbc:h2:mem:toto", "sa", "");

            Statement statement = conn1.createStatement();
            statement.execute(" CREATE TABLE testColumnMetaDataWithIn ( id INTEGER(10), someColumn INTEGER(10) ) ");

            PreparedStatement insert = conn1.prepareStatement(" INSERT INTO testColumnMetaDataWithIn VALUES( ? , ? ) ");
            insert.setInt(1, 0);
            insert.setInt(2, 999);
            insert.execute();

            PreparedStatement select = conn1.prepareStatement(" SELECT * FROM testColumnMetaDataWithIn WHERE someColumn IN ( ?, ? ) ");
            int parameterType = select.getParameterMetaData().getParameterType(1);
            Assert.assertEquals(Types.INTEGER, parameterType);


        } finally {
            if (conn1 != null && !conn1.isClosed()) {
                conn1.close();
            }
        }

    }

Index: src/main/org/h2/expression/ConditionIn.java
===================================================================
--- src/main/org/h2/expression/ConditionIn.java	(révision 5821)
+++ src/main/org/h2/expression/ConditionIn.java	(copie de travail)
@@ -95,6 +95,10 @@
             if (allValuesConstant && !e.isConstant()) {
                 allValuesConstant = false;
             }
+            if (left instanceof ExpressionColumn && e instanceof Parameter) {
+                ((Parameter) e).setColumn(
+                        ((ExpressionColumn) left).getColumn());
+            }
             valueList.set(i, e);
         }
         if (constant && allValuesConstant) {

Reply via email to