You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Mamta Satoor <ms...@gmail.com> on 2007/02/17 04:41:37 UTC

Dan's svn commit: r508418 - Mapping of DOUBLE to Types.INTEGER

Dan, your commit this morning had following change for "Given a valid SQL
type return the corresponding
JDBC type identifier from java.sql.Types."

+        if ("DOUBLE".equals(type) || "DOUBLE PRECISION".equals(type))
+            return Types.INTEGER;

Is Types.INTEGER the correct return value? Reference manual has a table for
Mapping of java.sql.Types to SQL types and it doesn't have INTEGER for SQL
type DOUBLE.

Mamta


On 2/16/07, djd@apache.org <dj...@apache.org> wrote:
>
> Author: djd
> Date: Fri Feb 16 06:24:03 2007
> New Revision: 508418
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=508418
> Log:
> Improve the JDBC.assertSameContents to use the assertEquals() methods for
> Blob and Clob in BaseJDBCTestCase.
> Create a SQLXML constant in JDBC for the tests to use rather than using
> engine code.
> Add an initial version of utility method to DatabaseMetaDataTest that
> returns a JDBC type identifier from java.sql.Types
> given a SQL type name.
>
> Modified:
>
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
>
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
>
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.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=508418&r1=508417&r2=508418
>
> ==============================================================================
> ---
> 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
> Fri Feb 16 06:24:03 2007
> @@ -20,6 +20,7 @@
> */
> package org.apache.derbyTesting.functionTests.tests.jdbcapi;
>
> +import java.io.IOException;
> import java.sql.CallableStatement;
> import java.sql.Connection;
> import java.sql.DatabaseMetaData;
> @@ -79,6 +80,7 @@
> *  metadata continues to work at various points in the upgrade.
> */
> public class DatabaseMetaDataTest extends BaseJDBCTestCase {
> +
>     /*
>     ** Escaped function testing
>     */
> @@ -786,10 +788,11 @@
>     /**
>      * Execute dmd.getTables() but perform additional checking
>      * of the ODBC variant.
> +     * @throws IOException
>      */
>     private ResultSet getDMDTables(DatabaseMetaData dmd,
>             String catalog, String schema, String table, String[]
> tableTypes)
> -        throws SQLException
> +        throws SQLException, IOException
>     {
>         checkGetTablesODBC(catalog, schema, table, tableTypes);
>         return dmd.getTables(catalog, schema, table, tableTypes);
> @@ -799,8 +802,9 @@
>      * Test getTables() without modifying the database.
>      *
>      * @throws SQLException
> +     * @throws IOException
>      */
> -    public void testGetTablesNoModify() throws SQLException {
> +    public void testGetTablesNoModify() throws SQLException, IOException
> {
>
>         DatabaseMetaData dmd = getDMD();
>
> @@ -876,8 +880,9 @@
>      * Test getTables() with  modifying the database.
>      *
>      * @throws SQLException
> +     * @throws IOException
>      */
> -    public void testGetTablesModify() throws SQLException {
> +    public void testGetTablesModify() throws SQLException, IOException {
>
>         int totalTables = createTablesForTest(false);
>
> @@ -994,9 +999,10 @@
>     /**
>      * Execute and check the ODBC variant of getTables which
>      * uses a procedure to provide the same information to ODBC clients.
> +     * @throws IOException
>      */
>     private void checkGetTablesODBC(String catalog, String schema,
> -            String table, String[] tableTypes) throws SQLException
> +            String table, String[] tableTypes) throws SQLException,
> IOException
>     {
>         String tableTypesAsString = null;
>         if (tableTypes != null) {
> @@ -1356,8 +1362,6 @@
>      */
>     public void testGetTypeInfo() throws SQLException
>     {
> -       // SQLXML is the constant used to represent XML data type in derby
> -       final int SQLXML = JDBC40Translation.SQLXML;
>         // Client returns BOOLEAN type from the engine as SMALLINT
>         int BOOLEAN = Types.BOOLEAN;
>         if (usingDerbyNetClient())
> @@ -1430,7 +1434,7 @@
>           Types.INTEGER, Types.LONGVARBINARY, Types.LONGVARCHAR,
>           Types.NUMERIC, Types.REAL, Types.SMALLINT,
>           Types.TIME, Types.TIMESTAMP,  Types.VARBINARY,
> -          Types.VARCHAR, SQLXML
> +          Types.VARCHAR, JDBC.SQLXML
>         };
>
>         // Rows are returned from getTypeInfo in order of
> @@ -1517,7 +1521,7 @@
>             case Types.VARCHAR:
>                 precision = 32672;
>                 break;
> -           case SQLXML:
> +           case JDBC.SQLXML:
>                precision = 0;
>                break;
>             }
> @@ -1600,7 +1604,7 @@
>             case Types.VARCHAR:
>                 searchable = DatabaseMetaData.typeSearchable;
>                 break;
> -           case SQLXML:
> +           case JDBC.SQLXML:
>                searchable = DatabaseMetaData.typePredNone;
>                break;
>             default:
> @@ -2020,5 +2024,58 @@
>         }
>
>         return list;
> +    }
> +
> +    /**
> +     * Given a valid SQL type return the corresponding
> +     * JDBC type identifier from java.sql.Types.
> +     * Will assert if the type is not known
> +     * (in future, currently just return Types.NULL).
> +     */
> +    public static int getJDBCType(String type)
> +    {
> +        if ("SMALLINT".equals(type))
> +            return Types.SMALLINT;
> +        if ("INTEGER".equals(type) || "INT".equals(type))
> +            return Types.INTEGER;
> +        if ("BIGINT".equals(type))
> +            return Types.BIGINT;
> +
> +        if (type.equals("FLOAT") || type.startsWith("FLOAT("))
> +            return Types.FLOAT;
> +        if (type.equals("REAL"))
> +            return Types.REAL;
> +
> +        if ("DOUBLE".equals(type) || "DOUBLE PRECISION".equals(type))
> +            return Types.INTEGER;
> +
> +        if ("DATE".equals(type))
> +            return Types.DATE;
> +        if ("TIME".equals(type))
> +            return Types.TIME;
> +        if ("TIMESTAMP".equals(type))
> +            return Types.TIMESTAMP;
> +
> +        if (type.equals("DECIMAL") || type.startsWith("DECIMAL("))
> +            return Types.DECIMAL;
> +        if (type.equals("NUMERIC") || type.startsWith("NUMERIC("))
> +            return Types.NUMERIC;
> +
> +        if (type.equals("BLOB") || type.startsWith("BLOB("))
> +            return Types.BLOB;
> +        if (type.equals("BINARY LARGE OBJECT") ||
> +                type.startsWith("BINARY LARGE OBJECT("))
> +            return Types.BLOB;
> +
> +        if (type.equals("CLOB") || type.startsWith("CLOB("))
> +            return Types.CLOB;
> +        if (type.equals("CHARACTER LARGE OBJECT") ||
> +                type.startsWith("CHARACTER LARGE OBJECT("))
> +            return Types.CLOB;
> +
> +        if ("XML".equals(type))
> +            return JDBC.SQLXML;
> +
> +        return Types.NULL;
>     }
> }
>
> Modified:
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
> URL:
> http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?view=diff&rev=508418&r1=508417&r2=508418
>
> ==============================================================================
> ---
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
> (original)
> +++
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
> Fri Feb 16 06:24:03 2007
> @@ -444,12 +444,10 @@
>         assertEquals("Clobs have different lengths",
>                      c1.length(), c2.length());
>         Reader r1 = c1.getCharacterStream();
> +        assertNotNull(r1); // java.sql.Blob object cannot represent NULL
>         Reader r2 = c2.getCharacterStream();
> -        if (r1 == null || r2 == null) {
> -            assertNull("Clob c2 has null-stream, clob c1 doesn't", r1);
> -            assertNull("Clob c1 has null-stream, clob c2 doesn't", r2);
> -            return;
> -        }
> +        assertNotNull(r2); // java.sql.Blob object cannot represent NULL
> +
>         long index = 1;
>         int ch1 = r1.read();
>         int ch2 = r2.read();
>
> Modified:
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
> URL:
> http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?view=diff&rev=508418&r1=508417&r2=508418
>
> ==============================================================================
> ---
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
> (original)
> +++
> db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Fri
> Feb 16 06:24:03 2007
> @@ -19,6 +19,7 @@
> */
> package org.apache.derbyTesting.junit;
>
> +import java.io.IOException;
> import java.sql.*;
> import java.util.ArrayList;
> import java.util.Arrays;
> @@ -33,6 +34,11 @@
> *
> */
> public class JDBC {
> +
> +    /**
> +     * Types.SQLXML value without having to compile with JDBC4.
> +     */
> +    public static final int SQLXML = 2009;
>
>     /**
>      * Tell if we are allowed to use DriverManager to create database
> @@ -751,11 +757,12 @@
>      * The compete ResultSet is walked for both ResultSets,
>      * and they are both closed.
>      * <BR>
> -     * Columns are compared as primitive ints or longs or as
> -     * Strings. Code needs more work to handle BLOB/CLOB columns.
> +     * Columns are compared as primitive ints or longs, Blob,
> +     * Clobs or as Strings.
> +     * @throws IOException
>      */
>     public static void assertSameContents(ResultSet rs1, ResultSet rs2)
> -            throws SQLException {
> +            throws SQLException, IOException {
>         ResultSetMetaData rsmd = rs1.getMetaData();
>         int columnCount = rsmd.getColumnCount();
>         while (rs1.next()) {
> @@ -768,6 +775,14 @@
>                     break;
>                 case Types.BIGINT:
>                     Assert.assertEquals(rs1.getLong(col), rs2.getLong
> (col));
> +                    break;
> +                case Types.BLOB:
> +                    BaseJDBCTestCase.assertEquals(rs1.getBlob(col),
> +                            rs2.getBlob(col));
> +                    break;
> +                case Types.CLOB:
> +                    BaseJDBCTestCase.assertEquals(rs1.getClob(col),
> +                            rs2.getClob(col));
>                     break;
>                 default:
>                     Assert.assertEquals(rs1.getString(col), rs2.getString
> (col));
>
>
>

Re: Dan's svn commit: r508418 - Mapping of DOUBLE to Types.INTEGER

Posted by Daniel John Debrunner <dj...@apache.org>.
Mamta Satoor wrote:
> Dan, your commit this morning had following change for "Given a valid 
> SQL type return the corresponding
> JDBC type identifier from java.sql.Types."
>  
> +        if ("DOUBLE".equals(type) || "DOUBLE PRECISION".equals(type))
> +            return Types.INTEGER;
>  
> Is Types.INTEGER the correct return value? Reference manual has a table 
> for Mapping of java.sql.Types to SQL types and it doesn't have INTEGER 
> for SQL type DOUBLE.

Thanks for noticing that! Anyone should feel free to fix issues if they 
see them, remember no code ownership :-)

Dan.