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 km...@apache.org on 2006/02/02 06:41:15 UTC

svn commit: r374271 - in /db/derby/code/trunk/java/client/org/apache/derby/client/am: Cursor.java DateTime.java

Author: kmarsden
Date: Wed Feb  1 21:41:12 2006
New Revision: 374271

URL: http://svn.apache.org/viewcvs?rev=374271&view=rev
Log:
DERBY-877 zOS - with DerbyClient getDate(#) fails with IllegalArgumentException - unsupported date format - resultset.java

The patch fixes issues with getString, getTimeStamp, getDate and getTime on TIMESTAMP, DATE and TIME columns when the client JVM encoding does not match the server encoding for the characters being evaluated in DateTime.java methods

- Changes the following methods in DateTime.java to take encoding parameter and create string based on encoding.
dateBytesToDate, timeBytesToTime, timeBytesToTimeStamp, dateBytesToTimeStamp, timestampBytesToDate, timestampBytesToTime

- Changes calling code to pass column encoding and throw SQLExceptions for UnsupportedEncoding exceptions if thrown from the methods above.

Tests: derbyall passed as did the repro attached to this issue on Windows with Sun JDK 1.5 . Verified on zOS


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java?rev=374271&r1=374270&r2=374271&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java Wed Feb  1 21:41:12 2006
@@ -19,10 +19,10 @@
 */
 
 package org.apache.derby.client.am;
-
 import org.apache.derby.iapi.reference.JDBC30Translation;
 
 import java.sql.SQLException;
+import java.io.UnsupportedEncodingException;
 
 // When we calculate column offsets make sure we calculate the correct offsets for double byte charactr5er data
 // length from server is number of chars, not bytes
@@ -410,71 +410,111 @@
 
     // Build a JDBC Date object from the DERBY ISO DATE field.
     private final java.sql.Date getDATE(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.dateBytesToDate(dataBuffer_,
+        try {
+            return org.apache.derby.client.am.DateTime.dateBytesToDate(dataBuffer_,
                 columnDataPosition_[column - 1],
-                recyclableDate_);
+                recyclableDate_, 
+                charsetName_[column - 1]);
+        }catch (UnsupportedEncodingException e) {
+             throw new SqlException(agent_.logWriter_, e, 
+                    "Encoding is unsupported for conversion to DATE");
+        }
+
+        
     }
 
     // Build a JDBC Time object from the DERBY ISO TIME field.
     private final java.sql.Time getTIME(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.timeBytesToTime(dataBuffer_,
-                columnDataPosition_[column - 1],
-                recyclableTime_);
+        try {
+            return org.apache.derby.client.am.DateTime.timeBytesToTime(dataBuffer_,
+                    columnDataPosition_[column - 1],
+                    recyclableTime_,
+                    charsetName_[column - 1]);
+        } catch (UnsupportedEncodingException e) {
+            throw new SqlException(agent_.logWriter_, e, 
+                    "Encoding is unsupported for conversion to TIME");
+        }
     }
 
     // Build a JDBC Timestamp object from the DERBY ISO TIMESTAMP field.
     private final java.sql.Timestamp getTIMESTAMP(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.timestampBytesToTimestamp(dataBuffer_,
+
+        try {
+        return org.apache.derby.client.am.DateTime.timestampBytesToTimestamp(
+                dataBuffer_,
                 columnDataPosition_[column - 1],
-                recyclableTimestamp_);
+                recyclableTimestamp_, 
+                charsetName_[column - 1]);
+    } catch (java.io.UnsupportedEncodingException e) {
+        throw new SqlException(agent_.logWriter_, e, 
+                "Encoding is unsupported for conversion to TIMESTAMP");
+    }
     }
 
     // Build a JDBC Timestamp object from the DERBY ISO DATE field.
     private final java.sql.Timestamp getTimestampFromDATE(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.dateBytesToTimestamp(dataBuffer_,
-                columnDataPosition_[column - 1],
-                recyclableTimestamp_);
+        try {
+            return org.apache.derby.client.am.DateTime.dateBytesToTimestamp(dataBuffer_,
+                    columnDataPosition_[column - 1],
+                    recyclableTimestamp_, 
+                    charsetName_[column -1]);
+        } catch (UnsupportedEncodingException e) {
+              throw new SqlException(agent_.logWriter_, e, 
+                      "Encoding is unsupported for conversion to TIMESTAMP");            
+        }
     }
 
     // Build a JDBC Timestamp object from the DERBY ISO TIME field.
     private final java.sql.Timestamp getTimestampFromTIME(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.timeBytesToTimestamp(dataBuffer_,
-                columnDataPosition_[column - 1],
-                recyclableTimestamp_);
+        try {
+            return org.apache.derby.client.am.DateTime.timeBytesToTimestamp(dataBuffer_,
+                    columnDataPosition_[column - 1],
+                    recyclableTimestamp_,
+                    charsetName_[column -1]);
+        } catch (UnsupportedEncodingException e) {
+            throw new SqlException(agent_.logWriter_, e, 
+                    "Encoding is unsupported for conversion to TIMESTAMP");
+        }
     }
 
     // Build a JDBC Date object from the DERBY ISO TIMESTAMP field.
     private final java.sql.Date getDateFromTIMESTAMP(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.timestampBytesToDate(dataBuffer_,
-                columnDataPosition_[column - 1],
-                recyclableDate_);
+        try {
+            return org.apache.derby.client.am.DateTime.timestampBytesToDate(dataBuffer_,
+                    columnDataPosition_[column - 1],
+                    recyclableDate_,
+                    charsetName_[column -1]);
+        } catch (UnsupportedEncodingException e) {
+             throw new SqlException(agent_.logWriter_, e, 
+                     "Encoding is unsupported for conversion to DATE");
+        }
     }
 
     // Build a JDBC Time object from the DERBY ISO TIMESTAMP field.
     private final java.sql.Time getTimeFromTIMESTAMP(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.timestampBytesToTime(dataBuffer_,
-                columnDataPosition_[column - 1],
-                recyclableTime_);
+        try {
+            return org.apache.derby.client.am.DateTime.timestampBytesToTime(dataBuffer_,
+                    columnDataPosition_[column - 1],
+                    recyclableTime_,
+                    charsetName_[column -1]);
+        } catch (UnsupportedEncodingException e) {
+             throw new SqlException(agent_.logWriter_, e, 
+                     "Encoding is unsupported for conversion to TIME");
+        }
     }
 
     private final String getStringFromDATE(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.dateBytesToDate(dataBuffer_,
-                columnDataPosition_[column - 1],
-                recyclableDate_).toString();
+        return getDATE(column).toString();
     }
 
     // Build a string object from the DERBY byte TIME representation.
     private final String getStringFromTIME(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.timeBytesToTime(dataBuffer_,
-                columnDataPosition_[column - 1],
-                recyclableTime_).toString();
+        return getTIME(column).toString();
     }
 
     // Build a string object from the DERBY byte TIMESTAMP representation.
     private final String getStringFromTIMESTAMP(int column) throws SqlException {
-        return org.apache.derby.client.am.DateTime.timestampBytesToTimestamp(dataBuffer_,
-                columnDataPosition_[column - 1],
-                recyclableTimestamp_).toString();
+        return getTIMESTAMP(column).toString();
     }
 
     // Extract bytes from a database java.sql.Types.BINARY field.

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java?rev=374271&r1=374270&r2=374271&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java Wed Feb  1 21:41:12 2006
@@ -19,6 +19,8 @@
 */
 package org.apache.derby.client.am;
 
+import java.io.UnsupportedEncodingException;
+
 
 /**
  * High performance converters from date/time byte encodings to JDBC Date, Time and Timestamp objects.
@@ -44,15 +46,25 @@
     // *********************************************************
 
     /**
-     * Expected character representation is DERBY string representation of a date, which is in one of the following
-     * format.
+     * Expected character representation is DERBY string representation of a date, 
+     * which is in JIS format: <code> yyyy-mm-dd </code>
+     * 
+     * @param buffer    
+     * @param offset    
+     * @param recyclableDate
+     * @param encoding            encoding of buffer data
+     * @return
+     * @throws UnsupportedEncodingException
      */
     public static final java.sql.Date dateBytesToDate(byte[] buffer,
                                                       int offset,
-                                                      java.sql.Date recyclableDate) {
+                                                      java.sql.Date recyclableDate, 
+                                                      String encoding) 
+    throws UnsupportedEncodingException {
         int year, month, day;
 
-        String date = new String(buffer, offset, DateTime.dateRepresentationLength);
+        String date = new String(buffer, offset, 
+                DateTime.dateRepresentationLength,encoding);
         int yearIndx, monthIndx, dayIndx;
         if (date.charAt(4) == '-') {
             // JIS format: yyyy-mm-dd.
@@ -90,16 +102,26 @@
         }
     }
 
+    
     /**
-     * Expected character representation is DERBY string representation of a time, which is in one of the following
-     * format: hh.mm.ss.
+     * Expected character representation is DERBY string representation of time,
+     * which is in the format: <code> hh.mm.ss </code>
+     * @param buffer
+     * @param offset
+     * @param recyclableTime
+     * @param encoding           encoding of buffer
+     * @return
+     * @throws UnsupportedEncodingException
      */
     public static final java.sql.Time timeBytesToTime(byte[] buffer,
                                                       int offset,
-                                                      java.sql.Time recyclableTime) {
+                                                      java.sql.Time recyclableTime,
+                                                      String encoding) 
+    throws UnsupportedEncodingException {
         int hour, minute, second;
 
-        String time = new String(buffer, offset, DateTime.timeRepresentationLength);
+        String time = new String(buffer, offset, 
+                DateTime.timeRepresentationLength, encoding);
         int zeroBase = ((int) '0');
 
         // compute hour.
@@ -128,13 +150,24 @@
     /**
      * Expected character representation is DERBY string representation of a timestamp:
      * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+     * 
+     * @param buffer
+     * @param offset
+     * @param recyclableTimestamp
+     * @param encoding                encoding of buffer
+     * @return
+     * @throws UnsupportedEncodingException
      */
     public static final java.sql.Timestamp timestampBytesToTimestamp(byte[] buffer,
                                                                      int offset,
-                                                                     java.sql.Timestamp recyclableTimestamp) {
+                                                                     java.sql.Timestamp recyclableTimestamp, 
+                                                                     String encoding) 
+    throws UnsupportedEncodingException
+    {
         int year, month, day, hour, minute, second, fraction;
-
-        String timestamp = new String(buffer, offset, DateTime.timestampRepresentationLength);
+        String timestamp = new String(buffer, offset, 
+                DateTime.timestampRepresentationLength,encoding);
+       
         int zeroBase = ((int) '0');
 
         year =
@@ -301,16 +334,27 @@
     // ******* CROSS output converters (byte[] -> class) *******
     // *********************************************************
 
+    
     /**
-     * Expected character representation is DERBY string representation of a date, which is in one of the following
-     * format.
+     * Expected character representation is DERBY string representation of a date
+     * which is in JIS format: <code> yyyy-mm-dd </code>
+     * 
+     * @param buffer
+     * @param offset
+     * @param recyclableTimestamp
+     * @param encoding                encoding of buffer
+     * @return
+     * @throws UnsupportedEncodingException
      */
     public static final java.sql.Timestamp dateBytesToTimestamp(byte[] buffer,
                                                                 int offset,
-                                                                java.sql.Timestamp recyclableTimestamp) {
+                                                                java.sql.Timestamp recyclableTimestamp,
+                                                                String encoding) 
+    throws UnsupportedEncodingException {
         int year, month, day;
 
-        String date = new String(buffer, offset, DateTime.dateRepresentationLength);
+        String date = new String(buffer, offset, DateTime.dateRepresentationLength,
+                encoding);
         int yearIndx, monthIndx, dayIndx;
 
         yearIndx = 0;
@@ -348,16 +392,28 @@
         }
     }
 
+    
     /**
-     * Expected character representation is DERBY string representation of a time, which is in one of the following
-     * format.
+     *  Expected character representation is DERBY string representation of time
+     * which is in the format: <code> hh.mm.ss </code>
+     * 
+     * @param buffer
+     * @param offset
+     * @param recyclableTimestamp
+     * @param encoding                 encoding of buffer
+     * @return  
+     * @throws UnsupportedEncodingException
+     * 
      */
     public static final java.sql.Timestamp timeBytesToTimestamp(byte[] buffer,
                                                                 int offset,
-                                                                java.sql.Timestamp recyclableTimestamp) {
+                                                                java.sql.Timestamp recyclableTimestamp, 
+                                                                String encoding)
+    throws UnsupportedEncodingException {
         int hour, minute, second;
 
-        String time = new String(buffer, offset, DateTime.timeRepresentationLength);
+        String time = new String(buffer, offset, 
+                DateTime.timeRepresentationLength, encoding);
         int zeroBase = ((int) '0');
 
         // compute hour.
@@ -386,17 +442,29 @@
             return recyclableTimestamp;
         }
     }
-
+    
+    
     /**
      * Expected character representation is DERBY string representation of a timestamp:
      * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+     * 
+     * @param buffer
+     * @param offset
+     * @param recyclableDate
+     * @param encoding             encoding of buffer
+     * @return
+     * @throws UnsupportedEncodingException
      */
     public static final java.sql.Date timestampBytesToDate(byte[] buffer,
                                                            int offset,
-                                                           java.sql.Date recyclableDate) {
+                                                           java.sql.Date recyclableDate, 
+                                                           String encoding) 
+    throws UnsupportedEncodingException 
+     {
         int year, month, day;
 
-        String timestamp = new String(buffer, offset, DateTime.timestampRepresentationLength);
+        String timestamp = new String(buffer, offset, 
+                DateTime.timestampRepresentationLength, encoding);
         int zeroBase = ((int) '0');
 
         year =
@@ -423,16 +491,27 @@
         }
     }
 
+   
     /**
      * Expected character representation is DERBY string representation of a timestamp:
      * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+     * 
+     * @param buffer
+     * @param offset
+     * @param recyclableTime
+     * @param encoding            encoding of buffer
+     * @return
+     * @throws UnsupportedEncodingException
      */
     public static final java.sql.Time timestampBytesToTime(byte[] buffer,
                                                            int offset,
-                                                           java.sql.Time recyclableTime) {
+                                                           java.sql.Time recyclableTime, 
+                                                           String encoding) 
+    throws  UnsupportedEncodingException {
         int hour, minute, second;
 
-        String timestamp = new String(buffer, offset, DateTime.timestampRepresentationLength);
+        String timestamp = new String(buffer, offset, 
+                DateTime.timestampRepresentationLength, encoding);
         int zeroBase = ((int) '0');
 
         hour =