You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Shreyas Kaushik <Sh...@Sun.COM> on 2005/05/02 08:13:27 UTC

[PATCH]Derby-229

Hi,

This is the latest patch.
I have taken care of comments from Mamta and Dan. Please let me know if 
I have missed anything.

~ Shreyas

Re: [PATCH]Derby-229

Posted by "Lance J. Andersen" <La...@Sun.COM>.

Bernt M. Johnsen wrote:

>>>>>>>>>>>>>Daniel John Debrunner wrote (2005-05-02 09:23:59):
>>>>>>>>>>>>>                          
>>>>>>>>>>>>>
>>The JDBC tutorial (second edition) books says for this method
>>
>> "Checks whether the database treats mixed ..."
>>
>>note the *database*, not the driver. I think this method is describing
>>how identifiers behave in SQL statements, not in JDBC method calls.
>>
>>Also section 26.1.5 of JDBC tutorial book (second edition) describes how
>> duplicate column names are handled, and it says if there are identical
>>names the application needs to use a column index to obtain the correct
>>value. Nothing about quoted names in JDBC method calls.
>>    
>>
>
>I admit I refferd to the tutorial (third ed.) not the spec. 
>
>That said, quoted and unquoted are not identical in SQL (unless the
>quoted variant is all upper case and a legal SQL identifier, so "I", I
>and i are identical while "i" is another identifier). I find it
>reasonable to be able to access quoted identifires (e.g. "i") with the
>column name too (e.q. like getInt("\"i\"")). 
>
>  
>
This behavior is not spec'd though currently for JDBC so the milage 
might vary driver to driver.  I have another outstanding issue in this 
area to address so I will clean this up as part of that effort.



Re: [PATCH]Derby-229

Posted by "Bernt M. Johnsen" <Be...@Sun.COM>.
>>>>>>>>>>>> Daniel John Debrunner wrote (2005-05-02 09:23:59):
> 
> The JDBC tutorial (second edition) books says for this method
> 
>  "Checks whether the database treats mixed ..."
> 
> note the *database*, not the driver. I think this method is describing
> how identifiers behave in SQL statements, not in JDBC method calls.
> 
> Also section 26.1.5 of JDBC tutorial book (second edition) describes how
>  duplicate column names are handled, and it says if there are identical
> names the application needs to use a column index to obtain the correct
> value. Nothing about quoted names in JDBC method calls.

I admit I refferd to the tutorial (third ed.) not the spec. 

That said, quoted and unquoted are not identical in SQL (unless the
quoted variant is all upper case and a legal SQL identifier, so "I", I
and i are identical while "i" is another identifier). I find it
reasonable to be able to access quoted identifires (e.g. "i") with the
column name too (e.q. like getInt("\"i\"")). 

-- 
Bernt Marius Johnsen, Database Technology Group, Sun Microsystems, Norway

Re: [PATCH]Derby-229

Posted by Daniel John Debrunner <dj...@debrunners.com>.
Bernt M. Johnsen wrote:
> Hi all,
> 
> I have the following comment to this patch. This solves the problem of
> getting the *first* matching column instead of the *last*.
> 
> But: Since DatabaseMetaData.supportsMixedCaseQuotedIdentifiers()
> return true (which is a requirement to JDBC compliant drivers), it
> should be possible to do e.g. getXXX("\"quotedId\"") to get the column
> which exactly matches "quotedId". (Alternatively,
> supportsMixedCaseQuotedIdentifiers() could return false, but then the
> driver would not be JDBC compliant).


The JDBC tutorial (second edition) books says for this method

 "Checks whether the database treats mixed ..."

note the *database*, not the driver. I think this method is describing
how identifiers behave in SQL statements, not in JDBC method calls.

Also section 26.1.5 of JDBC tutorial book (second edition) describes how
 duplicate column names are handled, and it says if there are identical
names the application needs to use a column index to obtain the correct
value. Nothing about quoted names in JDBC method calls.

Dan.


Re: [PATCH]Derby-229

Posted by Shreyas Kaushik <Sh...@Sun.COM>.
Hi Lance,

I'm sorry I missed this mail yesterday. I should have been more clear 
the blurb is from the Derby codeline , sorry for this

~ Shreyas



Lance J. Andersen wrote:

> Hi Shreyas,
>
> Which codeline was blurb below that you cut and pasted from as I did 
> not see the blurb below in the javadocs for 
> supportsMixedCaseQuotedIdentifiers.
>
>
>       supportsMixedCaseQuotedIdentifiers
>
>public boolean *supportsMixedCaseQuotedIdentifiers*()
>                                           throws SQLException <http://java.sun.com/j2se/1.4.2/docs/api/java/sql/SQLException.html>
>
>     Retrieves whether this database treats mixed case quoted SQL
>     identifiers as case sensitive and as a result stores them in mixed
>     case. 
>
>     *Returns:*
>         |true| if so; |false| otherwise 
>     *Throws:*
>         |SQLException
>         <http://java.sun.com/j2se/1.4.2/docs/api/java/sql/SQLException.html>|
>         - if a database access error occurs
>
>
>
> However the tutorial (3rd edition) does indicate a compliant driver is 
> true.
>
> The JDBC spec does not mention this in the compliance section.  Looks 
> like another issue I need to clarify for JDBC 4.0.
>
> Regards
> Lance
>
>
>
> Shreyas Kaushik wrote:
>
>> Does the JDBC spec say anything about this ? I did not find anything 
>> that mandates this or says if this return false the driver is not 
>> JDBC compliant.
>>
>> On the contrary the comment says,
>>
>>   /**
>>     * Does the database treat mixed case unquoted SQL identifiers as
>>     * case sensitive and as a result store them in mixed case?
>>     *
>>     * A JDBC-Compliant driver will always return false.
>>     *
>>     * @return true if so
>>     */
>>
>> Lance, can you help us out here ?
>>
>> ~ Shreyas
>>
>> Bernt M. Johnsen wrote:
>>
>>> Hi all,
>>>
>>> I have the following comment to this patch. This solves the problem of
>>> getting the *first* matching column instead of the *last*.
>>>
>>> But: Since DatabaseMetaData.supportsMixedCaseQuotedIdentifiers()
>>> return true (which is a requirement to JDBC compliant drivers), it
>>> should be possible to do e.g. getXXX("\"quotedId\"") to get the column
>>> which exactly matches "quotedId". (Alternatively,
>>> supportsMixedCaseQuotedIdentifiers() could return false, but then the
>>> driver would not be JDBC compliant).
>>>
>>> If this is considered a new Jira issue I'd willingly file and fix it
>>> (need developer status though).
>>>
>>> Bernt
>>>
>>>  
>>>
>>>>>>>>>>>>>>> Shreyas Kaushik wrote (2005-05-02 11:43:27):
>>>>>>>>>>>>>>>                         
>>>>>>>>>>>>>>
>>>> Hi,
>>>>
>>>> This is the latest patch.
>>>> I have taken care of comments from Mamta and Dan. Please let me 
>>>> know if I have missed anything.
>>>>
>>>> ~ Shreyas
>>>>   
>>>
>>>
>>>  
>>>
>>>> Index: 
>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out 
>>>>
>>>> ===================================================================
>>>> --- 
>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out    
>>>> (revision 0)
>>>> +++ 
>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out    
>>>> (revision 0)
>>>> @@ -0,0 +1,9 @@
>>>> +Test caseInsensitiveColumn 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
>>>> Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>> ===================================================================
>>>> --- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java    
>>>> (revision 165091)
>>>> +++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java    
>>>> (working copy)
>>>> @@ -3591,8 +3591,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;
>>>> Index: 
>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java 
>>>>
>>>> ===================================================================
>>>> --- 
>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java    
>>>> (revision 0)
>>>> +++ 
>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java    
>>>> (revision 0)
>>>> @@ -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 caseInsensitiveColumn {
>>>> +
>>>> +    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 caseInsensitiveColumn 
>>>> 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);
>>>> +                   e.printStackTrace();
>>>> +
>>>> +         }
>>>> +     }
>>>> +     +     static private void dumpSQLExceptions (SQLException se) {
>>>> +                System.out.println("FAIL -- unexpected exception");
>>>> +                while (se != null) {
>>>> +                        
>>>> System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
>>>> +                        se = se.getNextException();
>>>> +                }
>>>> +        }
>>>> +}       
>>>
>>>
>>>
>>>  
>>>

