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

Commit7776319

Browse files
author
Dave Cramer
committed
Implementation for cancelQuery by Grant Finnemore <grantf@guruhut.co.za>
1 parent29e3ef0 commit7776319

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

‎src/interfaces/jdbc/org/postgresql/Connection.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
importorg.postgresql.core.*;
1212

1313
/*
14-
* $Id: Connection.java,v 1.40 2001/12/11 04:44:23 barry Exp $
14+
* $Id: Connection.java,v 1.41 2002/02/26 02:15:54 davec Exp $
1515
*
1616
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
1717
* JDBC2 versions of the Connection class.
@@ -91,6 +91,40 @@ public abstract class Connection
9191
publicConnection()
9292
{}
9393

94+
publicvoidcancelQuery()throwsSQLException
95+
{
96+
PG_StreamcancelStream =null;
97+
try {
98+
cancelStream =newPG_Stream(PG_HOST,PG_PORT);
99+
}catch (ConnectExceptioncex) {
100+
// Added by Peter Mount <peter@retep.org.uk>
101+
// ConnectException is thrown when the connection cannot be made.
102+
// we trap this an return a more meaningful message for the end user
103+
thrownewPSQLException ("postgresql.con.refused");
104+
}catch (IOExceptione) {
105+
thrownewPSQLException ("postgresql.con.failed",e);
106+
}
107+
108+
// Now we need to construct and send a cancel packet
109+
try {
110+
cancelStream.SendInteger(16,4);
111+
cancelStream.SendInteger(80877102,4);
112+
cancelStream.SendInteger(pid,4);
113+
cancelStream.SendInteger(ckey,4);
114+
cancelStream.flush();
115+
}
116+
catch(IOExceptione) {
117+
thrownewPSQLException("postgresql.con.failed",e);
118+
}
119+
finally {
120+
try {
121+
if(cancelStream !=null)
122+
cancelStream.close();
123+
}
124+
catch(IOExceptione) {}// Ignore
125+
}
126+
}
127+
94128
/*
95129
* This method actually opens the connection. It is called by Driver.
96130
*
@@ -266,8 +300,8 @@ protected void openConnection(String host, int port, Properties info, String dat
266300
switch (beresp)
267301
{
268302
case'K':
269-
pid =pg_stream.ReceiveInteger(4);
270-
ckey =pg_stream.ReceiveInteger(4);
303+
pid =pg_stream.ReceiveIntegerR(4);
304+
ckey =pg_stream.ReceiveIntegerR(4);
271305
break;
272306
case'E':
273307
case'N':
@@ -281,6 +315,16 @@ protected void openConnection(String host, int port, Properties info, String dat
281315
switch (beresp)
282316
{
283317
case'Z':
318+
319+
try
320+
{
321+
pg_stream.SendChar('Q');
322+
pg_stream.SendChar(' ');
323+
pg_stream.SendChar(0);
324+
pg_stream.flush();
325+
}catch (IOExceptione) {
326+
thrownewPSQLException("postgresql.con.ioerror",e);
327+
}
284328
break;
285329
case'E':
286330
case'N':
@@ -448,6 +492,7 @@ public String getURL() throws SQLException
448492
* @return the user name
449493
* @exception SQLException just in case...
450494
*/
495+
intlastMessage =0;
451496
publicStringgetUserName()throwsSQLException
452497
{
453498
returnPG_USER;

‎src/interfaces/jdbc/org/postgresql/Statement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void clearWarnings() throws SQLException
179179
*/
180180
publicvoidcancel()throwsSQLException
181181
{
182-
// FIXME: Cancel feature has been available since 6.4. Implement it here!
182+
thrownewPSQLException("postgresql.unimplemented");
183183
}
184184

185185
/*

‎src/interfaces/jdbc/org/postgresql/jdbc2/Statement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ public int[] executeBatch() throws SQLException
211211
returnresult;
212212
}
213213

214+
publicvoidCancel()throwsSQLException
215+
{
216+
connection.cancelQuery();
217+
}
218+
214219
publicjava.sql.ConnectiongetConnection()throwsSQLException
215220
{
216221
return (java.sql.Connection)connection;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp