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 dj...@apache.org on 2005/06/10 01:32:07 UTC

svn commit: r189858 - in /incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij: ijMultiResult.java util.java

Author: djd
Date: Thu Jun  9 16:32:06 2005
New Revision: 189858

URL: http://svn.apache.org/viewcvs?rev=189858&view=rev
Log:
Change ij to special case DECIMAL types when passing values
from a ResultSet to a PreparedStatement since in J2ME there
is no Object type that represents a DECIMAL. This code
is used when an ij prepared statement is executed with the using clause.

Modified:
    incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultiResult.java
    incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java

Modified: incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultiResult.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultiResult.java?rev=189858&r1=189857&r2=189858&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultiResult.java (original)
+++ incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultiResult.java Thu Jun  9 16:32:06 2005
@@ -36,23 +36,14 @@
  */
 class ijMultiResult extends ijResultImpl {
 
-	Vector results = new Vector();
-	Statement statement;
-	ResultSet rs;
+	private Statement statement;
+	private ResultSet rs;
 	boolean closeWhenDone;
 
 	ijMultiResult(Statement s, ResultSet rs, boolean c) {
 		statement = s;
 		this.rs = rs;
 		closeWhenDone = c;
-	}
-
-	public void addStatementResult(Statement s) throws SQLException {
-System.out.println("adding statement "+results.size()+1);
-		if (s.getUpdateCount() >=0)
-			results.addElement(new Integer(s.getUpdateCount()));
-		else
-			results.addElement(s.getResultSet());
 	}
 
 	public boolean isMulti() { return true; }

Modified: incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java?rev=189858&r1=189857&r2=189858&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java (original)
+++ incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java Thu Jun  9 16:32:06 2005
@@ -53,6 +53,19 @@
  */
 public class util implements java.security.PrivilegedAction {
 	
+	private static boolean HAVE_BIG_DECIMAL;
+	
+	{
+		boolean haveBigDecimal;
+		try {
+			Class.forName("java.math.BigDecimal");
+			haveBigDecimal = true;
+		} catch (Throwable t) {
+			haveBigDecimal = false;
+		}
+		HAVE_BIG_DECIMAL = haveBigDecimal;
+	}
+	
 	private static final Class[] DS_GET_CONN_TYPES = {"".getClass(), "".getClass()};
 	private util() {}
 
@@ -592,9 +605,49 @@
 			// We need to make sure we pass along the scale, because
 			// setObject assumes a scale of zero (beetle 4365)
 			for (int c=1; c<=numCols; c++) {
-				ps.setObject(c,rs.getObject(c),
-					 rsmd.getColumnType(c),
-					 rsmd.getScale(c));
+				int sqlType = rsmd.getColumnType(c);
+				
+				if (sqlType == Types.DECIMAL)
+				{
+					if (util.HAVE_BIG_DECIMAL)
+					{
+						ps.setObject(c,rs.getObject(c),
+								 sqlType,
+								 rsmd.getScale(c));							
+					}
+					else
+					{
+						// In J2ME there is no object that represents
+						// a DECIMAL value. By default use String to
+						// pass values around, but for integral types
+						// first convert to a integral type from the DECIMAL
+						// because strings like 3.4 are not convertible to
+						// an integral type.
+						switch (ps.getMetaData().getColumnType(c))
+						{
+						case Types.BIGINT:
+							ps.setLong(c, rs.getLong(c));
+						    break;
+						case Types.INTEGER:
+						case Types.SMALLINT:
+						case Types.TINYINT:
+							ps.setInt(c, rs.getInt(c));
+							break;
+						default:
+							ps.setString(c,rs.getString(c));
+						    break;
+						}								
+					}
+					
+				}
+				else
+				{
+					ps.setObject(c,rs.getObject(c),
+							 sqlType);					
+				}
+				
+				
+
 			}