Re: [PATCH]Derby-229

Posted by "Lance J. Andersen" <La...@Sun.COM>.
Hi Shreyas,

Which codeline was blurb below that you cut and pasted from as I did not 
see the blurb below in the javadocs for supportsMixedCaseQuotedIdentifiers.


      supportsMixedCaseQuotedIdentifiers

public boolean supportsMixedCaseQuotedIdentifiers()
                                           throws SQLException <http://java.sun.com/j2se/1.4.2/docs/api/java/sql/SQLException.html>

    Retrieves whether this database treats mixed case quoted SQL
    identifiers as case sensitive and as a result stores them in mixed
    case.

    Returns:
        true if so; false otherwise 
    Throws:
        SQLException
        <http://java.sun.com/j2se/1.4.2/docs/api/java/sql/SQLException.html>
        - if a database access error occurs



However the tutorial (3rd edition) does indicate a compliant driver is true.

The JDBC spec does not mention this in the compliance section.  Looks 
like another issue I need to clarify for JDBC 4.0.

Regards
Lance



Shreyas Kaushik wrote:

> Does the JDBC spec say anything about this ? I did not find anything 
> that mandates this or says if this return false the driver is not JDBC 
> compliant.
>
> On the contrary the comment says,
>
>   /**
>     * Does the database treat mixed case unquoted SQL identifiers as
>     * case sensitive and as a result store them in mixed case?
>     *
>     * A JDBC-Compliant driver will always return false.
>     *
>     * @return true if so
>     */
>
> Lance, can you help us out here ?
>
> ~ Shreyas
>
> Bernt M. Johnsen wrote:
>
>> Hi all,
>>
>> I have the following comment to this patch. This solves the problem of
>> getting the *first* matching column instead of the *last*.
>>
>> But: Since DatabaseMetaData.supportsMixedCaseQuotedIdentifiers()
>> return true (which is a requirement to JDBC compliant drivers), it
>> should be possible to do e.g. getXXX("\"quotedId\"") to get the column
>> which exactly matches "quotedId". (Alternatively,
>> supportsMixedCaseQuotedIdentifiers() could return false, but then the
>> driver would not be JDBC compliant).
>>
>> If this is considered a new Jira issue I'd willingly file and fix it
>> (need developer status though).
>>
>> Bernt
>>
>>  
>>
>>>>>>>>>>>>>> Shreyas Kaushik wrote (2005-05-02 11:43:27):
>>>>>>>>>>>>>>                         
>>>>>>>>>>>>>
>>> Hi,
>>>
>>> This is the latest patch.
>>> I have taken care of comments from Mamta and Dan. Please let me know 
>>> if I have missed anything.
>>>
>>> ~ Shreyas
>>>   
>>
>>
>>  
>>
>>> Index: 
>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out 
>>>
>>> ===================================================================
>>> --- 
>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out    
>>> (revision 0)
>>> +++ 
>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out    
>>> (revision 0)
>>> @@ -0,0 +1,9 @@
>>> +Test caseInsensitiveColumn 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
>>> Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>> ===================================================================
>>> --- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java    
>>> (revision 165091)
>>> +++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java    
>>> (working copy)
>>> @@ -3591,8 +3591,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;
>>> Index: 
>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java 
>>>
>>> ===================================================================
>>> --- 
>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java    
>>> (revision 0)
>>> +++ 
>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java    
>>> (revision 0)
>>> @@ -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 caseInsensitiveColumn {
>>> +
>>> +    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 caseInsensitiveColumn 
>>> 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);
>>> +                   e.printStackTrace();
>>> +
>>> +         }
>>> +     }
>>> +     +     static private void dumpSQLExceptions (SQLException se) {
>>> +                System.out.println("FAIL -- unexpected exception");
>>> +                while (se != null) {
>>> +                        
>>> System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
>>> +                        se = se.getNextException();
>>> +                }
>>> +        }
>>> +}       
>>
>>
>>
>>  
>>

Re: [PATCH]Derby-229

Posted by Shreyas Kaushik <Sh...@Sun.COM>.
Does the JDBC spec say anything about this ? I did not find anything 
that mandates this or says if this return false the driver is not JDBC 
compliant.

On the contrary the comment says,

   /**
     * Does the database treat mixed case unquoted SQL identifiers as
     * case sensitive and as a result store them in mixed case?
     *
     * A JDBC-Compliant driver will always return false.
     *
     * @return true if so
     */

Lance, can you help us out here ?

~ Shreyas

Bernt M. Johnsen wrote:

>Hi all,
>
>I have the following comment to this patch. This solves the problem of
>getting the *first* matching column instead of the *last*.
>
>But: Since DatabaseMetaData.supportsMixedCaseQuotedIdentifiers()
>return true (which is a requirement to JDBC compliant drivers), it
>should be possible to do e.g. getXXX("\"quotedId\"") to get the column
>which exactly matches "quotedId". (Alternatively,
>supportsMixedCaseQuotedIdentifiers() could return false, but then the
>driver would not be JDBC compliant).
>
>If this is considered a new Jira issue I'd willingly file and fix it
>(need developer status though).
>
>Bernt
>
>  
>
>>>>>>>>>>>>>Shreyas Kaushik wrote (2005-05-02 11:43:27):
>>>>>>>>>>>>>                          
>>>>>>>>>>>>>
>>Hi,
>>
>>This is the latest patch.
>>I have taken care of comments from Mamta and Dan. Please let me know if 
>>I have missed anything.
>>
>>~ Shreyas
>>    
>>
>
>  
>
>>Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>===================================================================
>>--- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out	(revision 0)
>>+++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out	(revision 0)
>>@@ -0,0 +1,9 @@
>>+Test caseInsensitiveColumn 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
>>Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>===================================================================
>>--- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java	(revision 165091)
>>+++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java	(working copy)
>>@@ -3591,8 +3591,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;
>>Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>===================================================================
>>--- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java	(revision 0)
>>+++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java	(revision 0)
>>@@ -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 caseInsensitiveColumn {
>>+
>>+    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 caseInsensitiveColumn 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);
>>+                   e.printStackTrace();
>>+
>>+ 		}
>>+     }
>>+     
>>+     static private void dumpSQLExceptions (SQLException se) {
>>+                System.out.println("FAIL -- unexpected exception");
>>+                while (se != null) {
>>+                        System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
>>+                        se = se.getNextException();
>>+                }
>>+        }
>>+}     
>>    
>>
>
>
>  
>

