[Commits] Rev 400: CONJ-17 : ResultSetMetaData.getColumnName() returned empty string for special cases, where result set column was not a column from any table. in file:///H:/bzr/mariadb-jdbc-push/

Vladislav Vaintroub wlad at montyprogram.com
Sun Feb 3 01:32:59 EET 2013


At file:///H:/bzr/mariadb-jdbc-push/

------------------------------------------------------------
revno: 400
revision-id: wlad at montyprogram.com-20130202233230-paskqiwhblvv5t1u
parent: wlad at montyprogram.com-20130202210450-dxrzq4m56uavbrex
fixes bug: https://mariadb.atlassian.net/browse/CONJ-17
committer: Vladislav Vaintroub <wlad at montyprogram.com>
branch nick: mariadb-jdbc-push
timestamp: Sun 2013-02-03 00:32:30 +0100
message:
  CONJ-17 : ResultSetMetaData.getColumnName() returned empty string for special cases, where result set column was not a column from any table.
  For example, column name returned by ResultRSetMetaData.getColumnName(1)  for the query  " select count(*) from table"  would be empty string ""
  
  The fix is to return column label (called "virtual column name" here http://dev.mysql.com/doc/internals/en/text-protocol.html#packet-Protocol::ColumnDefinition) instead of "".
-------------- next part --------------
=== modified file 'src/main/java/org/mariadb/jdbc/MySQLResultSetMetaData.java'
--- a/src/main/java/org/mariadb/jdbc/MySQLResultSetMetaData.java	2013-01-13 23:15:13 +0000
+++ b/src/main/java/org/mariadb/jdbc/MySQLResultSetMetaData.java	2013-02-02 23:32:30 +0000
@@ -185,7 +185,10 @@ public class MySQLResultSetMetaData impl
      * @throws java.sql.SQLException if a database access error occurs
      */
     public String getColumnName(final int column) throws SQLException {
-        return getColumnInformation(column).getOriginalName();
+        String s =  getColumnInformation(column).getOriginalName();
+        if ("".equals(s))  // odd things that are no columns, e.g count(*)
+            s =  getColumnLabel(column);
+        return s;
     }
 
     /**

=== modified file 'src/test/java/org/mariadb/jdbc/ResultSetMetaDataTest.java'
--- a/src/test/java/org/mariadb/jdbc/ResultSetMetaDataTest.java	2013-01-13 23:15:13 +0000
+++ b/src/test/java/org/mariadb/jdbc/ResultSetMetaDataTest.java	2013-02-02 23:32:30 +0000
@@ -7,6 +7,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
 
 
 public class ResultSetMetaDataTest extends BaseTest {
@@ -50,4 +51,13 @@ public class ResultSetMetaDataTest exten
         assertEquals("us",cols.getString("COLUMN_NAME"));
         assertEquals(Types.INTEGER, cols.getInt("DATA_TYPE"));  
     }
+    
+    @Test 
+    public void conj17() throws Exception { 
+        ResultSet rs = connection.createStatement().executeQuery("select count(*),1 from information_schema.tables"); 
+        rs.next(); 
+        assertEquals(rs.getMetaData().getColumnName(1),"count(*)"); 
+        assertEquals(rs.getMetaData().getColumnName(2),"1"); 
+    } 
+
 }



More information about the commits mailing list