Bug #9437 "if" function irregularities on windows 2k
Submitted: 28 Mar 2005 22:22 Modified: 22 May 2005 11:26
Reporter: josh tippett Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:3.1.7 OS:Windows (windows 2k 5.00.2195)
Assigned to: CPU Architecture:Any

[28 Mar 2005 22:22] josh tippett
Description:
when using the "if" function with string arguments in a prepared statement ... 

a byte array ([B) is returned on windows 
a string (java.lang.String) is returned on linux

How to repeat:
<%@ page import="javax.sql.DataSource,
                 javax.naming.InitialContext,
                 java.sql.Connection,
                 java.io.PrintWriter,
                 java.sql.ResultSet,
                 java.sql.PreparedStatement"%>
<%
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet resultSet = null;

    try{
        InitialContext ictx = new InitialContext();
        DataSource source = (DataSource) ictx.lookup("java:/mysqlDS");
        connection = source.getConnection();

        String alias = "someLocale";
        String sql = "select if ( languageCode = ?, ?, ? ) as " + alias + " from Locale";
        statement = connection.prepareStatement(sql);

        int count = 1;
        statement.setObject(count++, "en");
        statement.setObject(count++, "en_US");
        statement.setObject(count++, "en_GB");

        resultSet = statement.executeQuery();

        out.print("mysql-connector-java-3.1.7-bin.jar <br/>");
        out.print("on windows 2k 5.00.2195 the class will be a byte array: [B <br/>");
        out.print("on linux 2.4.23-xfs the class will be a String: java.lang.String <br/>");
        if (resultSet.next()){
            Object object = resultSet.getObject(alias);
            if (object != null){
                out.print("Class: " + object.getClass().getName() + "<br/>");
                out.print("Object: " + object.toString());
            }            
        }

    }catch(Exception e){
        e.printStackTrace(new PrintWriter(out));
    }finally{
        if (resultSet != null) resultSet.close();
        if (statement != null) statement.close();
        if (connection != null) connection.close();
    }
%>

Suggested fix:

return a string (java.lang.String) in all cases
[31 Mar 2005 17:59] Mark Matthews
What does the structure (and example data) for the "Locale" table look like? We'll need at least that much information to attempt reproducing the problem on our end.
[31 Mar 2005 18:11] josh tippett
CREATE TABLE `Locale` (
  `languageCode` char(2) NOT NULL default '',
  `countryCode` char(2) NOT NULL default '',
  `supported` enum('no','yes') NOT NULL default 'no',
  `ordering` int(11) default NULL,
  `createDate` datetime NOT NULL default '1000-01-01 00:00:03',
  `modifyDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`languageCode`,`countryCode`),
  KEY `languageCode` (`languageCode`),
  KEY `countryCode` (`countryCode`),
  KEY `ordering` (`ordering`),
  KEY `modifyDate` (`modifyDate`),
  CONSTRAINT `FK_Locale_Country` FOREIGN KEY (`countryCode`) REFERENCES `Country` (`code`),
  CONSTRAINT `FK_Locale_Language` FOREIGN KEY (`languageCode`) REFERENCES `Language` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
[31 Mar 2005 23:57] josh tippett
CREATE TABLE `Locale` (
  `languageCode` char(2) NOT NULL default '',
  `countryCode` char(2) NOT NULL default '',
  `supported` enum('no','yes') NOT NULL default 'no',
  `ordering` int(11) default NULL,
  `createDate` datetime NOT NULL default '1000-01-01 00:00:03',
  `modifyDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`languageCode`,`countryCode`),
  KEY `languageCode` (`languageCode`),
  KEY `countryCode` (`countryCode`),
  KEY `ordering` (`ordering`),
  KEY `modifyDate` (`modifyDate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into Locale values ('en', 'US', 'yes', null, now(), now());
insert into Locale values ('en', 'GB', 'no', null, now(), now());
[12 May 2005 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[22 May 2005 11:26] Vasily Kishkin
I created test case and tried to repeat on Windows. I got the follow result:

Class: java.lang.String
Object: en_US

Test case is attached
[22 May 2005 11:26] Vasily Kishkin
Test case

Attachment: test.java (text/plain), 990 bytes.