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 ba...@apache.org on 2005/05/24 21:37:29 UTC

svn commit: r178257 - in /incubator/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/suites/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/

Author: bandaram
Date: Tue May 24 12:37:28 2005
New Revision: 178257

URL: http://svn.apache.org/viewcvs?rev=178257&view=rev
Log:
Derby-229: Return first matching column name, instead of last column in the select list for getter methods.

Column names supplied to getter [updater] methods are case insensitive.
If a select list contains the same column more than once, the first instance
of the column will be returned [updated]. Derby returns or updates the last
column in the select list, not the first. 

Submitted by Shreyas Kaushik. (Shreyas.Kaushik@Sun.COM)

Added:
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/rsgetXXXcolumnNames.out   (with props)
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/rsgetXXXcolumnNames.java   (with props)
Modified:
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=178257&r1=178256&r2=178257&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java Tue May 24 12:37:28 2005
@@ -3601,8 +3601,14 @@
 		ResultDescription rd = resultDescription;
 
     	// 1 or 0 based? assume 1 (probably wrong)
-    	for (int i=rd.getColumnCount(); i>=1; i--) {
+        // Changing the order in which columns are found from 1 till column count.
+        // This is necessary in cases where the column names are the same but are in different cases.
+        // This is because in updateXXX and getXXX methods column names are case insensitive
+        // and in that case the first column should be returned.
+        
+        int columnCount = rd.getColumnCount();
 
+        for(int i = 1 ; i<= columnCount;i++) {
     		String name = rd.getColumnDescriptor(i).getName();
     		if (StringUtil.SQLEqualsIgnoreCase(columnName, name)) {
     			return i;

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/rsgetXXXcolumnNames.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/rsgetXXXcolumnNames.out?rev=178257&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/rsgetXXXcolumnNames.out (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/rsgetXXXcolumnNames.out Tue May 24 12:37:28 2005
@@ -0,0 +1,9 @@
+Test rsgetXXXcolumnNames starting
+Before updation...
+ResultSet is: 1
+ResultSet is: 346
+After update...
+Column Number 1: 900
+Column Number 2: 346
+Col COL1: 900
+Col col1: 900

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/rsgetXXXcolumnNames.out
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall?rev=178257&r1=178256&r2=178257&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall (original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall Tue May 24 12:37:28 2005
@@ -15,4 +15,5 @@
 jdbcapi/setTransactionIsolation.java
 jdbcapi/prepStmtNull.java
 jdbcapi/testRelative.java
+jdbcapi/rsgetXXXcolumnNames.java
 

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/rsgetXXXcolumnNames.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/rsgetXXXcolumnNames.java?rev=178257&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/rsgetXXXcolumnNames.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/rsgetXXXcolumnNames.java Tue May 24 12:37:28 2005
@@ -0,0 +1,97 @@
+package org.apache.derbyTesting.functionTests.tests.jdbcapi;
+
+
+import java.sql.*;
+
+import org.apache.derby.tools.ij;
+import org.apache.derby.tools.JDBCDisplayUtil;
+
+public class rsgetXXXcolumnNames {
+
+    public static void main(String[] args) {
+        test1(args);
+    }
+    
+        public static void test1(String []args) {   
+                Connection con;
+                ResultSet rs;
+                Statement stmt = null;
+                PreparedStatement stmt1 = null;
+
+                System.out.println("Test rsgetXXXcolumnNames starting");
+
+                try
+                {
+                        // use the ij utility to read the property file and
+                        // make the initial connection.
+                        ij.getPropertyArg(args);
+                        con = ij.startJBMS();
+					
+			con.setAutoCommit(false);                        			              
+
+                        stmt = con.createStatement(); 
+
+			// create a table with two columns, their names differ in they being in different cases.
+                        stmt.executeUpdate("create table caseiscol(COL1 int ,\"col1\" int)");
+
+   			con.commit();
+   			
+			stmt.executeUpdate("insert into caseiscol values (1,346)");
+
+			con.commit();
+
+                        // select data from this table for updating
+			stmt1 = con.prepareStatement("select COL1, \"col1\" from caseiscol FOR UPDATE",ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+		        rs = stmt1.executeQuery();
+
+			// Get the data and disply it before updating.
+                        System.out.println("Before updation...");
+			while(rs.next()) {
+			   System.out.println("ResultSet is: "+rs.getObject(1));
+			   System.out.println("ResultSet is: "+rs.getObject(2));
+			}
+                        rs.close();
+			rs = stmt1.executeQuery();
+			while(rs.next()) {
+			   // Update the two columns with different data.
+			   // Since update is case insensitive only the first column should get updated in both cases.
+			   rs.updateInt("col1",100);
+			   rs.updateInt("COL1",900);
+			   rs.updateRow();
+			}
+			rs.close();
+
+			System.out.println("After update...");
+			rs = stmt1.executeQuery();
+
+			// Display the data after updating. Only the first column should have the updated value.
+			while(rs.next()) {
+			   System.out.println("Column Number 1: "+rs.getInt(1));
+			   System.out.println("Column Number 2: "+rs.getInt(2));
+			}
+			rs.close();
+			rs = stmt1.executeQuery();
+			while(rs.next()) {
+			   // Again checking for case insensitive behaviour here, should display the data in the first column.
+			   System.out.println("Col COL1: "+rs.getInt("COL1"));
+			   System.out.println("Col col1: "+rs.getInt("col1"));
+			}
+			rs.close();
+ 		} catch(SQLException sqle) {
+ 		   dumpSQLExceptions(sqle);
+ 		   sqle.printStackTrace();
+ 		} catch(Throwable e) {
+ 		   System.out.println("FAIL -- unexpected exception: "+e.getMessage());
+                   e.printStackTrace();
+
+ 		}
+     }
+     
+     static private void dumpSQLExceptions (SQLException se) {
+                System.out.println("FAIL -- unexpected exception");
+                while (se != null) {
+                        System.out.println("SQLSTATE("+se.getSQLState()+"): "+se.getMessage());
+                        se = se.getNextException();
+                }
+        }
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/rsgetXXXcolumnNames.java
------------------------------------------------------------------------------
    svn:eol-style = native