Index: org/postgresql/errors.properties
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/errors.properties,v
retrieving revision 1.22
diff -c -p -r1.22 errors.properties
*** org/postgresql/errors.properties	9 Jul 2003 05:12:03 -0000	1.22
--- org/postgresql/errors.properties	30 Jul 2003 14:31:01 -0000
*************** postgresql.input.rows.gt0:Maximum number
*** 103,105 ****
--- 103,106 ----
  postgresql.format.baddate:The date given: {0} does not match the format required: {1}.
  postgresql.format.badtime:The time given: {0} does not match the format required: {1}.
  postgresql.format.badtimestamp:The timestamp given {0} does not match the format required: {1}.
+ postgresql.fetchdir.invalid:The fetch direction given is not valid.
Index: org/postgresql/core/BaseStatement.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/core/BaseStatement.java,v
retrieving revision 1.3
diff -c -p -r1.3 BaseStatement.java
*** org/postgresql/core/BaseStatement.java	7 May 2003 03:03:30 -0000	1.3
--- org/postgresql/core/BaseStatement.java	30 Jul 2003 14:31:01 -0000
*************** public interface BaseStatement extends o
*** 31,36 ****
--- 31,37 ----
  	public void addWarning(String p_warning) throws SQLException;
  	public int getFetchSize() throws SQLException;
  	public int getMaxRows() throws SQLException;
+ 	public int getFetchDirection() throws SQLException;
  	public int getResultSetConcurrency() throws SQLException;
  	public String getStatementName();
  
Index: org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java,v
retrieving revision 1.13
diff -c -p -r1.13 AbstractJdbc1ResultSet.java
*** org/postgresql/jdbc1/AbstractJdbc1ResultSet.java	30 Jun 2003 21:10:55 -0000	1.13
--- org/postgresql/jdbc1/AbstractJdbc1ResultSet.java	30 Jul 2003 14:31:02 -0000
*************** public abstract class AbstractJdbc1Resul
*** 55,64 ****
--- 55,69 ----
  
  	private StringBuffer sbuf = null;
  	public byte[][] rowBuffer = null;
+ 	
+ 	protected int fetchDirection = ResultSet.FETCH_FORWARD;
  
   	private SimpleDateFormat m_tsFormat = null;
   	private SimpleDateFormat m_tstzFormat = null;
   	private SimpleDateFormat m_dateFormat = null;
+ 	
+ 	protected int maxfetchSize = 0; 	// The check to see what the maxFetchSize is when the Statement created it.
+ 	protected int currentFetchSize = 0;
  
  	public abstract ResultSetMetaData getMetaData() throws SQLException;
  
*************** public abstract class AbstractJdbc1Resul
*** 81,86 ****
--- 86,104 ----
  		this.this_row = null;
  		this.current_row = -1;
  		this.binaryCursor = binaryCursor;
+ 		try
+ 		{
+ 			this.fetchDirection = statement.getFetchDirection();
+ 			this.maxfetchSize = statement.getFetchSize();
+ 			this.currentFetchSize = this.maxfetchSize;
+ 		}
+ 		catch (SQLException e)
+ 		{
+ 			System.out.println("Exception thrown in constructor");
+ 			this.fetchDirection = ResultSet.FETCH_FORWARD;
+ 			this.maxfetchSize = 0;
+ 			this.currentFetchSize = 0;
+ 		}
  	}
  
      public BaseStatement getPGStatement() {
*************** public abstract class AbstractJdbc1Resul
*** 119,125 ****
  
  		if (++current_row >= rows.size())
  		{
! 			int fetchSize = statement.getFetchSize();
  			// Must be false if we weren't batching.
  			if (fetchSize == 0)
  				return false;
--- 137,143 ----
  
  		if (++current_row >= rows.size())
  		{
! 			int fetchSize = currentFetchSize;
  			// Must be false if we weren't batching.
  			if (fetchSize == 0)
  				return false;
*************** public abstract class AbstractJdbc1Resul
*** 131,141 ****
  			String[] binds = new String[0];
  			// Is this the correct query???
  			String cursorName = statement.getStatementName();
! 			sql[0] = "FETCH FORWARD " + fetchSize + " FROM " + cursorName;
  			QueryExecutor.execute(sql,
  								  binds,
  								  this);
- 
  			// Test the new rows array.
  			if (rows.size() == 0)
  				return false;
--- 149,159 ----
  			String[] binds = new String[0];
  			// Is this the correct query???
  			String cursorName = statement.getStatementName();
! 			String sfetchDir = (fetchDirection == ResultSet.FETCH_REVERSE) ? "BACKWARD " : "FORWARD ";
! 			sql[0] = "FETCH "+ sfetchDir + fetchSize + " FROM " + cursorName;
  			QueryExecutor.execute(sql,
  								  binds,
  								  this);
  			// Test the new rows array.
  			if (rows.size() == 0)
  				return false;
Index: org/postgresql/jdbc1/AbstractJdbc1Statement.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v
retrieving revision 1.29
diff -c -p -r1.29 AbstractJdbc1Statement.java
*** org/postgresql/jdbc1/AbstractJdbc1Statement.java	24 Jul 2003 00:30:39 -0000	1.29
--- org/postgresql/jdbc1/AbstractJdbc1Statement.java	30 Jul 2003 14:31:03 -0000
*************** public abstract class AbstractJdbc1State
*** 43,48 ****
--- 43,49 ----
  
  	/** Number of rows to get in a batch. */
  	protected int fetchSize = 0;
+ 	protected int fetchDirection = ResultSet.FETCH_FORWARD;
  
  	/** Timeout (in seconds) for a query (not used) */
  	protected int timeout = 0;
*************** public abstract class AbstractJdbc1State
*** 110,116 ****
  		return m_statementName;
  	}
  
! 	public int getFetchSize() throws SQLException {
  		return fetchSize;
  	}
  
--- 111,118 ----
  		return m_statementName;
  	}
  
! 	public int getFetchSize() throws SQLException 
! 	{
  		return fetchSize;
  	}
  
*************** public abstract class AbstractJdbc1State
*** 379,385 ****
                          // Note that we don't need a BEGIN because we've already
                          // made sure we're executing inside a transaction.
                          String cursDecl = "DECLARE " + statementName + " CURSOR FOR ";
!                         String endCurs = " FETCH FORWARD " + fetchSize + " FROM " + statementName + ";";
  
                          // Copy the real query to the curs decleration.
                          try
--- 381,388 ----
                          // Note that we don't need a BEGIN because we've already
                          // made sure we're executing inside a transaction.
                          String cursDecl = "DECLARE " + statementName + " CURSOR FOR ";
! 			String sfetchdir = (fetchDirection == ResultSet.FETCH_REVERSE) ? "BACKWARD " : "FORWARD ";
!                         String endCurs = " FETCH " + sfetchdir + fetchSize + " FROM " + statementName + ";";
  
                          // Copy the real query to the curs decleration.
                          try
*************** public abstract class AbstractJdbc1State
*** 2184,2189 ****
--- 2187,2197 ----
  		java.sql.Timestamp tmpts = new java.sql.Timestamp(millis);
  		tmpts.setNanos(nanosVal);
  		return tmpts;
+ 	}
+ 	
+ 	public int getFetchDirection() throws SQLException
+ 	{
+ 		return fetchDirection;
  	}
  			
  	
