Hello,

I understand that H2 syntactically supports the UNSIGNED keyword in DDL to
stay compatible with MySQL:

    CREATE TABLE t_unsigned (
      u_byte tinyint unsigned,
      u_short smallint unsigned,
      u_int int unsigned,
      u_long bigint unsigned
    );

Obviously, this is just a syntax compatibility, as I cannot insert this:

    INSERT INTO t_unsigned (u_byte) VALUES (255);

Would it make sense to enhance the H2 database in order to go a bit further
on UNSIGNED support? There are two alternative routes:

--------------------------------------------------------------------------
1. Simple fix: Just "upgrade" integer types in storage, and let the above
table be equivalent to this one:

    CREATE TABLE t_unsigned (
      u_byte smallint,
      u_short integer,
      u_int bigint,
      u_long number(20)
    );

2. Sophisticated fix: Store unsigned numbers in signed number containers,
but fix all relevant JDBC methods to produce the exact value:

    "255".equals(rs.getString("u_byte"));
    255 == rs.getInt("u_byte");
    (short) 255 == rs.getShort("u_byte");
    (byte) -1 == rs.getByte("u_byte"); // This would be "expected"
--------------------------------------------------------------------------

The simple fix would probably cause new issues in the long run. Besides, it
would allow values that are out of range, e.g. 1000 for u_byte. The
sophisticated fix would mean a bit of work, specifically because all the
arithmetic operations would need to be adapted. Consider

    cast((u_byte + u_byte) as smallint unsigned)

For u_byte == 255 (stored as -1), this would have to return 510, instead of
-2

What do you think?

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 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to