db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1365113 - in /db/derby/code/branches/10.7: ./ java/engine/org/apache/derby/catalog/types/BaseTypeIdImpl.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/SystemCatalogTest.java
Date Tue, 24 Jul 2012 15:12:50 GMT
Author: mamta
Date: Tue Jul 24 15:12:49 2012
New Revision: 1365113

URL: http://svn.apache.org/viewvc?rev=1365113&view=rev
Log:
DERBY-5407 When run across the network, dblook produces unusable DDL for VARCHAR FOR BIT DATA
columns.

Backporting to 10.7


Modified:
    db/derby/code/branches/10.7/   (props changed)
    db/derby/code/branches/10.7/java/engine/org/apache/derby/catalog/types/BaseTypeIdImpl.java
    db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SystemCatalogTest.java

Propchange: db/derby/code/branches/10.7/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1364690

Modified: db/derby/code/branches/10.7/java/engine/org/apache/derby/catalog/types/BaseTypeIdImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/engine/org/apache/derby/catalog/types/BaseTypeIdImpl.java?rev=1365113&r1=1365112&r2=1365113&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/engine/org/apache/derby/catalog/types/BaseTypeIdImpl.java
(original)
+++ db/derby/code/branches/10.7/java/engine/org/apache/derby/catalog/types/BaseTypeIdImpl.java
Tue Jul 24 15:12:49 2012
@@ -255,29 +255,37 @@ public class BaseTypeIdImpl implements F
             // will lose the format id. This can happen if you pass one of these
             // objects across the network. Here we recover the format id.
             //
