Bug #19912 Column type is incorrect when have order by in a prepared statement with a BLOB
Submitted: 18 May 2006 15:34 Modified: 19 May 2006 7:44
Reporter: Brian Robinson Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:mysql-connector-java-5.0.0-beta OS:Linux (Linux and Windows XP)
Assigned to: CPU Architecture:Any

[18 May 2006 15:34] Brian Robinson
Description:
This bug is causing us problems in the implementation of Sensitive customer information.

Versions
    MySQL server is running under SuSE linux 10.0
    mySQL version is 
         MySQL-server-standard-5.0.20a-0.sles9
         MySQL-client-standard-5.0.20a-0.sles9
    JDBC
         mysql-connector-java-3.1.10
         mysql-connector-java-5.0.0-beta

The column type coming back from a preparedstatement call with JDBC is incorrect if using a prepared statement and an order by in the select statement where there is a blob column. and calling function aes_decrypt. It seems also only to occur when the query has a JOIN. A simple select from one table does not seem to cause the problem.

See below for how to repeat.

How to repeat:
1) take two tables as defined as follows
create table bugfile(fileid bigint not null, filename blob, pathid bigint)

create table bugpath(pathid bigint not null, path varchar(254))

insert into bugpath (pathid, path) values (1, 'top')

insert into bugfile (fileid, filename, pathid) values (1, aes_encrypt('filename1', 'fish'), 1)
insert into bugfile (fileid, filename, pathid) values (2, aes_encrypt('filename2', 'fish'), 1)
insert into bugfile (fileid, filename, pathid) values (3, aes_encrypt('filename3', 'fish'), 1)

Now perform following select statement

SELECT aes_decrypt(FIC.filename,'fish') as FileName, FP.PATH 
FROM bugFile FIC, bugPATH FP
WHERE FP.PATHId=FIC.PATHID 
ORDER BY FIC.FileName ASC

create a small JAVA program to connect to the database and execute the statement

If you do this without a prepared statement then you get 
filename1
filename2
filename3 
as expected

If you then repeat in JAVA program with a prepared statement then you get 
[B@15e83f9
[B@2a5330
[B@bb7465

If you now remove the Order By from the statement then the query works fine in both cases

Suggested fix:
Sorry - no suggestions
[18 May 2006 15:41] Mark Matthews
Duplicate of BUG#12872. The server is returning incorrect metadata to the client.
[19 May 2006 7:44] Brian Robinson
WorkAround
=========

You can simply add a cast to the aes_decrypt to make sure you get a String back.

so from above example just do 
select cast(aes_decrypt(filename, 'fish') as CHAR) from bugfile.

This has "fixed" all problems so far I have had with this.