Re: [PATCH]Derby-229

Posted by "Bernt M. Johnsen" <Be...@Sun.COM>.
Hi all,

I have the following comment to this patch. This solves the problem of
getting the *first* matching column instead of the *last*.

But: Since DatabaseMetaData.supportsMixedCaseQuotedIdentifiers()
return true (which is a requirement to JDBC compliant drivers), it
should be possible to do e.g. getXXX("\"quotedId\"") to get the column
which exactly matches "quotedId". (Alternatively,
supportsMixedCaseQuotedIdentifiers() could return false, but then the
driver would not be JDBC compliant).

If this is considered a new Jira issue I'd willingly file and fix it
(need developer status though).

Bernt

>>>>>>>>>>>> Shreyas Kaushik wrote (2005-05-02 11:43:27):
> Hi,
> 
> This is the latest patch.
> I have taken care of comments from Mamta and Dan. Please let me know if 
> I have missed anything.
> 
> ~ Shreyas

> Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
> ===================================================================
> --- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out	(revision 0)
> +++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out	(revision 0)
> @@ -0,0 +1,9 @@
> +Test caseInsensitiveColumn 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
> Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
> ===================================================================
> --- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java	(revision 165091)
> +++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java	(working copy)
> @@ -3591,8 +3591,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;
> Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
> ===================================================================
> --- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java	(revision 0)
> +++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java	(revision 0)
> @@ -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 caseInsensitiveColumn {
> +
> +    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 caseInsensitiveColumn 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);
> +                   e.printStackTrace();
> +
> + 		}
> +     }
> +     
> +     static private void dumpSQLExceptions (SQLException se) {
> +                System.out.println("FAIL -- unexpected exception");
> +                while (se != null) {
> +                        System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
> +                        se = se.getNextException();
> +                }
> +        }
> +}     


-- 
Bernt Marius Johnsen, Database Technology Group, 
Sun Microsystems, Trondheim, Norway

Re: [PATCH]Derby-229

Posted by Shreyas Kaushik <Sh...@Sun.COM>.
Here is the latest patch with the name changed.

Output of svn stat:
-------------------

M      java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
A      
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/rsgetXXXcolumnNames.java
A      
java/testing/org/apache/derbyTesting/functionTests/master/rsgetXXXcolumnNames.out
M      
java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall

~ Shreyas

Satheesh Bandaram wrote:

>That probably meant new name was OK.... :-)  If you can submit your
>patch with your new suggestion, I will work to get this committed.
>
>Satheesh
>
>Shreyas Kaushik wrote:
>
>  
>
>>I sent out a mail having a changed name and did not receive any
>>response, hence thought the existing name was ok.
>>
>>~Shreyas
>>
>>Satheesh Bandaram wrote:
>>
>>    
>>
>>>I thought there was a comment to rename the test to more generic name?
>>>Or was it for another patch?
>>>
>>>Satheesh
>>>
>>>Shreyas Kaushik wrote:
>>>
>>> 
>>>
>>>      
>>>
>>>>Mamta Satoor wrote:
>>>>
>>>>  
>>>>
>>>>        
>>>>
>>>>>Hi Shreyas,
>>>>>
>>>>>Thanks for taking care of the earlier review comments. I think
>>>>>existing test jdbcapi/resultset.java could have been used to add new
>>>>>tests for this bug. resultset.java tests various other JDBC apis on
>>>>>ResultSet object.
>>>>>
>>>>>
>>>>>    
>>>>>          
>>>>>
>>>>This is a slightly different case, hence I wanted to keep this
>>>>seperate.
>>>>
>>>>  
>>>>
>>>>        
>>>>
>>>>>Besides that, I wondered how this test runs in Network Server mode. It
>>>>>will be nice to have these generic JDBC tests to be run in both
>>>>>embedded and Network Server mode to cover both the Derby offerings.
>>>>>
>>>>>
>>>>>    
>>>>>          
>>>>>
>>>>I added this test to run with the jdbcapi test suite, anything else I
>>>>need to do ?
>>>>
>>>>If there are no other major comments I guess this can be committed,
>>>>can someone do this ?
>>>>
>>>>~ Shreyas
>>>>
>>>>  
>>>>
>>>>        
>>>>
>>>>>Other than that, the patch and the comments look good to me,
>>>>>Mamta
>>>>>
>>>>>On 5/4/05, Shreyas Kaushik <Sh...@sun.com> wrote:
>>>>>
>>>>>
>>>>>    
>>>>>
>>>>>          
>>>>>
>>>>>>Attached is the new patch taking care of your comments. See inline
>>>>>>for
>>>>>>answers.
>>>>>>
>>>>>>~ Shreyas
>>>>>>
>>>>>>Satheesh Bandaram wrote:
>>>>>>
>>>>>> 
>>>>>>
>>>>>>      
>>>>>>
>>>>>>            
>>>>>>
>>>>>>>Thanks for the patch. Couple of comments:
>>>>>>>
>>>>>>> 1. New test caseInsensitiveColumn is not part of any testsuite. So,
>>>>>>>    the test will not get run. You would need to add this to an
>>>>>>>    existing suite.
>>>>>>>
>>>>>>>           
>>>>>>>              
>>>>>>>
>>>>>>Taken care , will run as a part of the jdbcapi suite.
>>>>>>
>>>>>> 
>>>>>>
>>>>>>      
>>>>>>
>>>>>>            
>>>>>>
>>>>>>> 1. Also, you should consider enhancing an existing test script when
>>>>>>>    adding a new test, rather than creating a new test everytime.
>>>>>>>    This increases number of tests in a suite, taking it longer to
>>>>>>>    run them. Instead, updating an existing test is better.
>>>>>>>
>>>>>>>           
>>>>>>>              
>>>>>>>
>>>>>>There was no test case testing this feature, since this is a new
>>>>>>feature
>>>>>>I added a speprate test. For Derby-203 for adding test cases I am
>>>>>>working on building from the existing test cases.
>>>>>>
>>>>>> 
>>>>>>
>>>>>>      
>>>>>>
>>>>>>            
>>>>>>
>>>>>>> 1. The patch needs to be generated from the trunk directory, so
>>>>>>>    your directory path wouldn't show in the patch.
>>>>>>>    (/drivers/derby/trunk)
>>>>>>>
>>>>>>>           
>>>>>>>              
>>>>>>>
>>>>>>Done.
>>>>>>
>>>>>> 
>>>>>>
>>>>>>      
>>>>>>
>>>>>>            
>>>>>>
>>>>>>>Satheesh
>>>>>>>
>>>>>>>Shreyas Kaushik wrote:
>>>>>>>
>>>>>>>  
>>>>>>>        
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>>>Hi,
>>>>>>>>
>>>>>>>>This is the latest patch.
>>>>>>>>I have taken care of comments from Mamta and Dan. Please let me
>>>>>>>>know
>>>>>>>>if I have missed anything.
>>>>>>>>
>>>>>>>>~ Shreyas
>>>>>>>>
>>>>>>>>------------------------------------------------------------------------
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>Index:
>>>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>>>
>>>>>>>>
>>>>>>>>===================================================================
>>>>>>>>---
>>>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>>>(revision 0)
>>>>>>>>+++
>>>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>>>(revision 0)
>>>>>>>>@@ -0,0 +1,9 @@
>>>>>>>>+Test caseInsensitiveColumn 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
>>>>>>>>Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>>>>>===================================================================
>>>>>>>>---
>>>>>>>>java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java      
>>>>>>>>(revision 165091)
>>>>>>>>+++
>>>>>>>>java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java      
>>>>>>>>(working copy)
>>>>>>>>@@ -3591,8 +3591,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;
>>>>>>>>Index:
>>>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>>>
>>>>>>>>
>>>>>>>>===================================================================
>>>>>>>>---
>>>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>>>(revision 0)
>>>>>>>>+++
>>>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>>>(revision 0)
>>>>>>>>@@ -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 caseInsensitiveColumn {
>>>>>>>>+
>>>>>>>>+    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 caseInsensitiveColumn
>>>>>>>>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);
>>>>>>>>+                   e.printStackTrace();
>>>>>>>>+
>>>>>>>>+             }
>>>>>>>>+     }
>>>>>>>>+
>>>>>>>>+     static private void dumpSQLExceptions (SQLException se) {
>>>>>>>>+                System.out.println("FAIL -- unexpected
>>>>>>>>exception");
>>>>>>>>+                while (se != null) {
>>>>>>>>+                      
>>>>>>>>System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
>>>>>>>>+                        se = se.getNextException();
>>>>>>>>+                }
>>>>>>>>+        }
>>>>>>>>+}
>>>>>>>>
>>>>>>>>
>>>>>>>>               
>>>>>>>>                
>>>>>>>>
>>>>>>Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>>>===================================================================
>>>>>>--- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>>>(revision 167869)
>>>>>>+++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>>>(working copy)
>>>>>>@@ -3591,8 +3591,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;
>>>>>>Index:
>>>>>>java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>
>>>>>>
>>>>>>===================================================================
>>>>>>---
>>>>>>java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>
>>>>>>(revision 0)
>>>>>>+++
>>>>>>java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>
>>>>>>(revision 0)
>>>>>>@@ -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 caseInsensitiveColumn {
>>>>>>+
>>>>>>+    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 caseInsensitiveColumn
>>>>>>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();
>>>>>>+                }
>>>>>>+        }
>>>>>>+}
>>>>>>Index:
>>>>>>java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>
>>>>>>
>>>>>>===================================================================
>>>>>>---
>>>>>>java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>
>>>>>>(revision 0)
>>>>>>+++
>>>>>>java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>
>>>>>>(revision 0)
>>>>>>@@ -0,0 +1,9 @@
>>>>>>+Test caseInsensitiveColumn 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
>>>>>>Index:
>>>>>>java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
>>>>>>
>>>>>>
>>>>>>===================================================================
>>>>>>---
>>>>>>java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall  
>>>>>>(revision 167869)
>>>>>>+++
>>>>>>java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall  
>>>>>>(working copy)
>>>>>>@@ -15,4 +15,4 @@
>>>>>>jdbcapi/setTransactionIsolation.java
>>>>>>jdbcapi/prepStmtNull.java
>>>>>>jdbcapi/testRelative.java
>>>>>>-
>>>>>>+jdbcapi/caseInsensitiveColumn.java
>>>>>>
>>>>>>
>>>>>>
>>>>>> 
>>>>>>      
>>>>>>            
>>>>>>
>>>>  
>>>>        
>>>>
>>> 
>>>
>>>      
>>>
>>
>>    
>>
>
>  
>

Re: [PATCH]Derby-229

Posted by Satheesh Bandaram <sa...@Sourcery.Org>.
That probably meant new name was OK.... :-)  If you can submit your
patch with your new suggestion, I will work to get this committed.

Satheesh

Shreyas Kaushik wrote:

