db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r406120 - in /db/derby/code/trunk/java/client/org/apache/derby/client: am/Sqlca.java net/NetConnectionReply.java net/NetCursor.java net/NetSqlca.java
Date Sat, 13 May 2006 15:21:10 GMT
Author: kmarsden
Date: Sat May 13 08:21:08 2006
New Revision: 406120

URL: http://svn.apache.org/viewcvs?rev=406120&view=rev
Log:
DERBY-900 -  Remove use of String(byte[]) and String(byte[], int, int) constructors in network
client leading to non-portable behaviour

Decided earlier to break up the derby900.p2.diff.txt, so I am attaching now a patch with the
cleanup changes separately in derby900_p2_cleanup.diff.txt. Changes are:

-- remove unnecessary conversion from sqlstate string to bytes and back to string , in parseSQLDCGRP(Sqlca[]
rowsetSqlca, int lastRow) in NetConnectionReply.
This has been done by adding a constructor in NetSqlca to take in the sqlstate as string.
-- cleanup method getSqlState() in Sqlca.
-- cleanup of ccsid_ in Sqlca as it is not used.

Please note, the parseSQLDCGRP method in the diff shows more changes because of change in
indentation because of removal of the try block.

-- ran derbynetclientmats on ibm142/linux OK.

Contributed by Sunitha Kambhampati



Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java?rev=406120&r1=406119&r2=406120&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java Sat May 13 08:21:08
2006
@@ -42,9 +42,7 @@
     protected byte[] sqlErrmcBytes_;
     protected byte[] sqlErrpBytes_;
     protected byte[] sqlWarnBytes_;
-    protected byte[] sqlStateBytes_;
-
-    protected int ccsid_;
+    
     protected int sqlErrmcCcsid_;
     protected boolean containsSqlcax_ = true;
     protected long rowsetRowCount_;
@@ -167,23 +165,7 @@
     }
 
     synchronized public String getSqlState() {
-        if (sqlState_ != null) {
-            return sqlState_;
-        }
-
-        if (sqlStateBytes_ == null) {
-            return null;
-        }
-
-        try {
-            sqlState_ = bytes2String(sqlStateBytes_,
-                    0,
-                    sqlStateBytes_.length);
-            return sqlState_;
-        } catch (java.io.UnsupportedEncodingException e) {
-            // leave sqlState as null.
-            return null;
-        }
+        return sqlState_;
     }
 
     // Gets the formatted message, can throw an exception.
@@ -373,7 +355,7 @@
         }
     }
 
