| From: | Barry Lind <blind(at)xythos(dot)com> | 
|---|---|
| To: | Kris Jurka <jurka(at)ejurka(dot)com> | 
| Cc: | Olaf Liepelt <olafl(at)comrad(dot)co(dot)nz>, pgsql-jdbc(at)postgresql(dot)org, pgsql-patches(at)postgresql(dot)org | 
| Subject: | Re: not fully fixed | 
| Date: | 2002-11-04 07:45:24 | 
| Message-ID: | 3DC62594.8070906@xythos.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-jdbc pgsql-patches | 
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(at)postgresql(dot)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
> 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dave Cramer | 2002-11-04 15:09:26 | Re: DatabaseMetaData.getTables() problem | 
| Previous Message | Barry Lind | 2002-11-04 07:44:48 | Re: DatabaseMetaData.getTables() problem | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dave Cramer | 2002-11-04 15:09:26 | Re: DatabaseMetaData.getTables() problem | 
| Previous Message | Barry Lind | 2002-11-04 07:44:48 | Re: DatabaseMetaData.getTables() problem |