> I sent out a mail having a changed name and did not receive any
> response, hence thought the existing name was ok.
>
> ~Shreyas
>
> Satheesh Bandaram wrote:
>
>> I thought there was a comment to rename the test to more generic name?
>> Or was it for another patch?
>>
>> Satheesh
>>
>> Shreyas Kaushik wrote:
>>
>>  
>>
>>> Mamta Satoor wrote:
>>>
>>>   
>>>
>>>> Hi Shreyas,
>>>>
>>>> Thanks for taking care of the earlier review comments. I think
>>>> existing test jdbcapi/resultset.java could have been used to add new
>>>> tests for this bug. resultset.java tests various other JDBC apis on
>>>> ResultSet object.
>>>>
>>>>
>>>>     
>>>
>>> This is a slightly different case, hence I wanted to keep this
>>> seperate.
>>>
>>>   
>>>
>>>> Besides that, I wondered how this test runs in Network Server mode. It
>>>> will be nice to have these generic JDBC tests to be run in both
>>>> embedded and Network Server mode to cover both the Derby offerings.
>>>>
>>>>
>>>>     
>>>
>>> I added this test to run with the jdbcapi test suite, anything else I
>>> need to do ?
>>>
>>> If there are no other major comments I guess this can be committed,
>>> can someone do this ?
>>>
>>> ~ Shreyas
>>>
>>>   
>>>
>>>> Other than that, the patch and the comments look good to me,
>>>> Mamta
>>>>
>>>> On 5/4/05, Shreyas Kaushik <Sh...@sun.com> wrote:
>>>>
>>>>
>>>>     
>>>>
>>>>> Attached is the new patch taking care of your comments. See inline
>>>>> for
>>>>> answers.
>>>>>
>>>>> ~ Shreyas
>>>>>
>>>>> Satheesh Bandaram wrote:
>>>>>
>>>>>  
>>>>>
>>>>>       
>>>>>
>>>>>> Thanks for the patch. Couple of comments:
>>>>>>
>>>>>>  1. New test caseInsensitiveColumn is not part of any testsuite. So,
>>>>>>     the test will not get run. You would need to add this to an
>>>>>>     existing suite.
>>>>>>
>>>>>>            
>>>>>
>>>>> Taken care , will run as a part of the jdbcapi suite.
>>>>>
>>>>>  
>>>>>
>>>>>       
>>>>>
>>>>>>  1. Also, you should consider enhancing an existing test script when
>>>>>>     adding a new test, rather than creating a new test everytime.
>>>>>>     This increases number of tests in a suite, taking it longer to
>>>>>>     run them. Instead, updating an existing test is better.
>>>>>>
>>>>>>            
>>>>>
>>>>> There was no test case testing this feature, since this is a new
>>>>> feature
>>>>> I added a speprate test. For Derby-203 for adding test cases I am
>>>>> working on building from the existing test cases.
>>>>>
>>>>>  
>>>>>
>>>>>       
>>>>>
>>>>>>  1. The patch needs to be generated from the trunk directory, so
>>>>>>     your directory path wouldn't show in the patch.
>>>>>>     (/drivers/derby/trunk)
>>>>>>
>>>>>>            
>>>>>
>>>>> Done.
>>>>>
>>>>>  
>>>>>
>>>>>       
>>>>>
>>>>>> Satheesh
>>>>>>
>>>>>> Shreyas Kaushik wrote:
>>>>>>
>>>>>>   
>>>>>>         
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> This is the latest patch.
>>>>>>> I have taken care of comments from Mamta and Dan. Please let me
>>>>>>> know
>>>>>>> if I have missed anything.
>>>>>>>
>>>>>>> ~ Shreyas
>>>>>>>
>>>>>>> ------------------------------------------------------------------------
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Index:
>>>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>>
>>>>>>>
>>>>>>> ===================================================================
>>>>>>> ---
>>>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>> (revision 0)
>>>>>>> +++
>>>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>> (revision 0)
>>>>>>> @@ -0,0 +1,9 @@
>>>>>>> +Test caseInsensitiveColumn 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
>>>>>>> Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>>>> ===================================================================
>>>>>>> ---
>>>>>>> java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java      
>>>>>>> (revision 165091)
>>>>>>> +++
>>>>>>> java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java      
>>>>>>> (working copy)
>>>>>>> @@ -3591,8 +3591,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;
>>>>>>> Index:
>>>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>>
>>>>>>>
>>>>>>> ===================================================================
>>>>>>> ---
>>>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>> (revision 0)
>>>>>>> +++
>>>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>> (revision 0)
>>>>>>> @@ -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 caseInsensitiveColumn {
>>>>>>> +
>>>>>>> +    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 caseInsensitiveColumn
>>>>>>> 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);
>>>>>>> +                   e.printStackTrace();
>>>>>>> +
>>>>>>> +             }
>>>>>>> +     }
>>>>>>> +
>>>>>>> +     static private void dumpSQLExceptions (SQLException se) {
>>>>>>> +                System.out.println("FAIL -- unexpected
>>>>>>> exception");
>>>>>>> +                while (se != null) {
>>>>>>> +                      
>>>>>>> System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
>>>>>>> +                        se = se.getNextException();
>>>>>>> +                }
>>>>>>> +        }
>>>>>>> +}
>>>>>>>
>>>>>>>
>>>>>>>                
>>>>>>
>>>>> Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>> ===================================================================
>>>>> --- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>> (revision 167869)
>>>>> +++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>> (working copy)
>>>>> @@ -3591,8 +3591,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;
>>>>> Index:
>>>>> java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>
>>>>>
>>>>> ===================================================================
>>>>> ---
>>>>> java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>
>>>>> (revision 0)
>>>>> +++
>>>>> java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>
>>>>> (revision 0)
>>>>> @@ -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 caseInsensitiveColumn {
>>>>> +
>>>>> +    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 caseInsensitiveColumn
>>>>> 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();
>>>>> +                }
>>>>> +        }
>>>>> +}
>>>>> Index:
>>>>> java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>
>>>>>
>>>>> ===================================================================
>>>>> ---
>>>>> java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>
>>>>> (revision 0)
>>>>> +++
>>>>> java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>
>>>>> (revision 0)
>>>>> @@ -0,0 +1,9 @@
>>>>> +Test caseInsensitiveColumn 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
>>>>> Index:
>>>>> java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
>>>>>
>>>>>
>>>>> ===================================================================
>>>>> ---
>>>>> java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall  
>>>>> (revision 167869)
>>>>> +++
>>>>> java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall  
>>>>> (working copy)
>>>>> @@ -15,4 +15,4 @@
>>>>> jdbcapi/setTransactionIsolation.java
>>>>> jdbcapi/prepStmtNull.java
>>>>> jdbcapi/testRelative.java
>>>>> -
>>>>> +jdbcapi/caseInsensitiveColumn.java
>>>>>
>>>>>
>>>>>
>>>>>  
>>>>>       
>>>>
>>>
>>>   
>>
>>
>>  
>>
>
>
>


Re: [PATCH]Derby-229

Posted by Shreyas Kaushik <Sh...@Sun.COM>.
I sent out a mail having a changed name and did not receive any 
response, hence thought the existing name was ok.

~Shreyas

Satheesh Bandaram wrote:

