Type "bit" with value null in union craches Hibernate JDBC Connection

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Type "bit" with value null in union craches Hibernate JDBC Connection

Michael Wyraz-2
Hi,

i think i found a critical bug in hsql. The following sql can reproduce
this:

-- begin sql --
DROP TABLE test1 IF EXISTS;
DROP TABLE test2 IF EXISTS;
CREATE TABLE test1 (id int, b1 bit);
CREATE TABLE test2 (id int);
insert into test1 values(1,true);
insert into test2 values(2);

select id,null as b1 from test2
union
select id,b1 from test1;
-- end sql --

This causes an exception in the database process:
Exception in thread "HSQLDB Connection @b6ef8"
java.lang.ClassCastException: java.lang.Boolean
    at org.hsqldb.rowio.RowOutputBase.writeData(Unknown Source)
    at org.hsqldb.Result.write(Unknown Source)
    at org.hsqldb.Result.write(Unknown Source)
    at org.hsqldb.ServerConnection.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:595)

The jdbc query never returns a value, the sql client freezes.

This happens only on Client-Server databases. When i start an in-memory
database (directly from DriverManager), it seems to work.

Below is a testcase to reproduce the problem.
Please send answers as copy to [hidden email] since i'm not in the
mailing list.

Michael.

-- testcase --

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import junit.framework.TestCase;

import org.hsqldb.Server;
import org.hsqldb.ServerConstants;

public class HSQLJoinBugTest extends TestCase
{
    public void testHibernateUnionBug() throws Throwable
    {
        Server dbServer=new Server();
        dbServer.setDatabasePath(0,"mem:test");
        dbServer.start();
        do
        {
            try { Thread.sleep(100); } catch (Exception ex) {}
        } while (dbServer.getState()==ServerConstants.SERVER_STATE_OPENING);

        if (dbServer.getState()!=ServerConstants.SERVER_STATE_ONLINE)
            throw new RuntimeException("Unable to start database Server
(ServerState: "+
                    dbServer.getStateDescriptor()+")");
       
        // load the driver
        new org.hsqldb.jdbcDriver();
        // connect to the database
        Connection
db=DriverManager.getConnection("jdbc:hsqldb:hsql://localhost","sa","");
        Statement st=db.createStatement();
       
        st.execute("CREATE TABLE test1 (id int, b1 bit)");
        st.execute("CREATE TABLE test2 (id int)");
        st.execute("INSERT INTO test1 VALUES(1,true)");
        st.execute("INSERT INTO test2 VALUES(2)");
       
        st.executeQuery("select id,null as b1 from test2 union select
id,b1 from test1");
    }
}



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
hsqldb-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-developers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Type "bit" with value null in union craches Hibernate JDBC Connection

Fred Toussi-2
It must be something to do with the unspecified type of the literal null
value. Try this instead:

select id,cast(null as boolean) as b1 from test2
union
select id,b1 from test1;


Will include check to prevent this in a future point release.

Fred

----- Original Message -----
From: "Michael Wyraz" <[hidden email]>
To: <[hidden email]>
Sent: 15 July 2005 17:15
Subject: [Hsqldb-developers] Type "bit" with value null in union craches
Hibernate JDBC Connection


Hi,

i think i found a critical bug in hsql. The following sql can reproduce
this:

-- begin sql --
DROP TABLE test1 IF EXISTS;
DROP TABLE test2 IF EXISTS;
CREATE TABLE test1 (id int, b1 bit);
CREATE TABLE test2 (id int);
insert into test1 values(1,true);
insert into test2 values(2);

select id,null as b1 from test2
union
select id,b1 from test1;
-- end sql --

This causes an exception in the database process:
Exception in thread "HSQLDB Connection @b6ef8"
java.lang.ClassCastException: java.lang.Boolean
    at org.hsqldb.rowio.RowOutputBase.writeData(Unknown Source)
    at org.hsqldb.Result.write(Unknown Source)
    at org.hsqldb.Result.write(Unknown Source)
    at org.hsqldb.ServerConnection.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:595)

The jdbc query never returns a value, the sql client freezes.

This happens only on Client-Server databases. When i start an in-memory
database (directly from DriverManager), it seems to work.

Below is a testcase to reproduce the problem.
Please send answers as copy to [hidden email] since i'm not in the
mailing list.

Michael.

-- testcase --

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import junit.framework.TestCase;

import org.hsqldb.Server;
import org.hsqldb.ServerConstants;

public class HSQLJoinBugTest extends TestCase
{
    public void testHibernateUnionBug() throws Throwable
    {
        Server dbServer=new Server();
        dbServer.setDatabasePath(0,"mem:test");
        dbServer.start();
        do
        {
            try { Thread.sleep(100); } catch (Exception ex) {}
        } while (dbServer.getState()==ServerConstants.SERVER_STATE_OPENING);

        if (dbServer.getState()!=ServerConstants.SERVER_STATE_ONLINE)
            throw new RuntimeException("Unable to start database Server
(ServerState: "+
                    dbServer.getStateDescriptor()+")");

        // load the driver
        new org.hsqldb.jdbcDriver();
        // connect to the database
        Connection
db=DriverManager.getConnection("jdbc:hsqldb:hsql://localhost","sa","");
        Statement st=db.createStatement();

        st.execute("CREATE TABLE test1 (id int, b1 bit)");
        st.execute("CREATE TABLE test2 (id int)");
        st.execute("INSERT INTO test1 VALUES(1,true)");
        st.execute("INSERT INTO test2 VALUES(2)");

        st.executeQuery("select id,null as b1 from test2 union select
id,b1 from test1");
    }
}



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
hsqldb-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-developers 



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
hsqldb-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-developers
Loading...