Index: org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v
retrieving revision 1.20
diff -c -p -r1.20 AbstractJdbc2ResultSet.java
*** org/postgresql/jdbc2/AbstractJdbc2ResultSet.java	30 Jun 2003 16:38:30 -0000	1.20
--- org/postgresql/jdbc2/AbstractJdbc2ResultSet.java	30 Jul 2003 14:31:04 -0000
*************** public abstract class AbstractJdbc2Resul
*** 382,395 ****
  	public int getFetchDirection() throws SQLException
  	{
  		//PostgreSQL normally sends rows first->last
! 		return java.sql.ResultSet.FETCH_FORWARD;
  	}
  
  
  	public int getFetchSize() throws SQLException
  	{
  		// Returning the current batch size seems the right thing to do.
! 		return rows.size();
  	}
  
  
--- 382,395 ----
  	public int getFetchDirection() throws SQLException
  	{
  		//PostgreSQL normally sends rows first->last
! 		return fetchDirection;
  	}
  
  
  	public int getFetchSize() throws SQLException
  	{
  		// Returning the current batch size seems the right thing to do.
! 		return currentFetchSize;
  	}
  
  
*************** public abstract class AbstractJdbc2Resul
*** 511,524 ****
  
  	public void setFetchDirection(int direction) throws SQLException
  	{
! 		throw new PSQLException("postgresql.psqlnotimp");
  	}
  
  
  	public void setFetchSize(int rows) throws SQLException
  	{
! 		// Sub-classes should implement this as part of their cursor support
! 		throw org.postgresql.Driver.notImplemented();
  	}
  
  
--- 511,527 ----
  
  	public void setFetchDirection(int direction) throws SQLException
  	{
! 		if (direction != ResultSet.FETCH_FORWARD && direction != ResultSet.FETCH_REVERSE && direction != ResultSet.FETCH_UNKNOWN)
! 			throw new PSQLException("postgresql.fetchdir.invalid");
! 		fetchDirection = direction;
  	}
  
  
  	public void setFetchSize(int rows) throws SQLException
  	{
! 		if (rows > maxfetchSize || rows < 0)
! 			throw new PSQLException("postgresql.invalid.fetchsize");
! 		currentFetchSize = rows;
  	}
  
  
Index: org/postgresql/jdbc2/AbstractJdbc2Statement.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v
retrieving revision 1.15
diff -c -p -r1.15 AbstractJdbc2Statement.java
*** org/postgresql/jdbc2/AbstractJdbc2Statement.java	30 Jun 2003 16:38:30 -0000	1.15
--- org/postgresql/jdbc2/AbstractJdbc2Statement.java	30 Jul 2003 14:31:05 -0000
*************** public abstract class AbstractJdbc2State
*** 127,137 ****
  		return (Connection) connection;
  	}
  
- 	public int getFetchDirection() throws SQLException
- 	{
- 		throw new PSQLException("postgresql.psqlnotimp");
- 	}
- 
  	public int getResultSetConcurrency() throws SQLException
  	{
  		return concurrency;
--- 127,132 ----
*************** public abstract class AbstractJdbc2State
*** 144,152 ****
  
  	public void setFetchDirection(int direction) throws SQLException
  	{
! 		// I don't think this should happen, since it's a hint it should just
! 		// fail quietly.
! 		//   throw Driver.notImplemented();
  	}
  
  	public void setFetchSize(int rows) throws SQLException
--- 139,147 ----
  
  	public void setFetchDirection(int direction) throws SQLException
  	{
! 		if (direction != ResultSet.FETCH_FORWARD && direction != ResultSet.FETCH_REVERSE && direction != ResultSet.FETCH_UNKNOWN)
! 			throw new PSQLException("postgresql.fetchdir.invalid");
! 		fetchDirection = direction;
  	}
  
  	public void setFetchSize(int rows) throws SQLException
