Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7ecb6ed

Browse files
author
Dave Cramer
committed
Patches from Oliver Jowett to fix CursorFetchTest, 7.4 now does not automatically delete cursors
1 parent 15c6764 commit 7ecb6ed

File tree

7 files changed

+416
-235
lines changed

7 files changed

+416
-235
lines changed

src/interfaces/jdbc/org/postgresql/core/BaseConnection.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2003, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseConnection.java,v 1.3 2003/05/29 03:21:32 barry Exp $
9+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseConnection.java,v 1.4 2003/10/29 02:39:09 davec Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -26,7 +26,7 @@ public interface BaseConnection extends PGConnection
2626
public void cancelQuery() throws SQLException;
2727
public Statement createStatement() throws SQLException;
2828
public BaseResultSet execSQL(String s) throws SQLException;
29-
public boolean getAutoCommit() throws SQLException;
29+
public boolean getAutoCommit();
3030
public String getCursorName() throws SQLException;
3131
public Encoding getEncoding() throws SQLException;
3232
public DatabaseMetaData getMetaData() throws SQLException;

src/interfaces/jdbc/org/postgresql/core/BaseStatement.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2003, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseStatement.java,v 1.5 2003/08/24 22:10:09 barry Exp $
9+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseStatement.java,v 1.6 2003/10/29 02:39:09 davec Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -30,11 +30,11 @@ public interface BaseStatement extends org.postgresql.PGStatement
3030
*/
3131
public void addWarning(String p_warning) throws SQLException;
3232
public void close() throws SQLException;
33-
public int getFetchSize() throws SQLException;
33+
public int getFetchSize();
3434
public int getMaxFieldSize() throws SQLException;
3535
public int getMaxRows() throws SQLException;
3636
public int getResultSetConcurrency() throws SQLException;
37-
public String getStatementName();
37+
public String getFetchingCursorName();
3838
public SQLWarning getWarnings() throws SQLException;
3939
public void setMaxFieldSize(int max) throws SQLException;
4040

src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Copyright (c) 2003, PostgreSQL Global Development Group
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.26 2003/09/13 04:02:15 barry Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.27 2003/10/29 02:39:09 davec Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -1270,10 +1270,9 @@ public void setAutoCommit(boolean autoCommit) throws SQLException
12701270
* gets the current auto-commit state
12711271
*
12721272
* @return Current state of the auto-commit mode
1273-
* @exception SQLException (why?)
12741273
* @see setAutoCommit
12751274
*/
1276-
public boolean getAutoCommit() throws SQLException
1275+
public boolean getAutoCommit()
12771276
{
12781277
return this.autoCommit;
12791278
}

src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java

+46-25
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Copyright (c) 2003, PostgreSQL Global Development Group
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.21 2003/09/22 04:54:59 barry Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.22 2003/10/29 02:39:09 davec Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -61,6 +61,9 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
6161
private SimpleDateFormat m_tstzFormat = null;
6262
private SimpleDateFormat m_dateFormat = null;
6363

64+
private int fetchSize; // Fetch size for next read (might be 0).
65+
private int lastFetchSize; // Fetch size of last read (might be 0).
66+
6467
public abstract ResultSetMetaData getMetaData() throws SQLException;
6568

6669
public AbstractJdbc1ResultSet(BaseStatement statement,
@@ -82,6 +85,8 @@ public AbstractJdbc1ResultSet(BaseStatement statement,
8285
this.this_row = null;
8386
this.current_row = -1;
8487
this.binaryCursor = binaryCursor;
88+
89+
this.lastFetchSize = this.fetchSize = (statement == null ? 0 : statement.getFetchSize());
8590
}
8691

8792
public BaseStatement getPGStatement() {
@@ -111,7 +116,21 @@ public void reInit (Field[] fields, Vector tuples, String status,
111116
this.current_row = -1;
112117
this.binaryCursor = binaryCursor;
113118
}
119+
120+
//
121+
// Part of the JDBC2 support, but convenient to implement here.
122+
//
114123

124+
public void setFetchSize(int rows) throws SQLException
125+
{
126+
fetchSize = rows;
127+
}
128+
129+
130+
public int getFetchSize() throws SQLException
131+
{
132+
return fetchSize;
133+
}
115134

116135
public boolean next() throws SQLException
117136
{
@@ -120,30 +139,32 @@ public boolean next() throws SQLException
120139

121140
if (++current_row >= rows.size())
122141
{
123-
int fetchSize = statement.getFetchSize();
124-
// Must be false if we weren't batching.
125-
if (fetchSize == 0)
126-
return false;
127-
// Use the ref to the statement to get
128-
// the details we need to do another cursor
129-
// query - it will use reinit() to repopulate this
130-
// with the right data.
131-
String[] sql = new String[1];
132-
String[] binds = new String[0];
133-
// Is this the correct query???
134-
String cursorName = statement.getStatementName();
135-
//if cursorName is null, we are not batching (likely because the
136-
//query itself can't be batched)
137-
if (cursorName == null)
138-
return false;
139-
sql[0] = "FETCH FORWARD " + fetchSize + " FROM " + cursorName;
140-
QueryExecutor.execute(sql,
141-
binds,
142-
this);
143-
144-
// Test the new rows array.
145-
if (rows.size() == 0)
146-
return false;
142+
String cursorName = statement.getFetchingCursorName();
143+
if (cursorName == null || lastFetchSize == 0 || rows.size() < lastFetchSize)
144+
return false; // Not doing a cursor-based fetch or the last fetch was the end of the query
145+
146+
// Use the ref to the statement to get
147+
// the details we need to do another cursor
148+
// query - it will use reinit() to repopulate this
149+
// with the right data.
150+
151+
// NB: We can reach this point with fetchSize == 0
152+
// if the fetch size is changed halfway through reading results.
153+
// Use "FETCH FORWARD ALL" in that case to complete the query.
154+
String[] sql = new String[] {
155+
fetchSize == 0 ? ("FETCH FORWARD ALL FROM " + cursorName) :
156+
("FETCH FORWARD " + fetchSize + " FROM " + cursorName)
157+
};
158+
159+
QueryExecutor.execute(sql,
160+
new String[0],
161+
this);
162+
163+
// Test the new rows array.
164+
lastFetchSize = fetchSize;
165+
if (rows.size() == 0)
166+
return false;
167+
147168
// Otherwise reset the counter and let it go on...
148169
current_row = 0;
149170
}

0 commit comments

Comments
 (0)