[Commits] Rev 399: CONJ-19 : DatabaseMetaData.getColumns() handled MySQL YEAR datatype as SMALLINT. in file:///H:/bzr/mariadb-jdbc-push/

Vladislav Vaintroub wlad at montyprogram.com
Sat Feb 2 23:05:01 EET 2013


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

------------------------------------------------------------
revno: 399
revision-id: wlad at montyprogram.com-20130202210450-dxrzq4m56uavbrex
parent: wlad at montyprogram.com-20130202133734-ayiwu6dkxx3nyl8m
fixes bug: https://mariadb.atlassian.net/browse/CONJ-19
committer: Vladislav Vaintroub <wlad at montyprogram.com>
branch nick: mariadb-jdbc-push
timestamp: Sat 2013-02-02 22:04:50 +0100
message:
  CONJ-19 : DatabaseMetaData.getColumns() handled MySQL YEAR datatype as SMALLINT.
  Fixed to return DATE by default  and SMALLINT only n case yearIsDateType=false is set
-------------- next part --------------
=== modified file 'src/main/java/org/mariadb/jdbc/MySQLDatabaseMetaData.java'
--- a/src/main/java/org/mariadb/jdbc/MySQLDatabaseMetaData.java	2013-02-02 13:37:14 +0000
+++ b/src/main/java/org/mariadb/jdbc/MySQLDatabaseMetaData.java	2013-02-02 21:04:50 +0000
@@ -57,6 +57,7 @@ import java.sql.Types;
 
 import org.mariadb.jdbc.internal.common.Utils;
 import org.mariadb.jdbc.internal.mysql.MySQLType;
+import org.mariadb.jdbc.internal.mysql.MySQLValueObject;
 
 
 public class MySQLDatabaseMetaData implements DatabaseMetaData {
@@ -65,7 +66,7 @@ public class MySQLDatabaseMetaData imple
     private String databaseProductName = "MySQL";
     private String username;
     
-    private static  String dataTypeClause (String fullTypeColumnName){
+    private  String dataTypeClause (String fullTypeColumnName){
         return
         " CASE data_type" +
         " WHEN 'bit' THEN "         + Types.BIT +
@@ -96,7 +97,7 @@ public class MySQLDatabaseMetaData imple
         " WHEN 'time' THEN "        + Types.TIME +
         " WHEN 'timestamp' THEN "   + Types.TIMESTAMP +
         " WHEN 'tinyint' THEN "     + Types.TINYINT +
-        " WHEN 'year' THEN "        + Types.SMALLINT +
+        " WHEN 'year' THEN "  + (((connection.getProtocol().datatypeMappingFlags &  MySQLValueObject.YEAR_IS_DATE_TYPE)== 0)? Types.SMALLINT :Types.DATE) +  
         " ELSE "                    + Types.OTHER +  
         " END ";
     }

=== modified file 'src/test/java/org/mariadb/jdbc/DatabaseMetadataTest.java'
--- a/src/test/java/org/mariadb/jdbc/DatabaseMetadataTest.java	2013-02-02 13:37:14 +0000
+++ b/src/test/java/org/mariadb/jdbc/DatabaseMetadataTest.java	2013-02-02 21:04:50 +0000
@@ -498,7 +498,7 @@ public class DatabaseMetadataTest extend
             checkType(columnName, type, "date_col", Types.DATE);
             checkType(columnName, type, "time_col", Types.TIME);
             checkType(columnName, type, "timestamp_col", Types.TIMESTAMP);
-            checkType(columnName, type, "year_col", Types.SMALLINT);
+            checkType(columnName, type, "year_col", Types.DATE);
             checkType(columnName, type, "bit_col", Types.BIT);
             checkType(columnName, type, "char_col", Types.CHAR);
             checkType(columnName, type, "varchar_col", Types.VARCHAR);
@@ -510,10 +510,35 @@ public class DatabaseMetadataTest extend
             checkType(columnName, type, "text_col", Types.LONGVARCHAR);
             checkType(columnName, type, "mediumtext_col", Types.LONGVARCHAR);
             checkType(columnName, type, "longtext_col", Types.LONGVARCHAR);
-            if (columnName.equals("char_col")) {
-                assertEquals(rs.getInt("COLUMN_SIZE"),5);
-            }
         }
     }
 
+    @Test
+    public void yearIsShortType() throws Exception {
+        Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&yearIsDateType=false");
+        try {
+            c.createStatement().execute("CREATE TABLE  IF NOT EXISTS ytab (y year)");
+            c.createStatement().execute("insert into ytab values(72)");
+            ResultSet rs = c.getMetaData().getColumns(connection.getCatalog(), null, "ytab", null);
+            assertTrue(rs.next());
+            assertEquals(rs.getInt("DATA_TYPE"),Types.SMALLINT);
+            ResultSet rs1 = c.createStatement().executeQuery("select * from ytab");
+            assertEquals(rs1.getMetaData().getColumnType(1), Types.SMALLINT);
+            assertTrue(rs1.next());
+            assertTrue(rs1.getObject(1) instanceof Short);
+            assertEquals(rs1.getShort(1), 1972);
+        } finally {
+            c.close();
+        }
+    }
+
+    /* CONJ-15 */
+    @Test
+    public void maxCharLengthUTF8() throws Exception {
+         connection.createStatement().execute("CREATE TABLE  IF NOT EXISTS maxcharlength (maxcharlength char(1)) character set utf8");
+         DatabaseMetaData dmd = connection.getMetaData();
+         ResultSet rs = dmd.getColumns(connection.getCatalog(), null, "maxcharlength", null);
+         assertTrue(rs.next());
+         assertEquals(rs.getInt("COLUMN_SIZE"),1);
+    }
 }
\ No newline at end of file



More information about the commits mailing list