Re: [JDBC] absolute() error with jdbc7.1-1.2

Поиск
Список
Период
Сортировка
Искать

Re: [JDBC] absolute() error with jdbc7.1-1.2

От:
Liam Stewart <liams@redhat.com>
Дата:
Вложения:

Attached is a patch against the CVS repository that fixes the problem.
There's also a little fix for the getRow() method. While fixing
absolute(), I noticed that getRow() wasn't quite following the spec: it
wasn't returning 0 when the ResultSet wasn't positioned on a row.  I've
started a ResultSet test case and included it as well.

Liam

On Mon, Nov 12, 2001 at 10:53:45AM -0800, Robert Down wrote:
> with the lasttest driver, I can't use absolute() according to the spec.
> 
> index = -1;
> rs.absolute(index);      
> 
> What it currently does:
> java.lang.ArrayIndexOutOfBoundsException: -2 < 0
> 
> 
> What it should do according to the spec:
> ========================================
> public boolean absolute(int row)
>                  throws SQLExceptionMoves the cursor to the given row number 
> in this ResultSet object. 
> 
> If the row number is positive, the cursor moves to the given row number with 
> respect to the beginning of the result set. The first row is row 1, the 
> second is row 2, and so on. 
> 
> If the given row number is negative, the cursor moves to an absolute row 
> position with respect to the end of the result set. For example, calling the 
> method absolute(-1) positions the cursor on the last row; calling the method 
> absolute(-2) moves the cursor to the next-to-last row, and so on. 
> 
> An attempt to position the cursor beyond the first/last row in the result set 
> leaves the cursor before the first row or after the last row. 
> ===========================================
> 
> Please note the important fact that you can use (-1) as a position.  This is 
> very important.
> 
> Thanks!
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly

-- 
Liam Stewart :: Red Hat Canada, Ltd. :: liams@redhat.com

Re: [JDBC] absolute() error with jdbc7.1-1.2

От:
Barry Lind <barry@xythos.com>
Дата:
Liam,

I reviewed and applied your patch.  It will be in beta3.

thanks,
--Barry

Liam Stewart wrote:

> Attached is a patch against the CVS repository that fixes the problem.
> There's also a little fix for the getRow() method. While fixing
> absolute(), I noticed that getRow() wasn't quite following the spec: it
> wasn't returning 0 when the ResultSet wasn't positioned on a row.  I've
> started a ResultSet test case and included it as well.
> 
> Liam
> 
> On Mon, Nov 12, 2001 at 10:53:45AM -0800, Robert Down wrote:
> 
>>with the lasttest driver, I can't use absolute() according to the spec.
>>
>>index = -1;
>>rs.absolute(index);      
>>
>>What it currently does:
>>java.lang.ArrayIndexOutOfBoundsException: -2 < 0
>>
>>
>>What it should do according to the spec:
>>========================================
>>public boolean absolute(int row)
>>                 throws SQLExceptionMoves the cursor to the given row number 
>>in this ResultSet object. 
>>
>>If the row number is positive, the cursor moves to the given row number with 
>>respect to the beginning of the result set. The first row is row 1, the 
>>second is row 2, and so on. 
>>
>>If the given row number is negative, the cursor moves to an absolute row 
>>position with respect to the end of the result set. For example, calling the 
>>method absolute(-1) positions the cursor on the last row; calling the method 
>>absolute(-2) moves the cursor to the next-to-last row, and so on. 
>>
>>An attempt to position the cursor beyond the first/last row in the result set 
>>leaves the cursor before the first row or after the last row. 
>>===========================================
>>
>>Please note the important fact that you can use (-1) as a position.  This is 
>>very important.
>>
>>Thanks!
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 3: if posting/reading through Usenet, please send an appropriate
>>subscribe-nomail command to majordomo@postgresql.org so that your
>>message can get through to the mailing list cleanly
>>
> 
> 
> ------------------------------------------------------------------------
> 
> package org.postgresql.test.jdbc2;
> 
> import org.postgresql.test.JDBC2Tests;
> import junit.framework.TestCase;
> import java.io.*;
> import java.sql.*;
> 
> /**
>  * ResultSet tests.
>  */
> public class ResultSetTest extends TestCase
> {
> 	private Connection con;
> 
> 	public ResultSetTest(String name)
> 	{
> 		super(name);
> 	}
> 
> 	protected void setUp() throws Exception
> 	{
> 		con = JDBC2Tests.openDB();
> 		Statement stmt = con.createStatement();
> 		
> 		JDBC2Tests.createTable(con, "testrs", "id integer");
> 
> 		stmt.executeUpdate("INSERT INTO testrs VALUES (1)");
> 		stmt.executeUpdate("INSERT INTO testrs VALUES (2)");
> 		stmt.executeUpdate("INSERT INTO testrs VALUES (3)");
> 		stmt.executeUpdate("INSERT INTO testrs VALUES (4)");
> 		stmt.executeUpdate("INSERT INTO testrs VALUES (6)");
> 		stmt.executeUpdate("INSERT INTO testrs VALUES (9)");
> 
> 		stmt.close();
> 	}
> 
> 	protected void tearDown() throws Exception
> 	{
> 		JDBC2Tests.dropTable(con, "testrs");
> 		JDBC2Tests.closeDB(con);
> 	}
> 
> 	public void testAbsolute() throws Exception
> 	{
> 		Statement stmt = con.createStatement();
> 		ResultSet rs = stmt.executeQuery("SELECT * FROM testrs");
> 		
> 		assertTrue(rs.absolute(-1));
> 		assertEquals(6, rs.getRow());
> 
> 		assertTrue(rs.absolute(1));
> 		assertEquals(1, rs.getRow());
> 
> 		assertTrue(!rs.absolute(-10));
> 		assertEquals(0, rs.getRow());
>  		assertTrue(rs.next());
>  		assertEquals(1, rs.getRow());
> 
> 		assertTrue(!rs.absolute(10));
> 		assertEquals(0, rs.getRow());
> 		assertTrue(rs.previous());
> 		assertEquals(6, rs.getRow());
> 		
> 		stmt.close();
> 	}
> }
> 
> 
> ------------------------------------------------------------------------
> 
> Index: src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java,v
> retrieving revision 1.41
> diff -c -r1.41 ResultSet.java
> *** src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java	2001/11/12 19:59:46	1.41
> --- src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java	2001/11/13 21:22:01
> ***************
> *** 836,841 ****
> --- 836,842 ----
>   		//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
> ***************
> *** 843,858 ****
>   				beforeFirst();
>   				return false;
>   			}
> ! 
> ! 		//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();
> ! 			return false;
>   		}
>   
>   		current_row = internalIndex;
> --- 844,862 ----
>   				beforeFirst();
>   				return false;
>   			}
> ! 		}
>   		else
>   		{
> ! 			//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();
> ! 				return false;
> ! 			}
>   		}
>   
>   		current_row = internalIndex;
> ***************
> *** 1074,1079 ****
> --- 1078,1088 ----
>   
>   	public int getRow() throws SQLException
>   	{
> + 		final int rows_size = rows.size();
> + 
> + 		if (current_row < 0 || current_row >= rows_size)
> + 			return 0;
> + 		
>   		return current_row + 1;
>   	}
>   
> Index: src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java,v
> retrieving revision 1.8
> diff -c -r1.8 JDBC2Tests.java
> *** src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java	2001/10/25 05:59:59	1.8
> --- src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java	2001/11/13 21:22:01
> ***************
> *** 205,210 ****
> --- 205,211 ----
>   		// Connectivity/Protocols
>   
>   		// ResultSet
> + 		suite.addTestSuite(ResultSetTest.class);
>   
>   		// Time, Date, Timestamp
>   		suite.addTestSuite(DateTest.class);
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
> 


