db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r374148 - in /db/derby/code/branches/10.1/java/client/org/apache/derby/client/am: Cursor.java DateTime.java
Date Wed, 01 Feb 2006 19:28:06 GMT
Author: kmarsden
Date: Wed Feb  1 11:28:02 2006
New Revision: 374148

URL: http://svn.apache.org/viewcvs?rev=374148&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
(note repro won't run with jdk 1.4.2). Also verified the fix on zOS 



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

Modified: db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/Cursor.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/Cursor.java?rev=374148&r1=374147&r2=374148&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/Cursor.java (original)
+++ db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/Cursor.java Wed Feb
 1 11:28:02 2006
@@ -20,6 +20,9 @@
 
 package org.apache.derby.client.am;
 
+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
 // Direct byte-level converters are called directly by this class, cross converters are deferred
to the CrossConverters class.
@@ -397,71 +400,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/branches/10.1/java/client/org/apache/derby/client/am/DateTime.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/DateTime.java?rev=374148&r1=374147&r2=374148&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/DateTime.java (original)
+++ db/derby/code/branches/10.1/java/client/org/apache/derby/client/am/DateTime.java Wed Feb
 1 11:28:02 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 =



Mime
View raw message