Bug #49516 | getString() from CachedRowSet using column alias with embedded space not working | ||
---|---|---|---|
Submitted: | 7 Dec 2009 17:03 | Modified: | 7 May 2010 17:53 |
Reporter: | John Mikle | Email Updates: | |
Status: | Can't repeat | Impact on me: | |
Category: | Connector / J | Severity: | S2 (Serious) |
Version: | 5.1.10 | OS: | MacOS (10.6.2) |
Assigned to: | Mark Matthews | CPU Architecture: | Any |
Tags: | cachedrowset, regression, ResultSet |
[7 Dec 2009 17:03]
John Mikle
[8 Dec 2009 6:54]
Tonci Grgin
John, thank you for opening new report for this problem.
[8 Dec 2009 10:27]
Tonci Grgin
I verified this using latest c/J sources and attached test case. useOldAliasMetadataBehavior=true E Time: 0,455 There was 1 error: 1) testBug49516(testsuite.simple.TestBug49516)java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Vector.get(Vector.java:712) at com.sun.rowset.CachedRowSetImpl.getCurrentRow(CachedRowSetImpl.java:1654) at com.sun.rowset.CachedRowSetImpl.getString(CachedRowSetImpl.java:1701) at com.sun.rowset.CachedRowSetImpl.getString(CachedRowSetImpl.java:2500) useOldAliasMetadataBehavior=false E Time: 0,457 There was 1 error: 1) testBug49516(testsuite.simple.TestBug49516)java.sql.SQLException: Invalid column name at com.sun.rowset.CachedRowSetImpl.getColIdxByName(CachedRowSetImpl.java:1638) at com.sun.rowset.CachedRowSetImpl.getString(CachedRowSetImpl.java:2500) useColumnNamesInFindColumn=true Time: 0,495 There was 1 error: 1) testBug49516(testsuite.simple.TestBug49516)java.sql.SQLException: Invalid column name useColumnNamesInFindColumn=false Time: 0,451 There was 1 error: 1) testBug49516(testsuite.simple.TestBug49516)java.sql.SQLException: Invalid column name This is inconsistent at least.
[8 Dec 2009 10:29]
Tonci Grgin
Test case for our test framework. Tested with JDK 1.5.
Attachment: TestBug49516.java (text/x-java), 2.07 KiB.
[10 Apr 2010 10:52]
Vivek Krishnan
I've checked this with the latest drivers 5.1.12 and its the same problem and have been testing it on Mac OS X 10.6.3. Eg. CREATE TABLE db_account ( id int NOT NULL AUTO_INCREMENT, name varchar(40) NOT NULL, account_id varchar(40) NOT NULL, username varchar(40) NOT NULL, password varchar(40) NOT NULL, current_cost decimal(16,2) NOT NULL, create_date datetime NOT NULL, service_provider_id int NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE db_child_account ( id int NOT NULL AUTO_INCREMENT, name varchar(40) NOT NULL, account_id int NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; I've also added some data into the DB. When I do Select acc.id, acc.name as account, cacc.name as child_account from db_account as acc, db_child_account as cacc where acc.id=cacc.account_id; When I use the above mentioned drivers, I get the column names as id, name and name.
[21 Apr 2010 11:17]
Federico Salvestroni
I have the same problem with Linux/Fedora and RedHat 4. I see the correct alias value set only in column's label but not in column's name. I wish someone will fix it sooner. Federico.
[1 May 2010 12:57]
Alex Lexx
We have exactly the same problem here, we tried id with *.getString(" 'cloumn name'") but it didn't worked...
[7 May 2010 17:34]
Mark Matthews
@Federico, The JDBC specification itself says that an alias is retrieved via getColumnLabel(). It does not become the column name, thus there is nothing to fix in that case.
[7 May 2010 17:39]
Mark Matthews
@Vivek, Yes, the JDBC specification states that the names would be 'name, name and '. If you want what you aliased them as, then you need to use ResultSet.getColumnLabel(). See http://java.sun.com/javase/6/docs/api/java/sql/ResultSet.html#findColumn(java.lang.String) and http://java.sun.com/javase/6/docs/api/java/sql/ResultSetMetaData.html#getColumnLabel(int)
[7 May 2010 17:53]
Mark Matthews
With what's going to be 5.1.13 (which is available in snapshot form from http://downloads.mysql.com/snapshots.php), I can't seem to repeat this bug using Java6 and the following testcase: public void testBug49516() throws Exception { CachedRowSetImpl crs; createTable( "bug49516", "(`testingID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `firstName` TEXT NOT NULL) CHARACTER SET utf8;"); this.stmt.executeUpdate("insert into bug49516 set firstName ='John'"); this.rs = this.stmt .executeQuery("select firstName as 'first person' from bug49516"); this.rs.first(); assertEquals("John", this.rs.getString("first person")); // this.rs.close(); // this.stmt.close(); this.rs = this.stmt .executeQuery("select firstName as 'first person' from bug49516"); crs = new CachedRowSetImpl(); crs.populate(this.rs); crs.first(); assertEquals("John", crs.getString(1)); }
[2 Mar 2011 14:54]
Lee Hart
I think Mark Matthews [7 May 2010 19:53] misses the point in that test case. The problem (for me too) would be hit upon by: assertEquals("John", crs.getString("first person")); This is especially a problem in joining tables, where the column names may not be unique. E.g. "SELECT a.b AS 'a_b', b.b AS 'b_b' FROM a JOIN b ON b.x = a.x;" I suspect this is a bug with CachedRowSet. The only work-around I found is to use the columnIndex rather than columnLabel. These work OK: assertEquals("John", this.rs.getString("first person")); assertEquals("John", crs.getString(1));
[22 Mar 2011 6:55]
Tonci Grgin
Lee, you are free to attach small but complete test case proving your point and we'll recheck.