Patch to fix getIndex for forte's transparent persistence

От:
"Dave Cramer" <dave@fastcrypt.com>
Дата:
Patch applied will It will be in beta3

Thanks,

Dave 

Index:
./pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
===================================================================
RCS file:
/projects/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Databas
eMetaData.java,v
retrieving revision 1.44
diff -c -r1.44 DatabaseMetaData.java
***
./pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
2001/11/09 02:57:50	1.44
---
./pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
2001/11/13 19:13:39
***************
*** 2903,2910 ****
  				tuple[0] = "".getBytes();
  				tuple[1] = "".getBytes();
  				tuple[2] = r.getBytes(1);
! 				tuple[3] = r.getBoolean(2) ?
"f".getBytes(): "t".getBytes();
! 				tuple[4] = null;
  				tuple[5] = r.getBytes(3);
  				tuple[6] = r.getBoolean(4) ?
 
Integer.toString(tableIndexClustered).getBytes():
--- 2903,2910 ----
  				tuple[0] = "".getBytes();
  				tuple[1] = "".getBytes();
  				tuple[2] = r.getBytes(1);
!                         tuple[3] = r.getBoolean(2) ?
"false".getBytes(): "true".getBytes();
!          	            tuple[4] = null;
  				tuple[5] = r.getBytes(3);
  				tuple[6] = r.getBoolean(4) ?
 
Integer.toString(tableIndexClustered).getBytes():
***************
*** 2913,2919 ****
 
Integer.toString(tableIndexOther).getBytes();
  				tuple[7] = Integer.toString(i +
1).getBytes();
  				java.sql.ResultSet columnNameRS =
connection.ExecSQL("select a.attname FROM pg_attribute a WHERE (a.attnum
= " + columnOrdinals[i] + ") AND (a.attrelid = " + r.getInt(9) + ")");
! 				columnNameRS.next();
  				tuple[8] = columnNameRS.getBytes(1);
  				tuple[9] = null;  // sort sequence ???
  				tuple[10] = r.getBytes(7);	//
inexact
--- 2913,2922 ----
 
Integer.toString(tableIndexOther).getBytes();
  				tuple[7] = Integer.toString(i +
1).getBytes();
  				java.sql.ResultSet columnNameRS =
connection.ExecSQL("select a.attname FROM pg_attribute a WHERE (a.attnum
= " + columnOrdinals[i] + ") AND (a.attrelid = " + r.getInt(9) + ")");
! 				if(columnNameRS.next())
!                                    tuple[8] =
columnNameRS.getBytes(1);
!                                 else
!                                    tuple[8] = "".getBytes();
  				tuple[8] = columnNameRS.getBytes(1);
  				tuple[9] = null;  // sort sequence ???
  				tuple[10] = r.getBytes(7);	//
inexact

FAQ