-            if ( "BOOLEAN".equals( unqualifiedName ) ) { return StoredFormatIds.BOOLEAN_TYPE_ID_IMPL;
}
-            else if ( "BIGINT".equals( unqualifiedName ) ) { return StoredFormatIds.LONGINT_TYPE_ID_IMPL;
}
-            else if ( "INTEGER".equals( unqualifiedName ) ) { return StoredFormatIds.INT_TYPE_ID_IMPL;
}
-            else if ( "SMALLINT".equals( unqualifiedName ) ) { return StoredFormatIds.SMALLINT_TYPE_ID_IMPL;
}
-            else if ( "TINYINT".equals( unqualifiedName ) ) { return StoredFormatIds.TINYINT_TYPE_ID_IMPL;
}
-            else if ( "LONGINT".equals( unqualifiedName ) ) { return StoredFormatIds.LONGINT_TYPE_ID_IMPL;
}
-            else if ( "DECIMAL".equals( unqualifiedName ) ) { return StoredFormatIds.DECIMAL_TYPE_ID_IMPL;
}
-            else if ( "NUMERIC".equals( unqualifiedName ) ) { return StoredFormatIds.DECIMAL_TYPE_ID_IMPL;
}
-            else if ( "DOUBLE".equals( unqualifiedName ) ) { return StoredFormatIds.DOUBLE_TYPE_ID_IMPL;
}
-            else if ( "REAL".equals( unqualifiedName ) ) { return StoredFormatIds.REAL_TYPE_ID_IMPL;
}
-            else if ( "REF".equals( unqualifiedName ) ) { return StoredFormatIds.REF_TYPE_ID_IMPL;
}
-            else if ( "CHAR".equals( unqualifiedName ) ) { return StoredFormatIds.CHAR_TYPE_ID_IMPL;
}
-            else if ( "VARCHAR".equals( unqualifiedName ) ) { return StoredFormatIds.VARCHAR_TYPE_ID_IMPL;
}
-            else if ( "LONG VARCHAR".equals( unqualifiedName ) ) { return StoredFormatIds.LONGVARCHAR_TYPE_ID_IMPL;
}
-            else if ( "CLOB".equals( unqualifiedName ) ) { return StoredFormatIds.CLOB_TYPE_ID_IMPL;
}
+            if ( TypeId.BOOLEAN_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.BOOLEAN_TYPE_ID_IMPL;
}
+            else if ( TypeId.LONGINT_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.LONGINT_TYPE_ID_IMPL;
}
+            else if ( TypeId.INTEGER_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.INT_TYPE_ID_IMPL;
}
+            else if ( TypeId.SMALLINT_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.SMALLINT_TYPE_ID_IMPL;
}
+            else if ( TypeId.TINYINT_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.TINYINT_TYPE_ID_IMPL;
}
+            else if ( TypeId.LONGINT_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.LONGINT_TYPE_ID_IMPL;
}
+            else if ( TypeId.DECIMAL_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.DECIMAL_TYPE_ID_IMPL;
}
+            else if ( TypeId.NUMERIC_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.DECIMAL_TYPE_ID_IMPL;
}
+            else if ( TypeId.DOUBLE_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.DOUBLE_TYPE_ID_IMPL;
}
+            else if ( TypeId.REAL_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.REAL_TYPE_ID_IMPL;
}
+            else if ( TypeId.REF_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.REF_TYPE_ID_IMPL;
}
+            else if ( TypeId.CHAR_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.CHAR_TYPE_ID_IMPL;
}
+            else if ( TypeId.VARCHAR_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.VARCHAR_TYPE_ID_IMPL;
}
+            else if ( TypeId.LONGVARCHAR_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.LONGVARCHAR_TYPE_ID_IMPL;
}
+            else if ( TypeId.CLOB_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.CLOB_TYPE_ID_IMPL;
}
+            //DERBY-5407 Network Server on wire sends CHAR () FOR BIT DATA 
+            // not CHAR FOR BIT DATA. Keeping the check for CHAR FOR BIT
+            // DATA just in case if there is any dependency on that check
+            else if ( TypeId.BIT_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.BIT_TYPE_ID_IMPL;
}
             else if ( "CHAR FOR BIT DATA".equals( unqualifiedName ) ) { return StoredFormatIds.BIT_TYPE_ID_IMPL;
}
+            //DERBY-5407 Network Server on wire sends VARCHAR () FOR BIT DATA 
+            // not VARCHAR FOR BIT DATA. Keeping the check for VARCHAR FOR BIT
+            // DATA just in case if there is any dependency on that check
+            else if ( TypeId.VARBIT_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.VARBIT_TYPE_ID_IMPL;
}
             else if ( "VARCHAR FOR BIT DATA".equals( unqualifiedName ) ) { return StoredFormatIds.VARBIT_TYPE_ID_IMPL;
}
-            else if ( "LONG VARCHAR FOR BIT DATA".equals( unqualifiedName ) ) { return StoredFormatIds.LONGVARBIT_TYPE_ID_IMPL;
}
-            else if ( "BLOB".equals( unqualifiedName ) ) { return StoredFormatIds.BLOB_TYPE_ID_IMPL;
}
-            else if ( "DATE".equals( unqualifiedName ) ) { return StoredFormatIds.DATE_TYPE_ID_IMPL;
}
-            else if ( "TIME".equals( unqualifiedName ) ) { return StoredFormatIds.TIME_TYPE_ID_IMPL;
}
-            else if ( "TIMESTAMP".equals( unqualifiedName ) ) { return StoredFormatIds.TIMESTAMP_TYPE_ID_IMPL;
}
-            else if ( "XML".equals( unqualifiedName ) ) { return StoredFormatIds.XML_TYPE_ID_IMPL;
}
+            else if ( TypeId.LONGVARBIT_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.LONGVARBIT_TYPE_ID_IMPL;
}
+            else if ( TypeId.BLOB_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.BLOB_TYPE_ID_IMPL;
}
+            else if ( TypeId.DATE_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.DATE_TYPE_ID_IMPL;
}
+            else if ( TypeId.TIME_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.TIME_TYPE_ID_IMPL;
}
+            else if ( TypeId.TIMESTAMP_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.TIMESTAMP_TYPE_ID_IMPL;
}
+            else if ( TypeId.XML_NAME.equals( unqualifiedName ) ) { return StoredFormatIds.XML_TYPE_ID_IMPL;
}
             else { return 0; }
         }
     }

