db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r329372 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing/org/apache/derbyTesting/functionTe...
Date Sat, 29 Oct 2005 04:57:28 GMT
Author: tmnk
Date: Fri Oct 28 21:57:12 2005
New Revision: 329372

URL: http://svn.apache.org/viewcvs?rev=329372&view=rev
Log:
- DERBY-525_3 getAsciiStreamshould replace non-ASCII characters with 0x3f, '?' to match embedded
- Patch by Tomohito Nakayama (tomonaka@basil.ocn.ne.jp)

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/AsciiStream.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/AsciiStream.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/AsciiStream.java?rev=329372&r1=329371&r2=329372&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/AsciiStream.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/AsciiStream.java Fri Oct 28
21:57:12 2005
@@ -19,11 +19,17 @@
 */
 package org.apache.derby.client.am;
 
+import java.io.StringReader;
+
 public class AsciiStream extends java.io.InputStream {
     private java.io.Reader reader_;
     private String materializedString_;
     private int charsRead_ = 0;
-
+	
+	public AsciiStream(String materializedString){
+		this(materializedString,new StringReader(materializedString));
+	}
+	
     public AsciiStream(String materializedString, java.io.Reader reader) {
         reader_ = reader;
         materializedString_ = materializedString;
@@ -34,7 +40,11 @@
         ++charsRead_;
         if (oneChar != -1) // if not eos
         {
-            return 0x00ff & oneChar;
+		if(oneChar <= 0x00ff)
+			return oneChar;
+		else
+			return 0x003f;
+		
         } else {
             return -1; // end of stream
         }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java?rev=329372&r1=329371&r2=329372&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java Fri Oct 28 21:57:12
2005
@@ -939,9 +939,8 @@
         java.io.InputStream result = null;
         if (wasNonNullSensitiveUpdate(column)) {
 		
-		result = new java.io.ByteArrayInputStream
-			(convertToAsciiByteArray((String) agent_.crossConverters_.setObject(java.sql.Types.CHAR,
-											    updatedColumns_[column - 1])));
+		result = new AsciiStream((String) agent_.crossConverters_.setObject(java.sql.Types.CHAR,
+										    updatedColumns_[column - 1]));
         } else {
             result = isNull(column) ? null : cursor_.getAsciiStream(column);
         }
@@ -3962,25 +3961,6 @@
             }
         }
     }
-
-	
-	private static byte[] convertToAsciiByteArray(String original){
-
-		byte[] result = new byte[original.length()];
-
-		for(int i = 0;
-		    i < original.length();
-		    i ++){
-			
-			if(original.charAt(i) <= 0x00ff)
-				result[i] = (byte) original.charAt(i);
-			else
-				result[i] = 0x003f;
-		}
-
-		return result;
-
-	}
 	
 	
 	private CloseFilterInputStream createCloseFilterInputStream(java.io.InputStream is) throws
