Hi,
Hm, I'm not sure. Why would you use a varchar(1) for a boolean, and not
bit? The following fails with PostgreSQL:
drop table test;
create table test(val varchar(1));
insert into test(val) values(true); -- value too long for type character
varying(1) 22001/0
select * from test;
It does work with MySQL. It doesn't work with Oracle, as Oracle doesn't
understand "true" ("column not allowed here"). It sounds like for both
MySQL and Oracle, setBoolean(true) is kind of the same as setInt(1).
Now if PostgreSQL supports setBoolean(true) for varchar(1), then I think H2
should support it as well (I didn't test it yet).
Regards,
Thomas
On Wed, Feb 12, 2014 at 3:46 PM, Lukas Eder <[email protected]> wrote:
> Hello guys,
>
> I was wondering if it would make sense for H2 to provide better database
> interoperability for BOOLEAN bind values when they're inserted into
> non-BOOLEAN columns. Consider this test scenario:
>
> create table test(val varchar(1));
>
>
> Now this program fails:
>
> Connection c = getConnection();
> PreparedStatement s = c.prepareStatement("insert into test values (?)");
> s.setBoolean(1, true);
> s.executeUpdate(); // H2 fails here
> s = c.prepareStatement("select * from test");
> ResultSet rs = s.executeQuery();
> rs.next();
> System.out.println(rs.getString(1));
>
>
> The exception I get is this:
>
> org.h2.jdbc.JdbcSQLException: Wert zu gross / lang für Feld "VAL
> VARCHAR(1)": "'TRUE' (4)"
> Value too long for column "VAL VARCHAR(1)": "'TRUE' (4)"; SQL statement:
> insert into test values (?) [22001-170]
> at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
> at org.h2.message.DbException.get(DbException.java:169)
> at org.h2.table.Column.validateConvertUpdateSequence(Column.java:315)
> at org.h2.table.Table.validateConvertUpdateSequence(Table.java:689)
> at org.h2.command.dml.Insert.insertRows(Insert.java:120)
> at org.h2.command.dml.Insert.update(Insert.java:84)
> at org.h2.command.CommandContainer.update(CommandContainer.java:75)
> at org.h2.command.Command.executeUpdate(Command.java:230)
> at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:156)
> at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:142)
> at org.jooq.test._.testcases.EnumTests.testCustomEnums(EnumTests.java:140)
>
>
> The same statement works perfectly with Oracle, which returns 1.
>
> This is just loud thinking, I'm not sure if it would be wise to change
> this behaviour in H2.
>
> Cheers
> Lukas
>
> --
> 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 post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.