-    private String bytes2String(byte[] bytes, int offset, int length)
+    protected String bytes2String(byte[] bytes, int offset, int length)
             throws java.io.UnsupportedEncodingException {
         // Network server uses utf8 encoding
         return new String(bytes, offset, length, Typdef.UTF8ENCODING);
@@ -400,14 +382,12 @@
 
     public void resetRowsetSqlca(org.apache.derby.client.am.Connection connection,
                                  int sqlCode,
-                                 byte[] sqlStateBytes,
-                                 byte[] sqlErrpBytes,
-                                 int ccsid) {
+                                 String sqlState,
+                                 byte[] sqlErrpBytes) {
         connection_ = connection;
         sqlCode_ = sqlCode;
-        sqlStateBytes_ = sqlStateBytes;
+        sqlState_ = sqlState;
         sqlErrpBytes_ = sqlErrpBytes;
-        ccsid_ = ccsid;
     }
 
     public void setRowsetRowCount(long rowCount) {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java?rev=406120&r1=406119&r2=406120&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java Sat
May 13 08:21:08 2006
@@ -2580,12 +2580,19 @@
         int sqlcode = readFastInt();
         byte[] sqlstate = readFastBytes(5);
         byte[] sqlerrproc = readFastBytes(8);
-        NetSqlca netSqlca = new NetSqlca(netAgent_.netConnection_,
-                sqlcode,
-                sqlstate,
-                sqlerrproc,
-                netAgent_.targetTypdef_.getCcsidSbc());
-
+        NetSqlca netSqlca = null;
+        
+        try
+        {
+            netSqlca = new NetSqlca(netAgent_.netConnection_,
+                    sqlcode,
+                    sqlstate,
+                    sqlerrproc);
+        }
+        catch(SqlException sqle)
+        {
+            throw new DisconnectException(netAgent_,sqle);
+        }
         parseSQLCAXGRP(netSqlca);
 
         if (netAgent_.targetSqlam_ >= NetConfiguration.MGRLVL_7) {
@@ -3108,37 +3115,27 @@
         int sqldcLinen = readFastInt(); // LINE_NUMBER
         int sqldcRown = (int) readFastLong(); // ROW_NUMBER
 
-        try
-        {
-            // save +20237 in the 0th entry of the rowsetSqlca's.
-            // this info is going to be used when a subsequent fetch prior is issued, and
if already
-            // received a +20237 then we've gone beyond the first row and there is no need
to
-            // flow another fetch to the server.
-            if (sqldcCode == 20237) {
-                rowsetSqlca[0] = new NetSqlca(netAgent_.netConnection_,
+        // save +20237 in the 0th entry of the rowsetSqlca's.
+        // this info is going to be used when a subsequent fetch prior is issued, and if
already
+        // received a +20237 then we've gone beyond the first row and there is no need to
+        // flow another fetch to the server.
+        if (sqldcCode == 20237) {
+            rowsetSqlca[0] = new NetSqlca(netAgent_.netConnection_,
+                    sqldcCode,
+                    sqldcState,
+                    null);
+        } else {
+            if (rowsetSqlca[sqldcRown] != null) {
+                rowsetSqlca[sqldcRown].resetRowsetSqlca(netAgent_.netConnection_,
                         sqldcCode,
-                        sqldcState.getBytes(Typdef.UTF8ENCODING),
-                        null,
-                        netAgent_.targetTypdef_.getCcsidSbc());
+                        sqldcState,
+                        null);
             } else {
-                if (rowsetSqlca[sqldcRown] != null) {
-                    rowsetSqlca[sqldcRown].resetRowsetSqlca(netAgent_.netConnection_,
-                            sqldcCode,
-                            sqldcState.getBytes(Typdef.UTF8ENCODING),
-                            null,
-                            netAgent_.targetTypdef_.getCcsidSbc());
-                } else {
-                    rowsetSqlca[sqldcRown] = new NetSqlca(netAgent_.netConnection_,
-                            sqldcCode,
-                            sqldcState.getBytes(Typdef.UTF8ENCODING),
-                            null,
-                            netAgent_.targetTypdef_.getCcsidSbc());
-                }
+                rowsetSqlca[sqldcRown] = new NetSqlca(netAgent_.netConnection_,
+                        sqldcCode,
+                        sqldcState,
+                        null);
             }
-        }
-        catch(UnsupportedEncodingException uee)
-        {
-            throw new DisconnectException(uee,netAgent_); 
         }
 
         // reset all entries between lastRow and sqldcRown to null

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java?rev=406120&r1=406119&r2=406120&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java Sat May 13
08:21:08 2006
@@ -698,7 +698,7 @@
         int sqlcode = readFdocaInt();
         byte[] sqlstate = readFdocaBytes(5);
         byte[] sqlerrproc = readFdocaBytes(8);
-        NetSqlca netSqlca = new NetSqlca(netAgent_.netConnection_, sqlcode, sqlstate, sqlerrproc,
typdef.getCcsidSbc());
+        NetSqlca netSqlca = new NetSqlca(netAgent_.netConnection_, sqlcode, sqlstate, sqlerrproc);
 
         parseSQLCAXGRP(typdef, netSqlca);
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java?rev=406120&r1=406119&r2=406120&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java Sat May 13 08:21:08
2006
@@ -21,6 +21,10 @@
 package org.apache.derby.client.net;
 
 import org.apache.derby.client.am.Sqlca;
+import org.apache.derby.shared.common.reference.SQLState;
+import org.apache.derby.client.am.ClientMessageId;
+import org.apache.derby.client.am.SqlException;
+import java.io.UnsupportedEncodingException;
 
 public class NetSqlca extends Sqlca {
     // these are the same variables that are in the Sqlca except ccsids
@@ -28,16 +32,31 @@
 
     NetSqlca(org.apache.derby.client.am.Connection connection,
              int sqlCode,
-             byte[] sqlStateBytes,
-             byte[] sqlErrpBytes,
-             int ccsid) {
+             String sqlState,
+             byte[] sqlErrpBytes) {
         super(connection);
         sqlCode_ = sqlCode;
-        sqlStateBytes_ = sqlStateBytes;
+        sqlState_ = sqlState;
         sqlErrpBytes_ = sqlErrpBytes;
-        ccsid_ = ccsid;
     }
 
+    NetSqlca(org.apache.derby.client.am.Connection connection,
+            int sqlCode,
+            byte[] sqlState,
+            byte[] sqlErrpBytes) throws SqlException {
+       super(connection);
+       sqlCode_ = sqlCode;
+       try
+       {
+           sqlState_ = bytes2String(sqlState,0,sqlState.length);
+       }catch(UnsupportedEncodingException uee)
+       {
+            throw new SqlException(null, 
+                  new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
+                       "sqlstate bytes", "SQLSTATE",uee);
+       }
+       sqlErrpBytes_ = sqlErrpBytes;
+   }
     protected void setSqlerrd(int[] sqlErrd) {
         sqlErrd_ = sqlErrd;
     }



Mime
View raw message