>I thought there was a comment to rename the test to more generic name?
>Or was it for another patch?
>
>Satheesh
>
>Shreyas Kaushik wrote:
>
>  
>
>>Mamta Satoor wrote:
>>
>>    
>>
>>>Hi Shreyas,
>>>
>>>Thanks for taking care of the earlier review comments. I think
>>>existing test jdbcapi/resultset.java could have been used to add new
>>>tests for this bug. resultset.java tests various other JDBC apis on
>>>ResultSet object.
>>> 
>>>
>>>      
>>>
>>This is a slightly different case, hence I wanted to keep this seperate.
>>
>>    
>>
>>>Besides that, I wondered how this test runs in Network Server mode. It
>>>will be nice to have these generic JDBC tests to be run in both
>>>embedded and Network Server mode to cover both the Derby offerings.
>>> 
>>>
>>>      
>>>
>>I added this test to run with the jdbcapi test suite, anything else I
>>need to do ?
>>
>>If there are no other major comments I guess this can be committed,
>>can someone do this ?
>>
>>~ Shreyas
>>
>>    
>>
>>>Other than that, the patch and the comments look good to me,
>>>Mamta
>>>
>>>On 5/4/05, Shreyas Kaushik <Sh...@sun.com> wrote:
>>> 
>>>
>>>      
>>>
>>>>Attached is the new patch taking care of your comments. See inline for
>>>>answers.
>>>>
>>>>~ Shreyas
>>>>
>>>>Satheesh Bandaram wrote:
>>>>
>>>>  
>>>>
>>>>        
>>>>
>>>>>Thanks for the patch. Couple of comments:
>>>>>
>>>>>  1. New test caseInsensitiveColumn is not part of any testsuite. So,
>>>>>     the test will not get run. You would need to add this to an
>>>>>     existing suite.
>>>>>
>>>>>    
>>>>>          
>>>>>
>>>>Taken care , will run as a part of the jdbcapi suite.
>>>>
>>>>  
>>>>
>>>>        
>>>>
>>>>>  1. Also, you should consider enhancing an existing test script when
>>>>>     adding a new test, rather than creating a new test everytime.
>>>>>     This increases number of tests in a suite, taking it longer to
>>>>>     run them. Instead, updating an existing test is better.
>>>>>
>>>>>    
>>>>>          
>>>>>
>>>>There was no test case testing this feature, since this is a new
>>>>feature
>>>>I added a speprate test. For Derby-203 for adding test cases I am
>>>>working on building from the existing test cases.
>>>>
>>>>  
>>>>
>>>>        
>>>>
>>>>>  1. The patch needs to be generated from the trunk directory, so
>>>>>     your directory path wouldn't show in the patch.
>>>>>     (/drivers/derby/trunk)
>>>>>
>>>>>    
>>>>>          
>>>>>
>>>>Done.
>>>>
>>>>  
>>>>
>>>>        
>>>>
>>>>>Satheesh
>>>>>
>>>>>Shreyas Kaushik wrote:
>>>>>
>>>>>    
>>>>>
>>>>>          
>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>This is the latest patch.
>>>>>>I have taken care of comments from Mamta and Dan. Please let me know
>>>>>>if I have missed anything.
>>>>>>
>>>>>>~ Shreyas
>>>>>>
>>>>>>------------------------------------------------------------------------
>>>>>>
>>>>>>
>>>>>>Index:
>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>>
>>>>>>===================================================================
>>>>>>---
>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out 
>>>>>>(revision 0)
>>>>>>+++
>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out 
>>>>>>(revision 0)
>>>>>>@@ -0,0 +1,9 @@
>>>>>>+Test caseInsensitiveColumn 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
>>>>>>Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>>>===================================================================
>>>>>>---
>>>>>>java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java       
>>>>>>(revision 165091)
>>>>>>+++
>>>>>>java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java       
>>>>>>(working copy)
>>>>>>@@ -3591,8 +3591,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;
>>>>>>Index:
>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>>
>>>>>>===================================================================
>>>>>>---
>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java 
>>>>>>(revision 0)
>>>>>>+++
>>>>>>/drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java 
>>>>>>(revision 0)
>>>>>>@@ -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 caseInsensitiveColumn {
>>>>>>+
>>>>>>+    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 caseInsensitiveColumn
>>>>>>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);
>>>>>>+                   e.printStackTrace();
>>>>>>+
>>>>>>+             }
>>>>>>+     }
>>>>>>+
>>>>>>+     static private void dumpSQLExceptions (SQLException se) {
>>>>>>+                System.out.println("FAIL -- unexpected exception");
>>>>>>+                while (se != null) {
>>>>>>+                       
>>>>>>System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
>>>>>>+                        se = se.getNextException();
>>>>>>+                }
>>>>>>+        }
>>>>>>+}
>>>>>>
>>>>>>
>>>>>>      
>>>>>>            
>>>>>>
>>>>Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>===================================================================
>>>>--- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java 
>>>>(revision 167869)
>>>>+++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java 
>>>>(working copy)
>>>>@@ -3591,8 +3591,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;
>>>>Index:
>>>>java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>
>>>>===================================================================
>>>>---
>>>>java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>(revision 0)
>>>>+++
>>>>java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>(revision 0)
>>>>@@ -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 caseInsensitiveColumn {
>>>>+
>>>>+    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 caseInsensitiveColumn
>>>>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();
>>>>+                }
>>>>+        }
>>>>+}
>>>>Index:
>>>>java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>
>>>>===================================================================
>>>>---
>>>>java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>(revision 0)
>>>>+++
>>>>java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>(revision 0)
>>>>@@ -0,0 +1,9 @@
>>>>+Test caseInsensitiveColumn 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
>>>>Index:
>>>>java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
>>>>
>>>>===================================================================
>>>>---
>>>>java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall   
>>>>(revision 167869)
>>>>+++
>>>>java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall   
>>>>(working copy)
>>>>@@ -15,4 +15,4 @@
>>>>jdbcapi/setTransactionIsolation.java
>>>>jdbcapi/prepStmtNull.java
>>>>jdbcapi/testRelative.java
>>>>-
>>>>+jdbcapi/caseInsensitiveColumn.java
>>>>
>>>>
>>>>
>>>>  
>>>>        
>>>>
>>
>>    
>>
>
>  
>

Re: [PATCH]Derby-229

Posted by Satheesh Bandaram <sa...@Sourcery.Org>.
I thought there was a comment to rename the test to more generic name?
Or was it for another patch?

Satheesh

Shreyas Kaushik wrote:

>
>
> Mamta Satoor wrote:
>
>> Hi Shreyas,
>>
>> Thanks for taking care of the earlier review comments. I think
>> existing test jdbcapi/resultset.java could have been used to add new
>> tests for this bug. resultset.java tests various other JDBC apis on
>> ResultSet object.
>>  
>>
> This is a slightly different case, hence I wanted to keep this seperate.
>
>> Besides that, I wondered how this test runs in Network Server mode. It
>> will be nice to have these generic JDBC tests to be run in both
>> embedded and Network Server mode to cover both the Derby offerings.
>>  
>>
> I added this test to run with the jdbcapi test suite, anything else I
> need to do ?
>
> If there are no other major comments I guess this can be committed,
> can someone do this ?
>
> ~ Shreyas
>
>> Other than that, the patch and the comments look good to me,
>> Mamta
>>
>> On 5/4/05, Shreyas Kaushik <Sh...@sun.com> wrote:
>>  
>>
>>> Attached is the new patch taking care of your comments. See inline for
>>> answers.
>>>
>>> ~ Shreyas
>>>
>>> Satheesh Bandaram wrote:
>>>
>>>   
>>>
>>>> Thanks for the patch. Couple of comments:
>>>>
>>>>   1. New test caseInsensitiveColumn is not part of any testsuite. So,
>>>>      the test will not get run. You would need to add this to an
>>>>      existing suite.
>>>>
>>>>     
>>>
>>> Taken care , will run as a part of the jdbcapi suite.
>>>
>>>   
>>>
>>>>   1. Also, you should consider enhancing an existing test script when
>>>>      adding a new test, rather than creating a new test everytime.
>>>>      This increases number of tests in a suite, taking it longer to
>>>>      run them. Instead, updating an existing test is better.
>>>>
>>>>     
>>>
>>> There was no test case testing this feature, since this is a new
>>> feature
>>> I added a speprate test. For Derby-203 for adding test cases I am
>>> working on building from the existing test cases.
>>>
>>>   
>>>
>>>>   1. The patch needs to be generated from the trunk directory, so
>>>>      your directory path wouldn't show in the patch.
>>>>      (/drivers/derby/trunk)
>>>>
>>>>     
>>>
>>> Done.
>>>
>>>   
>>>
>>>> Satheesh
>>>>
>>>> Shreyas Kaushik wrote:
>>>>
>>>>     
>>>>
>>>>> Hi,
>>>>>
>>>>> This is the latest patch.
>>>>> I have taken care of comments from Mamta and Dan. Please let me know
>>>>> if I have missed anything.
>>>>>
>>>>> ~ Shreyas
>>>>>
>>>>> ------------------------------------------------------------------------
>>>>>
>>>>>
>>>>> Index:
>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>>
>>>>> ===================================================================
>>>>> ---
>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out 
>>>>> (revision 0)
>>>>> +++
>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out 
>>>>> (revision 0)
>>>>> @@ -0,0 +1,9 @@
>>>>> +Test caseInsensitiveColumn 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
>>>>> Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>> ===================================================================
>>>>> ---
>>>>> java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java       
>>>>> (revision 165091)
>>>>> +++
>>>>> java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java       
>>>>> (working copy)
>>>>> @@ -3591,8 +3591,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;
>>>>> Index:
>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>>
>>>>> ===================================================================
>>>>> ---
>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java 
>>>>> (revision 0)
>>>>> +++
>>>>> /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java 
>>>>> (revision 0)
>>>>> @@ -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 caseInsensitiveColumn {
>>>>> +
>>>>> +    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 caseInsensitiveColumn
>>>>> 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);
>>>>> +                   e.printStackTrace();
>>>>> +
>>>>> +             }
>>>>> +     }
>>>>> +
>>>>> +     static private void dumpSQLExceptions (SQLException se) {
>>>>> +                System.out.println("FAIL -- unexpected exception");
>>>>> +                while (se != null) {
>>>>> +                       
>>>>> System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
>>>>> +                        se = se.getNextException();
>>>>> +                }
>>>>> +        }
>>>>> +}
>>>>>
>>>>>
>>>>>       
>>>>
>>> Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>> ===================================================================
>>> --- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java 
>>> (revision 167869)
>>> +++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java 
>>> (working copy)
>>> @@ -3591,8 +3591,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;
>>> Index:
>>> java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>
>>> ===================================================================
>>> ---
>>> java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>> (revision 0)
>>> +++
>>> java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>> (revision 0)
>>> @@ -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 caseInsensitiveColumn {
>>> +
>>> +    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 caseInsensitiveColumn
>>> 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();
>>> +                }
>>> +        }
>>> +}
>>> Index:
>>> java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>
>>> ===================================================================
>>> ---
>>> java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>> (revision 0)
>>> +++
>>> java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>> (revision 0)
>>> @@ -0,0 +1,9 @@
>>> +Test caseInsensitiveColumn 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
>>> Index:
>>> java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
>>>
>>> ===================================================================
>>> ---
>>> java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall   
>>> (revision 167869)
>>> +++
>>> java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall   
>>> (working copy)
>>> @@ -15,4 +15,4 @@
>>> jdbcapi/setTransactionIsolation.java
>>> jdbcapi/prepStmtNull.java
>>> jdbcapi/testRelative.java
>>> -
>>> +jdbcapi/caseInsensitiveColumn.java
>>>
>>>
>>>
>>>   
>>
>
>
>


