Bug #13466 stumbling over field.isUnsigned() for int with upgraded DB --> 65536 added
Submitted: 25 Sep 2005 9:09 Modified: 25 Sep 2005 9:58
Reporter: Ralf Hauser Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:mysql-connector-java-3.1.10-bin-g.jar OS:Linux (Redhat Workstation server)
Assigned to: CPU Architecture:Any

[25 Sep 2005 9:09] Ralf Hauser
Description:
We recently upgraded from
old: /usr/sbin/mysqld --version
/usr/sbin/mysqld  Ver 4.0.24_Debian-10-log for pc-linux-gnu on i386 (Source distribution)

to
new:~$ mysql --version
mysql  Ver 14.7 Distrib 4.1.13, for pc-linux-gnu (i686) using readline 4.3
new:~$ /usr/sbin/mysqld --version -debug
(no clue why mysqld doesn't want to tell me what version it is when I do not have root permission)

Any, it appears that
int com.mysql.jdbc.ResultSet.getNativeInt(int columnIndex) 
fails and an int of "2" is displayed as "65538"

When doing the same query as I do with jdbc with the windows MySQL Query Browser 1.1.14, the correct result, namely "2" is displayed.

I stepped through with the source with the below test case with createTable = false, the correct result of 2 is returned. When doing createTable = true, I see the following difference in the ResultSet.getNativeInt, f.getMysqlType() no longer is
   case MysqlDefs.FIELD_TYPE_LONG:
but
   case MysqlDefs.FIELD_TYPE_SHORT:
if (!f.isUnsigned()) {
				return getNativeShort(columnIndex + 1);
			}

			return getNativeShort(columnIndex + 1) + 65536;
and obviously 65536 is added.

Originally, the field was created with
CREATE TABLE upgradedExistingTable (
   lang_id        SMALLINT UNSIGNED NOT NULL DEFAULT 1,

Using MyISAM Tables and on the client side java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode) on windows XP

server side: Linux 2.6.9-11.EL #1 Fri May 20 18:17:57 EDT 2005 i686 i686 i386 GNU/Linux

How to repeat:
            ResultSet rs = null;
            Statement stmt = null;
            try {
                PreparedStatement selUtfStringStmt = null;
                boolean createTable = false;
                if (createTable) {
                    stmt = this.conn.createStatement(
                            java.sql.ResultSet.TYPE_FORWARD_ONLY,
                            java.sql.ResultSet.CONCUR_UPDATABLE);
                    stmt.executeUpdate("DROP TABLE IF EXISTS bugInt");
                    stmt.executeUpdate("CREATE TABLE bugInt ("
                            + "id         INT NOT NULL AUTO_INCREMENT UNIQUE, "
                            + "lang_id    INT NOT NULL, PRIMARY KEY (id))");
                    stmt
                            .executeUpdate("INSERT INTO bugInt (lang_id) VALUES (2);");
                    selUtfStringStmt = this.conn
                            .prepareStatement("SELECT lang_id FROM bugInt WHERE id = '1' ");
                } else {
                    selUtfStringStmt = this.conn
                            .prepareStatement("SELECT lang_id FROM upgradedExistingTable WHERE id= '1' ");
                }
                log.debug("selUtfStringStmt: "
                        + ((DelegatingPreparedStatement) selUtfStringStmt)
                                .getDelegate().toString());
                rs = selUtfStringStmt.executeQuery();
                int i = 0;
                if (rs == null) {
                    log.debug("row set is null!");
                }
                if (!rs.next()) {
                    log.debug("no more results" + i);
                } else {
                    do {
                        i++;
                        log.debug("lang: " + rs.getInt("lang_id"));
                    } while (rs.next());
                    log.debug(i + " user found.");
                }
            } finally {
                if (rs != null) {
                    try {
                        rs.close();
                    } catch (SQLException ex) {
                        // ignore
                    }
                }
            }

Suggested fix:
If there was a CVS, I'd happily compile and test with a changed driver
[25 Sep 2005 9:58] Vasily Kishkin
Sorry...This bug is duplicate of http://bugs.mysql.com/bug.php?id=11874