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/04/21 03:20:40 UTC
svn commit: r395748 - in /db/derby/code/trunk/java:
client/org/apache/derby/client/am/DateTime.java
client/org/apache/derby/client/net/Request.java
testing/org/apache/derbyTesting/functionTests/suites/encodingTests.runall
Author: kmarsden
Date: Thu Apr 20 18:20:38 2006
New Revision: 395748
URL: http://svn.apache.org/viewcvs?rev=395748&view=rev
Log:
DERBY-1127 client gives SqlException for test callable.java and parameterMapping.java on zOS
Contributed by Sunitha Kambhampati
This patch fixes
-- the calls in DateTime to use correct UTF8 encoding as the server expects.
-- adds these two tests (callable.java, parameterMapping.java) to encodingTests
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/encodingTests.runall
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=395748&r1=395747&r2=395748&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 Thu Apr 20 18:20:38 2006
@@ -23,6 +23,7 @@
import org.apache.derby.shared.common.reference.SQLState;
import java.io.UnsupportedEncodingException;
+import org.apache.derby.client.net.Typdef;
/**
@@ -225,12 +226,20 @@
// ********************************************************
/**
- * The returned character representation is in JDBC date format: <code>yyyy-mm-dd</code> date format in DERBY string
- * representation of a date.
+ * Date is converted to a char representation in JDBC date format: <code>yyyy-mm-dd</code> date format
+ * and then converted to bytes using UTF8 encoding
+ * @param buffer bytes in UTF8 encoding of the date
+ * @param offset write into the buffer from this offset
+ * @param date date value
+ * @return DateTime.dateRepresentationLength. This is the fixed length in
+ * bytes taken to represent the date value
+ * @throws SqlException
+ * @throws UnsupportedEncodingException if UTF8 Encoding is not supported
*/
public static final int dateToDateBytes(byte[] buffer,
int offset,
- java.sql.Date date) throws SqlException {
+ java.sql.Date date)
+ throws SqlException,UnsupportedEncodingException {
int year = date.getYear() + 1900;
if (year > 9999) {
throw new SqlException(null,
@@ -252,19 +261,32 @@
dateChars[7] = '-';
dateChars[8] = (char) (day / 10 + zeroBase);
dateChars[9] = (char) (day % 10 + zeroBase);
- byte[] dateBytes = (new String(dateChars)).getBytes();
+
+ // Network server expects to read the date parameter value bytes with
+ // UTF-8 encoding. Reference - DERBY-1127
+ // see DRDAConnThread.readAndSetParams
+ byte[] dateBytes = (new String(dateChars)).getBytes(Typdef.UTF8ENCODING);
System.arraycopy(dateBytes, 0, buffer, offset, DateTime.dateRepresentationLength);
return DateTime.dateRepresentationLength;
}
/**
- * The returned character representation is in JDBC time escape format: <code>hh:mm:ss</code>, which is the same as
- * JIS time format in DERBY string representation of a time.
+ * java.sql.Time is converted to character representation which is in JDBC time escape
+ * format: <code>hh:mm:ss</code>, which is the same as JIS time format in DERBY string
+ * representation of a time. The char representation is converted to bytes using UTF8
+ * encoding.
+ * @param buffer bytes in UTF8 encoding of the time
+ * @param offset write into the buffer from this offset
+ * @param time java.sql.Time value
+ * @return DateTime.timeRepresentationLength. This is the fixed length in
+ * bytes taken to represent the time value
+ * @throws UnsupportedEncodingException
*/
public static final int timeToTimeBytes(byte[] buffer,
int offset,
- java.sql.Time time) {
+ java.sql.Time time)
+ throws UnsupportedEncodingException {
int hour = time.getHours();
int minute = time.getMinutes();
int second = time.getSeconds();
@@ -279,19 +301,32 @@
timeChars[5] = ':';
timeChars[6] = (char) (second / 10 + zeroBase);
timeChars[7] = (char) (second % 10 + zeroBase);
- byte[] timeBytes = (new String(timeChars)).getBytes();
+
+ // Network server expects to read the time parameter value bytes with
+ // UTF-8 encoding. Reference - DERBY-1127
+ // see DRDAConnThread.readAndSetParams
+ byte[] timeBytes = (new String(timeChars)).getBytes(Typdef.UTF8ENCODING);
System.arraycopy(timeBytes, 0, buffer, offset, DateTime.timeRepresentationLength);
return DateTime.timeRepresentationLength;
}
/**
- * The returned character representation is in DERBY string representation of a timestamp:
- * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+ * java.sql.Timestamp is converted to a character representation which is in DERBY string
+ * representation of a timestamp: <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+ * and then converted to bytes using UTF8 encoding
+ * @param buffer bytes in UTF8 encoding of the timestamp
+ * @param offset write into the buffer from this offset
+ * @param timestamp timestamp value
+ * @return DateTime.timestampRepresentationLength. This is the fixed
+ * length in bytes, taken to represent the timestamp value
+ * @throws SqlException
+ * @throws UnsupportedEncodingException
*/
public static final int timestampToTimestampBytes(byte[] buffer,
int offset,
- java.sql.Timestamp timestamp) throws SqlException {
+ java.sql.Timestamp timestamp)
+ throws SqlException,UnsupportedEncodingException {
int year = timestamp.getYear() + 1900;
if (year > 9999) {
throw new SqlException(null,
@@ -333,8 +368,11 @@
timestampChars[23] = (char) ((microsecond % 1000) / 100 + zeroBase);
timestampChars[24] = (char) ((microsecond % 100) / 10 + zeroBase);
timestampChars[25] = (char) (microsecond % 10 + zeroBase);
-
- byte[] timestampBytes = (new String(timestampChars)).getBytes();
+
+ // Network server expects to read the timestamp parameter value bytes with
+ // UTF-8 encoding. Reference - DERBY-1127
+ // see DRDAConnThread.readAndSetParams
+ byte[] timestampBytes = (new String(timestampChars)).getBytes(Typdef.UTF8ENCODING);
System.arraycopy(timestampBytes, 0, buffer, offset, DateTime.timestampRepresentationLength);
return DateTime.timestampRepresentationLength;
@@ -549,12 +587,21 @@
// *********************************************************
/**
- * The returned character representation is in JDBC date escape format: <code>yyyy-mm-dd</code>, which is the same
- * as JIS date format in DERBY string representation of a date.
+ * java.sql.Timestamp is converted to character representation that is in JDBC date escape
+ * format: <code>yyyy-mm-dd</code>, which is the same as JIS date format in DERBY string representation of a date.
+ * and then converted to bytes using UTF8 encoding.
+ * @param buffer
+ * @param offset write into the buffer from this offset
+ * @param timestamp timestamp value
+ * @return DateTime.dateRepresentationLength. This is the fixed length
+ * in bytes, that is taken to represent the timestamp value as a date.
+ * @throws SqlException
+ * @throws UnsupportedEncodingException
*/
public static final int timestampToDateBytes(byte[] buffer,
int offset,
- java.sql.Timestamp timestamp) throws SqlException {
+ java.sql.Timestamp timestamp)
+ throws SqlException,UnsupportedEncodingException {
int year = timestamp.getYear() + 1900;
if (year > 9999) {
throw new SqlException(null,
@@ -576,19 +623,31 @@
dateChars[7] = '-';
dateChars[8] = (char) (day / 10 + zeroBase);
dateChars[9] = (char) (day % 10 + zeroBase);
- byte[] dateBytes = (new String(dateChars)).getBytes();
+ // Network server expects to read the date parameter value bytes with
+ // UTF-8 encoding. Reference - DERBY-1127
+ // see DRDAConnThread.readAndSetParams
+ byte[] dateBytes = (new String(dateChars)).getBytes(Typdef.UTF8ENCODING);
System.arraycopy(dateBytes, 0, buffer, offset, DateTime.dateRepresentationLength);
return DateTime.dateRepresentationLength;
}
/**
- * The returned character representation is in JDBC time escape format: <code>hh:mm:ss</code>, which is the same as
- * JIS time format in DERBY string representation of a time.
+ * java.sql.Timestamp is converted to character representation in JDBC time escape format:
+ * <code>hh:mm:ss</code>, which is the same as
+ * JIS time format in DERBY string representation of a time. The char representation is
+ * then converted to bytes using UTF8 encoding and written out into the buffer
+ * @param buffer
+ * @param offset write into the buffer from this offset
+ * @param timestamp timestamp value
+ * @return DateTime.timeRepresentationLength. This is the fixed length
+ * in bytes taken to represent the timestamp value as Time.
+ * @throws UnsupportedEncodingException
*/
public static final int timestampToTimeBytes(byte[] buffer,
int offset,
- java.sql.Timestamp timestamp) {
+ java.sql.Timestamp timestamp)
+ throws UnsupportedEncodingException {
int hour = timestamp.getHours();
int minute = timestamp.getMinutes();
int second = timestamp.getSeconds();
@@ -603,19 +662,32 @@
timeChars[5] = ':';
timeChars[6] = (char) (second / 10 + zeroBase);
timeChars[7] = (char) (second % 10 + zeroBase);
- byte[] timeBytes = (new String(timeChars)).getBytes();
+
+ // Network server expects to read the time parameter value bytes with
+ // UTF-8 encoding. Reference - DERBY-1127
+ // see DRDAConnThread.readAndSetParams
+ byte[] timeBytes = (new String(timeChars)).getBytes(Typdef.UTF8ENCODING);
System.arraycopy(timeBytes, 0, buffer, offset, DateTime.timeRepresentationLength);
return DateTime.timeRepresentationLength;
}
/**
- * The returned character representation is in DERBY string representation of a timestamp:
- * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+ * java.sql.Date is converted to character representation that is in DERBY string
+ * representation of a timestamp:<code>yyyy-mm-dd-hh.mm.ss.ffffff</code> and then
+ * converted to bytes using UTF8 encoding and written out to the buffer
+ * @param buffer
+ * @param offset offset in buffer to start writing to
+ * @param date date value
+ * @return DateTime.timestampRepresentationLength. This is the fixed length
+ * in bytes, taken to represent the timestamp value.
+ * @throws SqlException
+ * @throws UnsupportedEncodingException
*/
public static final int dateToTimestampBytes(byte[] buffer,
int offset,
- java.sql.Date date) throws SqlException {
+ java.sql.Date date)
+ throws SqlException, UnsupportedEncodingException {
int year = date.getYear() + 1900;
if (year > 9999) {
throw new SqlException(null,
@@ -653,20 +725,30 @@
timestampChars[23] = '0';
timestampChars[24] = '0';
timestampChars[25] = '0';
-
- byte[] timestampBytes = (new String(timestampChars)).getBytes();
+
+ // Network server expects to read the timestamp parameter value bytes with
+ // UTF-8 encoding. Reference - DERBY-1127
+ // see DRDAConnThread.readAndSetParams
+ byte[] timestampBytes = (new String(timestampChars)).getBytes(Typdef.UTF8ENCODING);
System.arraycopy(timestampBytes, 0, buffer, offset, DateTime.timestampRepresentationLength);
return DateTime.timestampRepresentationLength;
}
/**
- * The returned character representation is in DERBY string representation of a timestamp:
- * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code>.
+ * java.sql.Time is converted to a character representation that is in DERBY string representation of a timestamp:
+ * <code>yyyy-mm-dd-hh.mm.ss.ffffff</code> and converted to bytes using UTF8 encoding
+ * @param buffer
+ * @param offset offset in buffer to start writing to
+ * @param time time value
+ * @return DateTime.timestampRepresentationLength which is the fixed length
+ * taken up by the conversion of time to timestamp in bytes
+ * @throws UnsupportedEncodingException
*/
public static final int timeToTimestampBytes(byte[] buffer,
int offset,
- java.sql.Time time) {
+ java.sql.Time time)
+ throws UnsupportedEncodingException {
int hour = time.getHours();
int minute = time.getMinutes();
int second = time.getSeconds();
@@ -700,7 +782,10 @@
timestampChars[24] = '0';
timestampChars[25] = '0';
- byte[] timestampBytes = (new String(timestampChars)).getBytes();
+ // Network server expects to read the timestamp parameter value bytes with
+ // UTF-8 encoding. Reference - DERBY-1127
+ // see DRDAConnThread.readAndSetParams for TIMESTAMP
+ byte[] timestampBytes = (new String(timestampChars)).getBytes(Typdef.UTF8ENCODING);
System.arraycopy(timestampBytes, 0, buffer, offset, DateTime.timestampRepresentationLength);
return DateTime.timestampRepresentationLength;
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java?rev=395748&r1=395747&r2=395748&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java Thu Apr 20 18:20:38 2006
@@ -21,8 +21,12 @@
import org.apache.derby.client.am.DisconnectException;
import org.apache.derby.client.am.EncryptionManager;
+import org.apache.derby.client.am.MessageId;
import org.apache.derby.client.am.SqlException;
import org.apache.derby.client.am.Utils;
+import org.apache.derby.shared.common.reference.SQLState;
+
+import java.io.UnsupportedEncodingException;
public class Request {
@@ -1523,21 +1527,40 @@
}
final void writeDate(java.sql.Date date) throws SqlException {
- ensureLength(offset_ + 10);
- org.apache.derby.client.am.DateTime.dateToDateBytes(bytes_, offset_, date);
- offset_ += 10;
+ try
+ {
+ ensureLength(offset_ + 10);
+ org.apache.derby.client.am.DateTime.dateToDateBytes(bytes_, offset_, date);
+ offset_ += 10;
+ } catch (java.io.UnsupportedEncodingException e) {
+ throw new SqlException(netAgent_.logWriter_,
+ new MessageId(SQLState.UNSUPPORTED_ENCODING),
+ "java.sql.Date", "DATE", e);
+ }
}
final void writeTime(java.sql.Time time) throws SqlException {
- ensureLength(offset_ + 8);
- org.apache.derby.client.am.DateTime.timeToTimeBytes(bytes_, offset_, time);
- offset_ += 8;
+ try{
+ ensureLength(offset_ + 8);
+ org.apache.derby.client.am.DateTime.timeToTimeBytes(bytes_, offset_, time);
+ offset_ += 8;
+ } catch(UnsupportedEncodingException e) {
+ throw new SqlException(netAgent_.logWriter_,
+ new MessageId(SQLState.UNSUPPORTED_ENCODING),
+ "java.sql.Time", "TIME", e);
+ }
}
final void writeTimestamp(java.sql.Timestamp timestamp) throws SqlException {
- ensureLength(offset_ + 26);
- org.apache.derby.client.am.DateTime.timestampToTimestampBytes(bytes_, offset_, timestamp);
- offset_ += 26;
+ try{
+ ensureLength(offset_ + 26);
+ org.apache.derby.client.am.DateTime.timestampToTimestampBytes(bytes_, offset_, timestamp);
+ offset_ += 26;
+ }catch(UnsupportedEncodingException e) {
+ throw new SqlException(netAgent_.logWriter_,
+ new MessageId(SQLState.UNSUPPORTED_ENCODING),
+ "java.sql.Timestamp", "TIMESTAMP", e);
+ }
}
// insert a java boolean into the buffer. the boolean is written
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/encodingTests.runall
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/encodingTests.runall?rev=395748&r1=395747&r2=395748&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/encodingTests.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/encodingTests.runall Thu Apr 20 18:20:38 2006
@@ -1,2 +1,4 @@
jdbcapi/lobStreams.java
derbynet/TestEnc.java
+derbynet/callable.java
+jdbcapi/parameterMapping.java