Re: [PATCH]Derby-229

Posted by Shreyas Kaushik <Sh...@Sun.COM>.

Mamta Satoor wrote:

>Hi Shreyas,
>
>Thanks for taking care of the earlier review comments. I think
>existing test jdbcapi/resultset.java could have been used to add new
>tests for this bug. resultset.java tests various other JDBC apis on
>ResultSet object.
>  
>
This is a slightly different case, hence I wanted to keep this seperate.

>Besides that, I wondered how this test runs in Network Server mode. It
>will be nice to have these generic JDBC tests to be run in both
>embedded and Network Server mode to cover both the Derby offerings.
>  
>
I added this test to run with the jdbcapi test suite, anything else I 
need to do ?

If there are no other major comments I guess this can be committed, can 
someone do this ?

~ Shreyas

>Other than that, the patch and the comments look good to me,
>Mamta
>
>On 5/4/05, Shreyas Kaushik <Sh...@sun.com> wrote:
>  
>
>>Attached is the new patch taking care of your comments. See inline for
>>answers.
>>
>>~ Shreyas
>>
>>Satheesh Bandaram wrote:
>>
>>    
>>
>>>Thanks for the patch. Couple of comments:
>>>
>>>   1. New test caseInsensitiveColumn is not part of any testsuite. So,
>>>      the test will not get run. You would need to add this to an
>>>      existing suite.
>>>
>>>      
>>>
>>Taken care , will run as a part of the jdbcapi suite.
>>
>>    
>>
>>>   1. Also, you should consider enhancing an existing test script when
>>>      adding a new test, rather than creating a new test everytime.
>>>      This increases number of tests in a suite, taking it longer to
>>>      run them. Instead, updating an existing test is better.
>>>
>>>      
>>>
>>There was no test case testing this feature, since this is a new feature
>>I added a speprate test. For Derby-203 for adding test cases I am
>>working on building from the existing test cases.
>>
>>    
>>
>>>   1. The patch needs to be generated from the trunk directory, so
>>>      your directory path wouldn't show in the patch.
>>>      (/drivers/derby/trunk)
>>>
>>>      
>>>
>>Done.
>>
>>    
>>
>>>Satheesh
>>>
>>>Shreyas Kaushik wrote:
>>>
>>>      
>>>
>>>>Hi,
>>>>
>>>>This is the latest patch.
>>>>I have taken care of comments from Mamta and Dan. Please let me know
>>>>if I have missed anything.
>>>>
>>>>~ Shreyas
>>>>
>>>>------------------------------------------------------------------------
>>>>
>>>>Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>>>===================================================================
>>>>--- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out  (revision 0)
>>>>+++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out  (revision 0)
>>>>@@ -0,0 +1,9 @@
>>>>+Test caseInsensitiveColumn 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
>>>>Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>>>===================================================================
>>>>--- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java        (revision 165091)
>>>>+++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java        (working copy)
>>>>@@ -3591,8 +3591,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;
>>>>Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>>>===================================================================
>>>>--- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java  (revision 0)
>>>>+++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java  (revision 0)
>>>>@@ -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 caseInsensitiveColumn {
>>>>+
>>>>+    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 caseInsensitiveColumn 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);
>>>>+                   e.printStackTrace();
>>>>+
>>>>+             }
>>>>+     }
>>>>+
>>>>+     static private void dumpSQLExceptions (SQLException se) {
>>>>+                System.out.println("FAIL -- unexpected exception");
>>>>+                while (se != null) {
>>>>+                        System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
>>>>+                        se = se.getNextException();
>>>>+                }
>>>>+        }
>>>>+}
>>>>
>>>>
>>>>        
>>>>
>>Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>===================================================================
>>--- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java  (revision 167869)
>>+++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java  (working copy)
>>@@ -3591,8 +3591,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;
>>Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>===================================================================
>>--- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java (revision 0)
>>+++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java (revision 0)
>>@@ -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 caseInsensitiveColumn {
>>+
>>+    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 caseInsensitiveColumn 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();
>>+                }
>>+        }
>>+}
>>Index: java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>===================================================================
>>--- java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out (revision 0)
>>+++ java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out (revision 0)
>>@@ -0,0 +1,9 @@
>>+Test caseInsensitiveColumn 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
>>Index: java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
>>===================================================================
>>--- java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall    (revision 167869)
>>+++ java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall    (working copy)
>>@@ -15,4 +15,4 @@
>>jdbcapi/setTransactionIsolation.java
>>jdbcapi/prepStmtNull.java
>>jdbcapi/testRelative.java
>>-
>>+jdbcapi/caseInsensitiveColumn.java
>>
>>
>>
>>    
>>

Re: [PATCH]Derby-229

Posted by Mamta Satoor <ms...@gmail.com>.
Hi Shreyas,

Thanks for taking care of the earlier review comments. I think
existing test jdbcapi/resultset.java could have been used to add new
tests for this bug. resultset.java tests various other JDBC apis on
ResultSet object.

Besides that, I wondered how this test runs in Network Server mode. It
will be nice to have these generic JDBC tests to be run in both
embedded and Network Server mode to cover both the Derby offerings.

Other than that, the patch and the comments look good to me,
Mamta

On 5/4/05, Shreyas Kaushik <Sh...@sun.com> wrote:
> Attached is the new patch taking care of your comments. See inline for
> answers.
> 
> ~ Shreyas
> 
> Satheesh Bandaram wrote:
> 
> > Thanks for the patch. Couple of comments:
> >
> >    1. New test caseInsensitiveColumn is not part of any testsuite. So,
> >       the test will not get run. You would need to add this to an
> >       existing suite.
> >
> Taken care , will run as a part of the jdbcapi suite.
> 
> >    1. Also, you should consider enhancing an existing test script when
> >       adding a new test, rather than creating a new test everytime.
> >       This increases number of tests in a suite, taking it longer to
> >       run them. Instead, updating an existing test is better.
> >
> There was no test case testing this feature, since this is a new feature
> I added a speprate test. For Derby-203 for adding test cases I am
> working on building from the existing test cases.
> 
> >    1. The patch needs to be generated from the trunk directory, so
> >       your directory path wouldn't show in the patch.
> >       (/drivers/derby/trunk)
> >
> Done.
> 
> >
> > Satheesh
> >
> > Shreyas Kaushik wrote:
> >
> >> Hi,
> >>
> >> This is the latest patch.
> >> I have taken care of comments from Mamta and Dan. Please let me know
> >> if I have missed anything.
> >>
> >> ~ Shreyas
> >>
> >>------------------------------------------------------------------------
> >>
> >>Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
> >>===================================================================
> >>--- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out  (revision 0)
> >>+++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out  (revision 0)
> >>@@ -0,0 +1,9 @@
> >>+Test caseInsensitiveColumn 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
> >>Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
> >>===================================================================
> >>--- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java        (revision 165091)
> >>+++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java        (working copy)
> >>@@ -3591,8 +3591,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;
> >>Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
> >>===================================================================
> >>--- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java  (revision 0)
> >>+++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java  (revision 0)
> >>@@ -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 caseInsensitiveColumn {
> >>+
> >>+    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 caseInsensitiveColumn 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);
> >>+                   e.printStackTrace();
> >>+
> >>+             }
> >>+     }
> >>+
> >>+     static private void dumpSQLExceptions (SQLException se) {
> >>+                System.out.println("FAIL -- unexpected exception");
> >>+                while (se != null) {
> >>+                        System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
> >>+                        se = se.getNextException();
> >>+                }
> >>+        }
> >>+}
> >>
> >>
> 
> 
> Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
> ===================================================================
> --- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java  (revision 167869)
> +++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java  (working copy)
> @@ -3591,8 +3591,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;
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java (revision 0)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java (revision 0)
> @@ -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 caseInsensitiveColumn {
> +
> +    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 caseInsensitiveColumn 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();
> +                }
> +        }
> +}
> Index: java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out (revision 0)
> +++ java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out (revision 0)
> @@ -0,0 +1,9 @@
> +Test caseInsensitiveColumn 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
> Index: java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall    (revision 167869)
> +++ java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall    (working copy)
> @@ -15,4 +15,4 @@
> jdbcapi/setTransactionIsolation.java
> jdbcapi/prepStmtNull.java
> jdbcapi/testRelative.java
> -
> +jdbcapi/caseInsensitiveColumn.java
> 
> 
>

Re: [PATCH]Derby-229

Posted by Shreyas Kaushik <Sh...@Sun.COM>.
What would be a good name, rsgetXXXcolumnNames be a good one ?

~ Shreyas

Daniel John Debrunner wrote:

>Shreyas Kaushik wrote:
>
>  
>
>>Attached is the new patch taking care of your comments. See inline for
>>answers.
>>
>>~ Shreyas
>>    
>>
>
>One of my comments is that the test could be expanded in the future to
>perform more testing around column names. In that case changing its name
>now would be a good thing to do.
>
>Dan.
>
>  
>

Re: [PATCH]Derby-229

Posted by Daniel John Debrunner <dj...@debrunners.com>.
Shreyas Kaushik wrote:

> Attached is the new patch taking care of your comments. See inline for
> answers.
> 
> ~ Shreyas

One of my comments is that the test could be expanded in the future to
perform more testing around column names. In that case changing its name
now would be a good thing to do.

Dan.


Re: [PATCH]Derby-229

Posted by Shreyas Kaushik <Sh...@Sun.COM>.
Attached is the new patch taking care of your comments. See inline for 
answers.

~ Shreyas

Satheesh Bandaram wrote:

> Thanks for the patch. Couple of comments:
>
>    1. New test caseInsensitiveColumn is not part of any testsuite. So,
>       the test will not get run. You would need to add this to an
>       existing suite.
>
Taken care , will run as a part of the jdbcapi suite.

>    1. Also, you should consider enhancing an existing test script when
>       adding a new test, rather than creating a new test everytime.
>       This increases number of tests in a suite, taking it longer to
>       run them. Instead, updating an existing test is better.
>
There was no test case testing this feature, since this is a new feature 
I added a speprate test. For Derby-203 for adding test cases I am 
working on building from the existing test cases.

>    1. The patch needs to be generated from the trunk directory, so
>       your directory path wouldn't show in the patch.
>       (/drivers/derby/trunk)
>
Done.

>
> Satheesh
>
> Shreyas Kaushik wrote:
>
>> Hi,
>>
>> This is the latest patch.
>> I have taken care of comments from Mamta and Dan. Please let me know 
>> if I have missed anything.
>>
>> ~ Shreyas
>>
>>------------------------------------------------------------------------
>>
>>Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out
>>===================================================================
>>--- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out	(revision 0)
>>+++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/master/caseInsensitiveColumn.out	(revision 0)
>>@@ -0,0 +1,9 @@
>>+Test caseInsensitiveColumn 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
>>Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
>>===================================================================
>>--- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java	(revision 165091)
>>+++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java	(working copy)
>>@@ -3591,8 +3591,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;
>>Index: /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java
>>===================================================================
>>--- /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java	(revision 0)
>>+++ /drivers/derby/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/caseInsensitiveColumn.java	(revision 0)
>>@@ -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 caseInsensitiveColumn {
>>+
>>+    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 caseInsensitiveColumn 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);
>>+                   e.printStackTrace();
>>+
>>+ 		}
>>+     }
>>+     
>>+     static private void dumpSQLExceptions (SQLException se) {
>>+                System.out.println("FAIL -- unexpected exception");
>>+                while (se != null) {
>>+                        System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
>>+                        se = se.getNextException();
>>+                }
>>+        }
>>+}     
>>  
>>