You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2006/11/20 14:17:12 UTC

svn commit: r477168 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/

Author: kahatlen
Date: Mon Nov 20 05:17:11 2006
New Revision: 477168

URL: http://svn.apache.org/viewvc?view=rev&rev=477168
Log:
DERBY-1132: Truncation Error with Concat

The Char & Varchar functions were not handled separately to assign to
length for the target type (in the bindExpression() method of
CastNode.java) and thus a default value of 15 was getting assigned to
it (from getColumnDisplaySize() method of DataTypeUtilities class)

Now I added a check for the string types (i.e. both Char & Varchar) in
the source type, and using the operand's maximum length or the maximum
length for that data type (whichever is minimum) and assigning it to
be the length for the target type. Thus avoiding the unwanted
truncation error caused by the default value of 15.

Patch contributed by Saurabh Vyas.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cast.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ejbql.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java?view=diff&rev=477168&r1=477167&r2=477168
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java Mon Nov 20 05:17:11 2006
@@ -41,6 +41,7 @@
 
 import org.apache.derby.iapi.types.DataTypeUtilities;
 import org.apache.derby.iapi.types.TypeId;
+import org.apache.derby.iapi.reference.Limits;
 
 import org.apache.derby.iapi.reference.SQLState;
 
@@ -235,6 +236,23 @@
 					if (opndType.getScale() > 0)
 						length += 1;               // 1 for the decimal .
 				 
+				}
+				/*
+				 * Derby-1132 : The length for the target type was calculated
+				 * incorrectly while Char & Varchar functions were used. Thus
+				 * adding the check for Char & Varchar and calculating the
+				 * length based on the operand type.
+				 */
+				else if(srcTypeId.isStringTypeId())
+				{
+					length = opndType.getMaximumWidth();
+			
+					// Truncate the target type width to the max width of the
+					// data type
+					if (this.targetCharType == Types.CHAR)
+						length = Math.min(length, Limits.DB2_CHAR_MAXWIDTH);
+					else if (this.targetCharType == Types.VARCHAR)
+						length = Math.min(length, Limits.DB2_VARCHAR_MAXWIDTH);
 				}
 				else 
 				{

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cast.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cast.out?view=diff&rev=477168&r1=477167&r2=477168
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cast.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cast.out Mon Nov 20 05:17:11 2006
@@ -1515,30 +1515,30 @@
 ij> insert into t1 values ('2005-09-10', '18.44.02', '2004-09-08-12.20.30.123456', 'cba', 'c');
 1 row inserted/updated/deleted
 ij> select char(c5), char(c6), char(c7), char(c8), char(c9) from t1;
-1         |2       |3                         |4              |5              
-------------------------------------------------------------------------------
-2003-09-10|16:44:02|xxxxxxFILTERED-TIMESTAMPxxxxx|abc            |abcde          
-2005-09-10|18:44:02|xxxxxxFILTERED-TIMESTAMPxxxxx|cba            |c              
+1         |2       |3                         |4    |5    
+----------------------------------------------------------
+2003-09-10|16:44:02|xxxxxxFILTERED-TIMESTAMPxxxxx|abc  |abcde
+2005-09-10|18:44:02|xxxxxxFILTERED-TIMESTAMPxxxxx|cba  |c    
 ij> select varchar(c5), varchar(c6), varchar(c7), varchar(c8), varchar(c9) from t1;
-1         |2       |3                         |4              |5              
-------------------------------------------------------------------------------
-2003-09-10|16:44:02|xxxxxxFILTERED-TIMESTAMPxxxxx|abc            |abcde          
-2005-09-10|18:44:02|xxxxxxFILTERED-TIMESTAMPxxxxx|cba            |c              
+1         |2       |3                         |4    |5    
+----------------------------------------------------------
+2003-09-10|16:44:02|xxxxxxFILTERED-TIMESTAMPxxxxx|abc  |abcde
+2005-09-10|18:44:02|xxxxxxFILTERED-TIMESTAMPxxxxx|cba  |c    
 ij> select char(c8, 10), varchar(c9, 9) from t1;
 1         |2        
 --------------------
 abc       |abcde    
 cba       |c        
 ij> select { fn concat(c8, char(c8)) } from t1;
-1                   
---------------------
-abc  abc            
-cba  cba            
+1         
+----------
+abc  abc  
+cba  cba  
 ij> select { fn concat(c8, varchar(c9)) } from t1;
-1                   
---------------------
-abc  abcde          
-cba  c              
+1         
+----------
+abc  abcde
+cba  c    
 ij> select { fn concat(varchar(c9, 20), char(c8, 8)) } from t1;
 1                           
 ----------------------------

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ejbql.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ejbql.out?view=diff&rev=477168&r1=477167&r2=477168
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ejbql.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ejbql.out Mon Nov 20 05:17:11 2006
@@ -1742,8 +1742,8 @@
 1              
 ---------------
 ij> values{ fn concat( CHAR(''), CHAR('') ) };
-1                             
-------------------------------
+1              
+---------------
 ij> values{ fn concat( 45, 67 )};
 ERROR 42846: Cannot convert types 'INTEGER' to 'VARCHAR'.
 ij> values{ fn concat( '45', 67 )};
@@ -1751,9 +1751,9 @@
 ij> values{ fn concat( 45, '67' )};
 ERROR 42846: Cannot convert types 'INTEGER' to 'VARCHAR'.
 ij> values{ fn concat( CHAR('C'), CHAR('#') ) };
-1                             
-------------------------------
-C              #              
+1   
+----
+C#  
 ij> values{ fn concat( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ`1234567890-=\    [];,./ \'' |',
                    'abcdefghijklmnopqrstuvwxyz~!@#$%^&*()_+|<>?:"{}     ''''''      ' ) };
 1                                                                                                                   

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out?view=diff&rev=477168&r1=477167&r2=477168
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out Mon Nov 20 05:17:11 2006
@@ -2541,11 +2541,11 @@
 ij> insert into t values (CHAR('2000-01-07'), 
 		      CHAR('20:06:58'), 
 		      CHAR('xxxxxxFILTERED-TIMESTAMPxxxxx'));
-ERROR 22007: The syntax of the string representation of a datetime value is incorrect.
+1 row inserted/updated/deleted
 ij> insert into t values (CHAR('2000-1-06'), 
 		      CHAR('20:06:57'), 
 		      CHAR('2000-01-7 20:06:58.8000'));
-ERROR 22007: The syntax of the string representation of a datetime value is incorrect.
+1 row inserted/updated/deleted
 ij> VALUES SYSCS_UTIL.SYSCS_CHECK_TABLE('APP', 'T');
 1          
 -----------