SqlException {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out?rev=329372&r1=329371&r2=329372&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/resultsetStream.out
Fri Oct 28 21:57:12 2005
@@ -11,4 +11,7 @@
 number of reads=56
 EXPECTED SQLSTATE(null): End of Stream prematurely reached while reading InputStream, parameter
#2.  Remaining data has been padded with 0x0.
 EXPECTED SQLSTATE(null): The specified size of the InputStream, parameter #2, is less than
the actual InputStream length
+Test of getAsciiStream
+U+0041U+0042U+0043U+0044U+0045U+0046U+0047U+00c0U+00c1U+00c2U+00c3U+00c4U+00c5U+00ffU+003fU+003fU+003fU+003fU+003fU+003f
+U+0041U+0042U+0043U+0044U+0045U+0046U+0047U+00c0U+00c1U+00c2U+00c3U+00c4U+00c5U+00ffU+0100U+3042U+3044U+3046U+3048U+304a
 Test resultsetStream finished

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out?rev=329372&r1=329371&r2=329372&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
Fri Oct 28 21:57:12 2005
@@ -13,4 +13,7 @@
 EXPECTED SQLSTATE(XJ001): Java exception: 'Input stream did not have exact amount of data
as the requested length.: java.io.IOException'.
 EXPECTED SQLSTATE(XSDA4): An unexpected exception was thrown
 EXPECTED SQLSTATE(XJ001): Java exception: 'Input stream did not have exact amount of data
as the requested length.: java.io.IOException'.
+Test of getAsciiStream
+U+0041U+0042U+0043U+0044U+0045U+0046U+0047U+00c0U+00c1U+00c2U+00c3U+00c4U+00c5U+00ffU+003fU+003fU+003fU+003fU+003fU+003f
+U+0041U+0042U+0043U+0044U+0045U+0046U+0047U+00c0U+00c1U+00c2U+00c3U+00c4U+00c5U+00ffU+0100U+3042U+3044U+3046U+3048U+304a
 Test resultsetStream finished

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java?rev=329372&r1=329371&r2=329372&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/resultsetStream.java
Fri Oct 28 21:57:12 2005
@@ -38,6 +38,8 @@
 import java.io.FileInputStream;
 import java.io.BufferedInputStream;
 import java.util.zip.CRC32;
+import java.io.Reader;
+import java.io.StringReader;
 
 /**
  * Test of JDBC result set Stream calls.
@@ -281,6 +283,9 @@
 			ppw.close();
 			rs.close();
 			stmt.close();
+			
+			TestOfGetAsciiStream.executeTestOfGetAsciiStream(con);
+
 			con.close();
 
 		}
@@ -302,4 +307,166 @@
 			se = se.getNextException();
 		}
 	}
+	
+	
+	static class TestOfGetAsciiStream {
+		
+		final static String TEST_STRING_DATA = 
+			"ABCDEFG" + 
+			"\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5" + 
+			"\u00ff\u0100" + 
+			"\u3042\u3044\u3046\u3048\u304a";
+				
+		
+		static private void executeTestOfGetAsciiStream(Connection conn) throws SQLException {
+			
+			System.out.println("Test of getAsciiStream");
+			createTestTable(conn);
+			executeTestRun(conn);
+
+		}
+		
+
+		static private void createTestTable(Connection conn) throws SQLException {
+
+			PreparedStatement st = null;
+			
+			try{
+				st = conn.prepareStatement("create table t3(text_data clob)");
+				st.executeUpdate();
+				
+			}finally{
+				if(st != null)
+					st.close();
+				
+			}
+			
+		}
+		
+
+		static private void executeTestRun(Connection conn) throws SQLException {
+			
+			insertTestData(conn);
+			printTestData(conn);
+			
+		}
+
+
+		static private void insertTestData(Connection conn) throws SQLException {
+			
+			PreparedStatement st = null;
+			
+			try{
+				
+				st = conn.prepareStatement("insert into t3(text_data) values(?)");
+				st.setCharacterStream(1,
+						      new StringReader(TEST_STRING_DATA),
+						      TEST_STRING_DATA.length());
+				st.executeUpdate();
+				
+			}finally{
+				if(st != null)
+					st.close();
+				
+			}
+
+		}
+
+
+		static private void printTestData(Connection conn) throws SQLException {
+			
+			PreparedStatement st = null;
+			ResultSet rs = null;
+			
+			try{
+				st = conn.prepareStatement("select text_data from t3");
+				rs = st.executeQuery();
+				
+				while(rs.next()){
+					printTestDataInARowViaStream(rs);
+					printTestDataInARowViaReader(rs);
+				}
+				
+			}catch(IOException e){
+				System.out.println("FAIL -- unexpected IOException: " + e.toString());
+				e.printStackTrace();
+				
+			}finally{
+				if(rs != null){
+					rs.close();
+				}
+
+				if(st != null){
+					st.close();
+				}
+				
+			}
+		}
+		
+		
+		static private void printTestDataInARowViaStream(ResultSet rs) throws SQLException, 
+										      IOException{
+			
+			InputStream is = null;
+
+			try{
+				is = rs.getAsciiStream(1);
+			
+				for(int c = is.read();
+				    c > -1;
+				    c = is.read()){
+					
+					System.out.print(getCharacterCodeString((char) c));
+				}
+				
+				System.out.println();
+				
+			}finally{
+				if(is != null)
+					is.close();
+			}
+				
+		}
+
+
+		static private void printTestDataInARowViaReader(ResultSet rs) throws SQLException, 
+										      IOException{
+
+			Reader reader = null;
+			
+			try{
+				reader = rs.getCharacterStream(1);
+
+				for(int c = reader.read();
+				    c > -1;
+				    c = reader.read()){
+					
+					System.out.print(getCharacterCodeString((char) c));
+
+				}
+			
+				System.out.println();
+				
+			}finally{
+				if(reader != null){
+					reader.close();
+				}
+			}
+			
+		}
+		
+		
+		private static String getCharacterCodeString(char c){
+
+			String hexString = Integer.toHexString((int) c);
+			
+			while(hexString.length() < 4){
+				hexString = "0" + hexString;
+			}
+			
+			return "U+" + hexString;
+		}
+		
+	}
+
 }



Mime
View raw message