db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From banda...@apache.org
Subject svn commit: r158935 - incubator/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
Date Thu, 24 Mar 2005 18:57:29 GMT
Author: bandaram
Date: Thu Mar 24 10:57:28 2005
New Revision: 158935

URL: http://svn.apache.org/viewcvs?view=rev&rev=158935
Log:
Derby-157: Catch Illegal values for date, time and timestamp.

Submitted by Army Brown (qozinx@sbcglobal.net)

Modified:
    incubator/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java

Modified: incubator/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?view=diff&r1=158934&r2=158935
==============================================================================
--- incubator/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ incubator/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Thu
Mar 24 10:57:28 2005
@@ -806,7 +806,6 @@
 				case CodePoint.EXCSAT:
 					parseEXCSAT();
 					writeEXCSATRD();
-					finalizeChain();
 					break;
 				case CodePoint.ACCSEC:
 					int securityCheckCode = parseACCSEC();
@@ -4039,7 +4038,17 @@
 				String paramVal = reader.readStringData(10).trim();  //parameter may be char value
 				if (SanityManager.DEBUG) 
 					trace("ndate parameter value is: \""+paramVal+"\"");
-				ps.setDate(i+1, java.sql.Date.valueOf(paramVal));
+				try {
+					ps.setDate(i+1, java.sql.Date.valueOf(paramVal));
+				} catch (java.lang.IllegalArgumentException e) {
+					// Just use SQLSTATE as message since, if user wants to
+					// retrieve it, the message will be looked up by the
+					// sqlcamessage() proc, which will get the localized
+					// message based on SQLSTATE, and will ignore the
+					// the message we use here...
+					throw new SQLException(SQLState.LANG_DATE_SYNTAX_EXCEPTION,
+						SQLState.LANG_DATE_SYNTAX_EXCEPTION.substring(0,5));
+				}
 				break;
 			}
 			case FdocaConstants.DRDA_TYPE_NTIME:
@@ -4047,20 +4056,37 @@
 				String paramVal = reader.readStringData(8).trim();  //parameter may be char value
 				if (SanityManager.DEBUG) 
 					trace("ntime parameter value is: "+paramVal);
-				ps.setTime(i+1, java.sql.Time.valueOf(paramVal));
+				try {
+					ps.setTime(i+1, java.sql.Time.valueOf(paramVal));
+				} catch (java.lang.IllegalArgumentException e) {
+					throw new SQLException(SQLState.LANG_DATE_SYNTAX_EXCEPTION,
+						SQLState.LANG_DATE_SYNTAX_EXCEPTION.substring(0,5));
+				}
 				break;
 			}
 			case FdocaConstants.DRDA_TYPE_NTIMESTAMP:
 			{
-				// DB2 represents ts with 26 chars, and a slightly different format than Java standard
-				// we do the conversion and pad 3 digits for nano seconds.
+				// JCC represents ts in a slightly different format than Java standard, so
+				// we do the conversion to Java standard here.
 				String paramVal = reader.readStringData(26).trim();  //parameter may be char value
 				if (SanityManager.DEBUG)
 					trace("ntimestamp parameter value is: "+paramVal);
-				String tsString = paramVal.substring(0,10)+" "+paramVal.substring(11,19).replace('.',
':')+paramVal.substring(19)+"000";
-				if (SanityManager.DEBUG)
-					trace("tsString is: "+tsString);
-				ps.setTimestamp(i+1, java.sql.Timestamp.valueOf(tsString));
+				try {
+					String tsString = paramVal.substring(0,10) + " " +
+						paramVal.substring(11,19).replace('.', ':') +
+						paramVal.substring(19);
+					if (SanityManager.DEBUG)
+						trace("tsString is: "+tsString);
+					ps.setTimestamp(i+1, java.sql.Timestamp.valueOf(tsString));
+				} catch (java.lang.IllegalArgumentException e1) {
+				// thrown by Timestamp.valueOf(...) for bad syntax...
+					throw new SQLException(SQLState.LANG_DATE_SYNTAX_EXCEPTION,
+						SQLState.LANG_DATE_SYNTAX_EXCEPTION.substring(0,5));
+				} catch (java.lang.StringIndexOutOfBoundsException e2) {
+				// can be thrown by substring(...) if syntax is invalid...
+					throw new SQLException(SQLState.LANG_DATE_SYNTAX_EXCEPTION,
+						SQLState.LANG_DATE_SYNTAX_EXCEPTION.substring(0,5));
+				}
 				break;
 			}
 			case FdocaConstants.DRDA_TYPE_NCHAR:



Mime
View raw message