db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r505023 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Date Thu, 08 Feb 2007 20:09:09 GMT
Author: djd
Date: Thu Feb  8 12:09:09 2007
New Revision: 505023

URL: http://svn.apache.org/viewvc?view=rev&rev=505023
Log:
DERBY-2242 (partial) Add ODBC type information checking for getTypeInfo() in DatabaseMetaDataTest.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?view=diff&rev=505023&r1=505022&r2=505023
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Thu Feb  8 12:09:09 2007
@@ -904,12 +904,22 @@
         int rowPosition = 0;
         while (rs.next())
         {
-            //assertNull("TABLE_CAT", rs.getString("TABLE_CAT"));
+            boolean ourTable;
             assertEquals("TABLE_CAT", "", rs.getString("TABLE_CAT"));
-            assertEquals("TABLE_SCHEM",
-                    dbIDS[rowPosition/dbIDS.length], rs.getString("TABLE_SCHEM"));
-            assertEquals("TABLE_NAME",
+            
+            String schema = rs.getString("TABLE_SCHEM");
+            
+            // See if the table is in one of the schemas we created.
+            // If not we perform what checking we can.
+            boolean ourSchema = Arrays.binarySearch(dbIDS, schema) >= 0;
+            
+            if (ourSchema) {        
+                assertEquals("TABLE_SCHEM",
+                    dbIDS[rowPosition/dbIDS.length], schema);
+                assertEquals("TABLE_NAME",
                     dbIDS[rowPosition%dbIDS.length], rs.getString("TABLE_NAME"));
+            }
+            
             assertEquals("TABLE_TYPE", "TABLE", rs.getString("TABLE_TYPE"));
             
             assertEquals("REMARKS", "", rs.getString("REMARKS"));
@@ -920,7 +930,8 @@
             assertNull("SELF_REFERENCING_COL_NAME", rs.getString("SELF_REFERENCING_COL_NAME"));
             assertNull("REF_GENERATION", rs.getString("REF_GENERATION"));
             
-            rowPosition++;
+            if (ourSchema)
+                rowPosition++;
          }
          rs.close();
          assertEquals("getTables count for all user tables",
@@ -1352,35 +1363,62 @@
         if (usingDerbyNetClient())
             BOOLEAN = Types.SMALLINT;
         
+        String[] JDBC_COLUMN_NAMES = new String[] {
+                "TYPE_NAME", "DATA_TYPE", "PRECISION", "LITERAL_PREFIX",
+                "LITERAL_SUFFIX", "CREATE_PARAMS", "NULLABLE", "CASE_SENSITIVE",
+                
+                "SEARCHABLE", "UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE",
+                "AUTO_INCREMENT", "LOCAL_TYPE_NAME",
+                
+                "MINIMUM_SCALE", "MAXIMUM_SCALE",
+                "SQL_DATA_TYPE", "SQL_DATETIME_SUB",
+                
+                "NUM_PREC_RADIX"          
+              };
+        
+        int[] JDBC_COLUMN_TYPES = new int[] {
+                Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
+                Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, BOOLEAN,
+                
+                Types.SMALLINT, BOOLEAN, BOOLEAN,
+                BOOLEAN, Types.VARCHAR,
+                
+                Types.SMALLINT, Types.SMALLINT,
+                Types.INTEGER, Types.INTEGER,
+                
+                Types.INTEGER
+              };
+        
+        boolean[] JDBC_COLUMN_NULLABILITY = {
+                false, false, true, true,
+                true, true, false, false,
+                false, true, false,
+                true, true,
+                true, true,
+                true, true,
+                true 
+        };
+        
+        // DERBY-2307 Nullablity is wrong for columns 1,7,9 (1-based)
+        // Make a modified copy of JDBC_COLUMN_NULLABILITY
+        // here to allow the test to pass. Left JDBC_COLUMN_NULLABILITY
+        // as the expected versions as it is also used for the ODBC
+        // checks below and has the correct values.
+        boolean[] JDBC_COLUMN_NULLABILITY_DERBY_2307 = {
+                true, false, true, true,
+                true, true, true, false,
+                true, true, false,
+                true, true,
+                true, true,
+                true, true,
+                true 
+        };
+        
         ResultSet rs = getDMD().getTypeInfo();
-        assertMetaDataResultSet(rs,
-          new String[] {
-            "TYPE_NAME", "DATA_TYPE", "PRECISION", "LITERAL_PREFIX",
-            "LITERAL_SUFFIX", "CREATE_PARAMS", "NULLABLE", "CASE_SENSITIVE",
-            
-            "SEARCHABLE", "UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE",
-            "AUTO_INCREMENT", "LOCAL_TYPE_NAME",
-            
-            "MINIMUM_SCALE", "MAXIMUM_SCALE",
-            "SQL_DATA_TYPE", "SQL_DATETIME_SUB",
-            
-            "NUM_PREC_RADIX"          
-          },
-          new int[] {
-            Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
-            Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, BOOLEAN,
-            
-            Types.SMALLINT, BOOLEAN, BOOLEAN,
-            BOOLEAN, Types.VARCHAR,
-            
-            Types.SMALLINT, Types.SMALLINT,
-            Types.INTEGER, Types.INTEGER,
-            
-            Types.INTEGER
-          }
-        , null
+        assertMetaDataResultSet(rs, JDBC_COLUMN_NAMES, JDBC_COLUMN_TYPES
+        , JDBC_COLUMN_NULLABILITY_DERBY_2307
         );
-        
+
 	/*
 	 Derby-2258 Removed 3 data types which are not supported by Derby
 	 and added XML data type which is supported by Derby
@@ -1658,7 +1696,49 @@
         
         rs.close();
         
-        getSQLTypes(getConnection());
+        // Now check the ODBC version:
+        
+        // ODBC column names & types differ from JDBC slightly.
+        // ODBC has one more column.
+        String[] ODBC_COLUMN_NAMES = new String[19];
+        System.arraycopy(JDBC_COLUMN_NAMES, 0, ODBC_COLUMN_NAMES, 0,
+                JDBC_COLUMN_NAMES.length);
+        ODBC_COLUMN_NAMES[2] = "COLUMN_SIZE";
+        ODBC_COLUMN_NAMES[11] = "AUTO_UNIQUE_VAL";
+        ODBC_COLUMN_NAMES[18] = "INTERVAL_PRECISION";
+        
+        int[] ODBC_COLUMN_TYPES = new int[ODBC_COLUMN_NAMES.length];
+        System.arraycopy(JDBC_COLUMN_TYPES, 0, ODBC_COLUMN_TYPES, 0,
+                JDBC_COLUMN_TYPES.length);
+        
+        ODBC_COLUMN_TYPES[1] = Types.SMALLINT; // DATA_TYPE
+        ODBC_COLUMN_TYPES[7] = Types.SMALLINT; // CASE_SENSITIVE
+        ODBC_COLUMN_TYPES[9] = Types.SMALLINT; // UNSIGNED_ATTRIBUTE
+        ODBC_COLUMN_TYPES[10] = Types.SMALLINT; // FIXED_PREC_SCALE
+        ODBC_COLUMN_TYPES[11] = Types.SMALLINT; // AUTO_UNIQUE_VAL
+        ODBC_COLUMN_TYPES[15] = Types.SMALLINT; // SQL_DATA_TYPE
+        ODBC_COLUMN_TYPES[16] = Types.SMALLINT; // SQL_DATETIME_SUB
+        ODBC_COLUMN_TYPES[18] = Types.SMALLINT; // INTERVAL_PRECISION
+        
+        boolean[] ODBC_COLUMN_NULLABILITY = new boolean[ODBC_COLUMN_NAMES.length];
+        System.arraycopy(JDBC_COLUMN_NULLABILITY, 0, ODBC_COLUMN_NULLABILITY, 0,
+                JDBC_COLUMN_NULLABILITY.length);
+        
+        ODBC_COLUMN_NULLABILITY[15] = false; // // SQL_DATETIME_SUB (JDBC unused)
+        ODBC_COLUMN_NULLABILITY[18] = true; // INTERVAL_PRECISION
+                
+        CallableStatement cs = prepareCall(
+                "CALL SYSIBM.SQLGETTYPEINFO (0, 'DATATYPE=''ODBC''')");
+        
+        cs.execute();
+        ResultSet odbcrs = cs.getResultSet();
+        assertNotNull(odbcrs);
+        
+        assertMetaDataResultSet(odbcrs, ODBC_COLUMN_NAMES, ODBC_COLUMN_TYPES, null);
+        
+        odbcrs.close();
+        cs.close();
+
     }
     
     /*



Mime
View raw message