Modified: db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SystemCatalogTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SystemCatalogTest.java?rev=1365113&r1=1365112&r2=1365113&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SystemCatalogTest.java
(original)
+++ db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SystemCatalogTest.java
Tue Jul 24 15:12:49 2012
@@ -25,6 +25,9 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.ResultSet;
+import java.sql.Types;
+
+import org.apache.derby.iapi.services.io.StoredFormatIds;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -40,7 +43,7 @@ import junit.framework.TestSuite;
  */
 public class SystemCatalogTest extends BaseJDBCTestCase {
 
-	public SystemCatalogTest(String name) {
+    public SystemCatalogTest(String name) {
 		super(name);
 	}
 	
@@ -555,6 +558,117 @@ public class SystemCatalogTest extends B
 		s.execute("drop table uniquekey3");
 		s.close();
 	}
+
+	/**
+	 * This test creates a table with all supported datatypes aqnd ensures 
+	 * that bound embedded and network server return the identical datatypes
+	 * for those datatypes. DERBY-5407
+	 * @throws SQLException
+	 */
+	public void testColumnDatatypesOfAllDataTypesInSystemCatalogs() throws SQLException {
+		int totalNumOfColumnDatatypes = 21;
+		Statement s = createStatement();
+		s.execute("create table allTypesTable (" +
+			"    a01 bigint," +
+			"    a02 blob,\n" +
+			"    a03 char( 1 ),\n" +
+			"    a04 char( 1 ) for bit data ,\n" +
+			"    a05 clob,\n" +
+			"    a06 date,\n" +
+			"    a07 decimal,\n" +
+			"    a08 double,\n" +
+			"    a09 float,\n" +
+			"    a10 int,\n" +
+			"    a11 long varchar,\n" +
+			"    a12 long varchar for bit data,\n" +
+			"    a13 numeric,\n" +
+			"    a14 real,\n" +
+			"    a15 smallint,\n" +
+			"    a16 time,\n" +
+			"    a17 timestamp,\n" +
+			"    a18 varchar(10),\n" +
+			"    a19 varchar(10) for bit data,\n" +
+			"    a20 xml,\n" +
+			"    a21 boolean\n" +
+        	")");
+		ResultSet rs = s.executeQuery("select columndatatype "+
+			"from sys.systables, sys.syscolumns "+
+			"where tablename='ALLTYPESTABLE' "+
+			"and tableid=referenceid "+
+			"order by columnname");
+		for (int i=1; i<=totalNumOfColumnDatatypes; i++)
+		{
+			rs.next();
+			switch(i)
+			{
+			case 1 :
+				assertTrue(rs.getString(1).startsWith("BIGINT"));
+				break;
+			case 2 :
+				assertTrue(rs.getString(1).startsWith("BLOB(2147483647)"));
+				break;
+			case 3 :
+				assertTrue(rs.getString(1).startsWith("CHAR(1)"));
+				break;
+			case 4 :
+				assertTrue(rs.getString(1).startsWith("CHAR (1) FOR BIT DATA"));
+				break;
+			case 5 :
+				assertTrue(rs.getString(1).startsWith("CLOB(2147483647)"));
+				break;
+			case 6 :
+				assertTrue(rs.getString(1).startsWith("DATE"));
+				break;
+			case 7 :
+				assertTrue(rs.getString(1).startsWith("DECIMAL(5,0)"));
+				break;
+			case 8 :
+				assertTrue(rs.getString(1).startsWith("DOUBLE"));
+				break;
+			case 9 :
+				assertTrue(rs.getString(1).startsWith("DOUBLE"));
+				break;
+			case 10 :
+				assertTrue(rs.getString(1).startsWith("INTEGER"));
+				break;
+			case 11 :
+				assertTrue(rs.getString(1).startsWith("LONG VARCHAR"));
+				break;
+			case 12 :
+				assertTrue(rs.getString(1).startsWith("LONG VARCHAR FOR BIT DATA"));
+				break;
+			case 13 :
+				assertTrue(rs.getString(1).startsWith("NUMERIC(5,0)"));
+				break;
+			case 14 :
+				assertTrue(rs.getString(1).startsWith("REAL"));
+				break;
+			case 15 :
+				assertTrue(rs.getString(1).startsWith("SMALLINT"));
+				break;
+			case 16 :
+				assertTrue(rs.getString(1).startsWith("TIME"));
+				break;
+			case 17 :
+				assertTrue(rs.getString(1).startsWith("TIMESTAMP"));
+				break;
+			case 18 :
+				assertTrue(rs.getString(1).startsWith("VARCHAR(10)"));
+				break;
+			case 19 :
+				assertTrue(rs.getString(1).startsWith("VARCHAR (10) FOR BIT DATA"));
+				break;
+			case 20 :
+				assertTrue(rs.getString(1).startsWith("XML"));
+				break;
+			case 21 :
+				assertTrue(rs.getString(1).startsWith("BOOLEAN"));
+				break;
+			}
+		}
+		rs.close();
+		s.execute("drop table ALLTYPESTABLE");
+	}
 	
 	/**
 	 * Check that column datatypes are reported correctly, both in



Mime
View raw message