Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16a3034

Browse files
author
Barry Lind
committed
Patch from Nic Ferrier to add support for result sets being cursor based
so that rows can be fetched incrementally. This is enabled by usingsetFetchSize()
1 parent2d1f940 commit16a3034

26 files changed

+428
-231
lines changed

‎src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,80 @@
66
importjava.sql.*;
77
importorg.postgresql.*;
88
importorg.postgresql.util.PSQLException;
9+
importorg.postgresql.jdbc1.AbstractJdbc1Connection;
10+
importorg.postgresql.jdbc1.AbstractJdbc1ResultSet;
11+
importorg.postgresql.jdbc1.AbstractJdbc1Statement;
912

1013
/*
1114
* Executes a query on the backend.
1215
*
1316
* <p>The lifetime of a QueryExecutor object is from sending the query
1417
* until the response has been received from the backend.
1518
*
16-
* $Id: QueryExecutor.java,v 1.17 2002/11/14 05:35:45 barry Exp $
19+
* $Id: QueryExecutor.java,v 1.18 2003/02/04 09:20:08 barry Exp $
1720
*/
1821

1922
publicclassQueryExecutor
2023
{
24+
//This version of execute does not take an existing result set, but
25+
//creates a new one for the results of the query
26+
publicstaticResultSetexecute (String[]p_sqlFrags,
27+
Object[]p_binds,
28+
java.sql.Statementstatement)
29+
throwsSQLException
30+
{
31+
QueryExecutorqe =newQueryExecutor();
32+
qe.m_sqlFrags =p_sqlFrags;
33+
qe.m_binds =p_binds;
34+
qe.statement =statement;
35+
if (statement !=null)
36+
qe.maxRows =statement.getMaxRows();
37+
else
38+
qe.maxRows =0;
2139

22-
privatefinalString[]m_sqlFrags;
23-
privatefinalObject[]m_binds;
24-
privatefinaljava.sql.Statementstatement;
25-
privatefinalPG_Streampg_stream;
26-
privatefinalorg.postgresql.jdbc1.AbstractJdbc1Connectionconnection;
40+
qe.connection = (AbstractJdbc1Connection)((AbstractJdbc1Statement)statement).getPGConnection();
41+
qe.pg_stream =qe.connection.getPGStream();
2742

28-
publicQueryExecutor(String[]p_sqlFrags,Object[]p_binds,
29-
java.sql.Statementstatement,
30-
PG_Streampg_stream,
31-
java.sql.Connectionconnection)
43+
returnqe.execute();
44+
}
45+
46+
//This version of execute reuses an existing result set for the query
47+
//results, this is used when a result set is backed by a cursor and
48+
//more results are fetched
49+
publicstaticvoidexecute (String[]p_sqlFrags,
50+
Object[]p_binds,
51+
java.sql.ResultSetrs)
3252
throwsSQLException
3353
{
34-
this.m_sqlFrags =p_sqlFrags;
35-
this.m_binds =p_binds;
36-
this.statement =statement;
37-
this.pg_stream =pg_stream;
38-
this.connection = (org.postgresql.jdbc1.AbstractJdbc1Connection)connection;
39-
40-
if (statement !=null)
41-
maxRows =statement.getMaxRows();
54+
QueryExecutorqe =newQueryExecutor();
55+
qe.m_sqlFrags =p_sqlFrags;
56+
qe.m_binds =p_binds;
57+
qe.rs =rs;
58+
qe.statement = (java.sql.Statement)((AbstractJdbc1ResultSet)qe.rs).getPGStatement();
59+
if (qe.statement !=null)
60+
qe.maxRows =qe.statement.getMaxRows();
4261
else
43-
maxRows =0;
62+
qe.maxRows =0;
63+
64+
qe.connection = (AbstractJdbc1Connection)((AbstractJdbc1Statement)qe.statement).getPGConnection();
65+
qe.pg_stream =qe.connection.getPGStream();
66+
67+
qe.execute();
4468
}
4569

70+
71+
privateQueryExecutor ()
72+
{
73+
}
74+
75+
privateString[]m_sqlFrags;
76+
privateObject[]m_binds;
77+
privatejava.sql.Statementstatement;
78+
privatejava.sql.ResultSetrs;
79+
80+
privateAbstractJdbc1Connectionconnection;
81+
privatePG_Streampg_stream;
82+
4683
privateField[]fields =null;
4784
privateVectortuples =newVector();
4885
privatebooleanbinaryCursor =false;
@@ -51,10 +88,12 @@ public QueryExecutor(String[] p_sqlFrags, Object[] p_binds,
5188
privatelonginsert_oid =0;
5289
privateintmaxRows;
5390

91+
5492
/*
5593
* Execute a query on the backend.
94+
*
5695
*/
57-
publicjava.sql.ResultSetexecute()throwsSQLException
96+
privatejava.sql.ResultSetexecute()throwsSQLException
5897
{
5998

6099
StringBuffererrorMessage =null;
@@ -130,7 +169,18 @@ public java.sql.ResultSet execute() throws SQLException
130169
if (errorMessage !=null )
131170
thrownewSQLException(errorMessage.toString() );
132171

133-
returnconnection.getResultSet(statement,fields,tuples,status,update_count,insert_oid,binaryCursor);
172+
173+
//if an existing result set was passed in reuse it, else
174+
//create a new one
175+
if (rs !=null)
176+
{
177+
((org.postgresql.jdbc1.AbstractJdbc1ResultSet)rs).reInit(fields,tuples,status,update_count,insert_oid,binaryCursor);
178+
}
179+
else
180+
{
181+
rs = ((AbstractJdbc1Statement)statement).createResultSet(fields,tuples,status,update_count,insert_oid,binaryCursor);
182+
}
183+
returnrs;
134184
}
135185
}
136186

@@ -145,10 +195,12 @@ private void sendQuery() throws SQLException
145195
for (inti =0 ;i <m_binds.length ; ++i)
146196
{
147197
if (m_binds[i] ==null)
148-
thrownewPSQLException("postgresql.prep.param",newInteger(i +1));
198+
thrownewPSQLException("postgresql.prep.param (" +i +")",newInteger(i +1));
199+
149200
pg_stream.Send(connection.getEncoding().encode(m_sqlFrags[i]));
150201
pg_stream.Send(connection.getEncoding().encode(m_binds[i].toString()));
151202
}
203+
152204
pg_stream.Send(connection.getEncoding().encode(m_sqlFrags[m_binds.length]));
153205
pg_stream.SendChar(0);
154206
pg_stream.flush();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp