Re: [PATCHES] Patch for jdbc2 ResultSet.java - Mailing list pgsql-jdbc

From Bruce Momjian
Subject Re: [PATCHES] Patch for jdbc2 ResultSet.java
Date
Msg-id 200109072214.f87MEvJ01807@candle.pha.pa.us
Whole thread Raw
In response to Re: Patch for jdbc2 ResultSet.java  (Joseph Shraibman <jks@selectacast.net>)
List pgsql-jdbc
Patch applied.  Thanks.

The patch did not apply so I had to merge it in manually.  Patch
attached.  I have review the diff I made vs. your.

>
>
> Barry Lind wrote:
> > Joseph,
> >
> > In looking at this patch it looks OK, except for the following change:
> >
> >  > !         if (index>=-rows.size())
> >  > --- 725,737 ----
> >  > !         if (index > rows_size)
> >
> > I haven't looked at the entire method, but the change you made seems
> > incorrect.
> >
> Oops!  Thanks for catching that.  Cut and paste error.  I hate those.
>
> > If you want this patch to be applied it should be sent to the
> > pgsql-patches mail list.
>
>
> I thought that jdbc stuff was preferred to be on the jdbc list.  I guess not.
>
> new patch:
>
>
> *** ResultSet.java.orig    Tue Sep  4 16:34:14 2001
> --- ResultSet.java    Wed Sep  5 15:35:59 2001
> ***************
> *** 134,140 ****
>      {
>        //release resources held (memory for tuples)
>        if(rows!=null) {
> -       rows.setSize(0);
>          rows=null;
>        }
>      }
> --- 134,139 ----
> ***************
> *** 709,716 ****
>      public int findColumn(String columnName) throws SQLException
>      {
>        int i;
> !
> !     for (i = 0 ; i < fields.length; ++i)
>          if (fields[i].getName().equalsIgnoreCase(columnName))
>        return (i+1);
>        throw new PSQLException ("postgresql.res.colname",columnName);
> --- 708,715 ----
>      public int findColumn(String columnName) throws SQLException
>      {
>        int i;
> !     final int flen = fields.length;
> !     for (i = 0 ; i < flen; ++i)
>          if (fields[i].getName().equalsIgnoreCase(columnName))
>        return (i+1);
>        throw new PSQLException ("postgresql.res.colname",columnName);
> ***************
> *** 726,736 ****
>        if (index==0)
>            throw new SQLException("Cannot move to index of 0");
>
>        //if index<0, count from the end of the result set, but check
>        //to be sure that it is not beyond the first index
>        if (index<0)
> !         if (index>=-rows.size())
> !         internalIndex=rows.size()+index;
>            else {
>            beforeFirst();
>            return false;
> --- 725,737 ----
>        if (index==0)
>            throw new SQLException("Cannot move to index of 0");
>
> +     final int rows_size = rows.size();
> +
>        //if index<0, count from the end of the result set, but check
>        //to be sure that it is not beyond the first index
>        if (index<0)
> !         if (index > -rows_size)
> !         internalIndex = rows_size+index;
>            else {
>            beforeFirst();
>            return false;
> ***************
> *** 739,745 ****
>        //must be the case that index>0,
>        //find the correct place, assuming that
>        //the index is not too large
> !     if (index<=rows.size())
>            internalIndex = index-1;
>        else {
>            afterLast();
> --- 740,746 ----
>        //must be the case that index>0,
>        //find the correct place, assuming that
>        //the index is not too large
> !     if (index <= rows_size)
>            internalIndex = index-1;
>        else {
>            afterLast();
> ***************
> *** 753,760 ****
>
>        public void afterLast() throws SQLException
>        {
> !     if (rows.size() > 0)
> !         current_row = rows.size();
>        }
>
>        public void beforeFirst() throws SQLException
> --- 754,762 ----
>
>        public void afterLast() throws SQLException
>        {
> !     final int rows_size = rows.size();
> !     if (rows_size > 0)
> !         current_row = rows_size;
>        }
>
>        public void beforeFirst() throws SQLException
> ***************
> *** 967,973 ****
>
>        public boolean isAfterLast() throws SQLException
>        {
> !     return (current_row >= rows.size()  && rows.size() > 0);
>        }
>
>        public boolean isBeforeFirst() throws SQLException
> --- 969,976 ----
>
>        public boolean isAfterLast() throws SQLException
>        {
> !     final int rows_size = rows.size();
> !     return (current_row >= rows_size && rows_size > 0);
>        }
>
>        public boolean isBeforeFirst() throws SQLException
> ***************
> *** 982,995 ****
>
>        public boolean isLast() throws SQLException
>        {
> !     return (current_row == rows.size() -1  && rows.size() > 0);
>        }
>
>        public boolean last() throws SQLException
>        {
> !     if (rows.size() <= 0)
>            return false;
> !     current_row = rows.size() - 1;
>        this_row = (byte [][])rows.elementAt(current_row);
>        return true;
>        }
> --- 985,1000 ----
>
>        public boolean isLast() throws SQLException
>        {
> !     final int rows_size = rows.size();
> !     return (current_row == rows_size -1  && rows_size > 0);
>        }
>
>        public boolean last() throws SQLException
>        {
> !     final int rows_size = rows.size();
> !     if (rows_size <= 0)
>            return false;
> !     current_row = rows_size - 1;
>        this_row = (byte [][])rows.elementAt(current_row);
>        return true;
>        }
> ***************
> *** 1480,1483 ****
>            }
>        }
>    }
> -
> --- 1485,1487 ----
>
>
>
>
>
>
>
> --
> Joseph Shraibman
> jks@selectacast.net
> Increase signal to noise ratio.  http://www.targabot.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java,v
retrieving revision 1.31
diff -c -r1.31 ResultSet.java
*** src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java    2001/08/24 16:50:18    1.31
--- src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java    2001/09/07 22:12:18
***************
*** 134,140 ****
    {
      //release resources held (memory for tuples)
      if(rows!=null) {
-       rows.setSize(0);
        rows=null;
      }
    }
--- 134,139 ----
***************
*** 710,716 ****
    {
      int i;

!     for (i = 0 ; i < fields.length; ++i)
        if (fields[i].getName().equalsIgnoreCase(columnName))
      return (i+1);
      throw new PSQLException ("postgresql.res.colname",columnName);
--- 709,716 ----
    {
      int i;

!     final int flen = fields.length;
!     for (i = 0 ; i < flen; ++i)
        if (fields[i].getName().equalsIgnoreCase(columnName))
      return (i+1);
      throw new PSQLException ("postgresql.res.colname",columnName);
***************
*** 726,736 ****
      if (index==0)
          throw new SQLException("Cannot move to index of 0");

      //if index<0, count from the end of the result set, but check
      //to be sure that it is not beyond the first index
      if (index<0)
!         if (index>=-rows.size())
!         internalIndex=rows.size()+index;
          else {
          beforeFirst();
          return false;
--- 726,738 ----
      if (index==0)
          throw new SQLException("Cannot move to index of 0");

+     final int rows_size = rows.size();
+
      //if index<0, count from the end of the result set, but check
      //to be sure that it is not beyond the first index
      if (index<0)
!         if (index > -rows_size)
!         internalIndex = rows_size+index;
          else {
          beforeFirst();
          return false;
***************
*** 739,745 ****
      //must be the case that index>0,
      //find the correct place, assuming that
      //the index is not too large
!     if (index<=rows.size())
          internalIndex = index-1;
      else {
          afterLast();
--- 741,747 ----
      //must be the case that index>0,
      //find the correct place, assuming that
      //the index is not too large
!     if (index <= rows_size)
          internalIndex = index-1;
      else {
          afterLast();
***************
*** 753,760 ****

      public void afterLast() throws SQLException
      {
!     if (rows.size() > 0)
!         current_row = rows.size();
      }

      public void beforeFirst() throws SQLException
--- 755,763 ----

      public void afterLast() throws SQLException
      {
!     final int rows_size = rows.size();
!     if (rows_size > 0)
!         current_row = rows_size;
      }

      public void beforeFirst() throws SQLException
***************
*** 967,973 ****

      public boolean isAfterLast() throws SQLException
      {
!     return (current_row >= rows.size()  && rows.size() > 0);
      }

      public boolean isBeforeFirst() throws SQLException
--- 970,977 ----

      public boolean isAfterLast() throws SQLException
      {
!     final int rows_size = rows.size();
!     return (current_row >= rows_size && rows_size > 0);
      }

      public boolean isBeforeFirst() throws SQLException
***************
*** 982,997 ****

      public boolean isLast() throws SQLException
      {
!     return (current_row == rows.size() -1  && rows.size() > 0);
      }

      public boolean last() throws SQLException
      {
!     if (rows.size() <= 0)
!         return false;
!     current_row = rows.size() - 1;
!     this_row = (byte [][])rows.elementAt(current_row);
!     return true;
      }

      public void moveToCurrentRow() throws SQLException
--- 986,1003 ----

      public boolean isLast() throws SQLException
      {
!     final int rows_size = rows.size();
!     return (current_row == rows_size -1  && rows_size > 0);
      }

      public boolean last() throws SQLException
      {
!     final int rows_size = rows.size();
!     if (rows_size <= 0)
!          return false;
!     current_row = rows_size - 1;
!      this_row = (byte [][])rows.elementAt(current_row);
!      return true;
      }

      public void moveToCurrentRow() throws SQLException
***************
*** 1480,1483 ****
          }
      }
  }
-
--- 1486,1488 ----

pgsql-jdbc by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [PATCHES] Patch for jdbc2 ResultSet.java
Next
From: Bruce Momjian
Date:
Subject: Re: Read transactions don't work on 7.0.x db's 3rd attempt