Thread: Re: not fully fixed

Re: not fully fixed

From
Kris Jurka
Date:
The previous patch for using an updateable result set to set null values
was incomplete because it only handled the storing of the database
values, while not properly updating the in memory result during
updateRowBuffer().  While the blob case actually threw an exception, no
other case really worked correctly.

Thanks for the complete example that makes debugging so much easier.  In
the future please post problems to the pgsql-jdbc@postgresql.org list
instead of me personally.  This will ensure the problem is dealt with if
I am busy or away.

Kris Jurka


Olaf Liepelt wrote:
>
> The bugfix for updating result sets with null values does not work for blob dataypes:
>
> code:
>
> public class PGTest {
>     public static void main(String args[])
>         throws Exception
>     {
>         String sql = "create table t(a serial primary key, b int, c bytea)";
>         Class.forName("org.postgresql.Driver");
>         Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "comrad", "");
>         try
>         {
>             Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
>             stmt.executeUpdate(sql);
>             sql = "INSERT INTO t (a, b) VALUES (3, 4)";
>             stmt.executeUpdate(sql);
>             stmt.close();
>         } catch (SQLException sqle)
>         {
>             sqle.printStackTrace();
>         }
>
>         try
>         {
>             sql = "select * from t for update";
>             Statement stmt = conn.createStatement();
>             ResultSet rs = stmt.executeQuery(sql);
>             rs.next();
>             rs.updateObject("a", new Integer(2));
>             rs.updateNull("c");
>             rs.updateRow();
>             conn.commit();
>         } catch (SQLException sqle)
>         {
>             sqle.printStackTrace();
>         }
>
>         Statement stmt = conn.createStatement();
>         stmt.executeUpdate("DROP TABLE t");
>         stmt.executeUpdate("DROP sequence t_a_seq");
>         stmt.close();
>         conn.close();
>     }
> }
>
> Thank for quick response last time.
> Regards OlafIndex: src/interfaces/jdbc/org/postgresql/jdbc2//AbstractJdbc2ResultSet.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v
retrieving revision 1.9
diff -c -r1.9 AbstractJdbc2ResultSet.java
*** src/interfaces/jdbc/org/postgresql/jdbc2//AbstractJdbc2ResultSet.java    2002/10/17 19:17:08    1.9
--- src/interfaces/jdbc/org/postgresql/jdbc2//AbstractJdbc2ResultSet.java    2002/11/04 04:36:16
***************
*** 1406,1439 ****
              String columnName = (String) columns.nextElement();
              int columnIndex = _findColumn( columnName ) - 1;

!             switch ( connection.getSQLType( fields[columnIndex].getPGType() ) )
              {

!                 case Types.DECIMAL:
!                 case Types.BIGINT:
!                 case Types.DOUBLE:
!                 case Types.BIT:
!                 case Types.VARCHAR:
!                 case Types.DATE:
!                 case Types.TIME:
!                 case Types.TIMESTAMP:
!                 case Types.SMALLINT:
!                 case Types.FLOAT:
!                 case Types.INTEGER:
!                 case Types.CHAR:
!                 case Types.NUMERIC:
!                 case Types.REAL:
!                 case Types.TINYINT:

!                     rowBuffer[columnIndex] = connection.getEncoding().encode(String.valueOf( updateValues.get(
columnName) )); 

!                 case Types.NULL:
!                     continue;

!                 default:
!                     rowBuffer[columnIndex] = (byte[]) updateValues.get( columnName );
!             }

          }
      }

--- 1406,1447 ----
              String columnName = (String) columns.nextElement();
              int columnIndex = _findColumn( columnName ) - 1;

!             Object valueObject = updateValues.get(columnName);
!             if (valueObject instanceof NullObject) {
!                 rowBuffer[columnIndex] = null;
!             }
!             else
              {
+
+                 switch ( connection.getSQLType( fields[columnIndex].getPGType() ) )
+                 {

!                     case Types.DECIMAL:
!                     case Types.BIGINT:
!                     case Types.DOUBLE:
!                     case Types.BIT:
!                     case Types.VARCHAR:
!                     case Types.DATE:
!                     case Types.TIME:
!                     case Types.TIMESTAMP:
!                     case Types.SMALLINT:
!                     case Types.FLOAT:
!                     case Types.INTEGER:
!                     case Types.CHAR:
!                     case Types.NUMERIC:
!                     case Types.REAL:
!                     case Types.TINYINT:

!                         rowBuffer[columnIndex] = connection.getEncoding().encode(String.valueOf( valueObject));

!                     case Types.NULL:
!                         continue;

!                     default:
!                         rowBuffer[columnIndex] = (byte[]) valueObject;
!                 }

+             }
          }
      }


Re: not fully fixed

From
Barry Lind
Date:
Patch applied.

thanks,
--Barry

Kris Jurka wrote:
> The previous patch for using an updateable result set to set null values
> was incomplete because it only handled the storing of the database
> values, while not properly updating the in memory result during
> updateRowBuffer().  While the blob case actually threw an exception, no
> other case really worked correctly.
>
> Thanks for the complete example that makes debugging so much easier.  In
> the future please post problems to the pgsql-jdbc@postgresql.org list
> instead of me personally.  This will ensure the problem is dealt with if
> I am busy or away.
>
> Kris Jurka
>
>
> Olaf Liepelt wrote:
>
>>The bugfix for updating result sets with null values does not work for blob dataypes:
>>
>>code:
>>
>>public class PGTest {
>>    public static void main(String args[])
>>        throws Exception
>>    {
>>        String sql = "create table t(a serial primary key, b int, c bytea)";
>>        Class.forName("org.postgresql.Driver");
>>        Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "comrad", "");
>>        try
>>        {
>>            Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
>>            stmt.executeUpdate(sql);
>>            sql = "INSERT INTO t (a, b) VALUES (3, 4)";
>>            stmt.executeUpdate(sql);
>>            stmt.close();
>>        } catch (SQLException sqle)
>>        {
>>            sqle.printStackTrace();
>>        }
>>
>>        try
>>        {
>>            sql = "select * from t for update";
>>            Statement stmt = conn.createStatement();
>>            ResultSet rs = stmt.executeQuery(sql);
>>            rs.next();
>>            rs.updateObject("a", new Integer(2));
>>            rs.updateNull("c");
>>            rs.updateRow();
>>            conn.commit();
>>        } catch (SQLException sqle)
>>        {
>>            sqle.printStackTrace();
>>        }
>>
>>        Statement stmt = conn.createStatement();
>>        stmt.executeUpdate("DROP TABLE t");
>>        stmt.executeUpdate("DROP sequence t_a_seq");
>>        stmt.close();
>>        conn.close();
>>    }
>>}
>>
>>Thank for quick response last time.
>>Regards Olaf
>>
>>
>>------------------------------------------------------------------------
>>
>>Index: src/interfaces/jdbc/org/postgresql/jdbc2//AbstractJdbc2ResultSet.java
>>===================================================================
>>RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v
>>retrieving revision 1.9
>>diff -c -r1.9 AbstractJdbc2ResultSet.java
>>*** src/interfaces/jdbc/org/postgresql/jdbc2//AbstractJdbc2ResultSet.java    2002/10/17 19:17:08    1.9
>>--- src/interfaces/jdbc/org/postgresql/jdbc2//AbstractJdbc2ResultSet.java    2002/11/04 04:36:16
>>***************
>>*** 1406,1439 ****
>>              String columnName = (String) columns.nextElement();
>>              int columnIndex = _findColumn( columnName ) - 1;
>>
>>!             switch ( connection.getSQLType( fields[columnIndex].getPGType() ) )
>>              {
>>
>>!                 case Types.DECIMAL:
>>!                 case Types.BIGINT:
>>!                 case Types.DOUBLE:
>>!                 case Types.BIT:
>>!                 case Types.VARCHAR:
>>!                 case Types.DATE:
>>!                 case Types.TIME:
>>!                 case Types.TIMESTAMP:
>>!                 case Types.SMALLINT:
>>!                 case Types.FLOAT:
>>!                 case Types.INTEGER:
>>!                 case Types.CHAR:
>>!                 case Types.NUMERIC:
>>!                 case Types.REAL:
>>!                 case Types.TINYINT:
>>
>>!                     rowBuffer[columnIndex] = connection.getEncoding().encode(String.valueOf( updateValues.get(
columnName) )); 
>>
>>!                 case Types.NULL:
>>!                     continue;
>>
>>!                 default:
>>!                     rowBuffer[columnIndex] = (byte[]) updateValues.get( columnName );
>>!             }
>>
>>          }
>>      }
>>
>>--- 1406,1447 ----
>>              String columnName = (String) columns.nextElement();
>>              int columnIndex = _findColumn( columnName ) - 1;
>>
>>!             Object valueObject = updateValues.get(columnName);
>>!             if (valueObject instanceof NullObject) {
>>!                 rowBuffer[columnIndex] = null;
>>!             }
>>!             else
>>              {
>>+
>>+                 switch ( connection.getSQLType( fields[columnIndex].getPGType() ) )
>>+                 {
>>
>>!                     case Types.DECIMAL:
>>!                     case Types.BIGINT:
>>!                     case Types.DOUBLE:
>>!                     case Types.BIT:
>>!                     case Types.VARCHAR:
>>!                     case Types.DATE:
>>!                     case Types.TIME:
>>!                     case Types.TIMESTAMP:
>>!                     case Types.SMALLINT:
>>!                     case Types.FLOAT:
>>!                     case Types.INTEGER:
>>!                     case Types.CHAR:
>>!                     case Types.NUMERIC:
>>!                     case Types.REAL:
>>!                     case Types.TINYINT:
>>
>>!                         rowBuffer[columnIndex] = connection.getEncoding().encode(String.valueOf( valueObject));
>>
>>!                     case Types.NULL:
>>!                         continue;
>>
>>!                     default:
>>!                         rowBuffer[columnIndex] = (byte[]) valueObject;
>>!                 }
>>
>>+             }
>>          }
>>      }
>>
>>
>>
>>------------------------------------------------------------------------
>>
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 5: Have you checked our extensive FAQ?
>>
>>http://www.postgresql.org/users-lounge/docs/faq.html
>