11
11
import org .postgresql .core .*;
12
12
13
13
/*
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 $
15
15
*
16
16
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
17
17
* JDBC2 versions of the Connection class.
@@ -91,6 +91,40 @@ public abstract class Connection
91
91
public Connection ()
92
92
{}
93
93
94
+ public void cancelQuery () throws SQLException
95
+ {
96
+ PG_Stream cancelStream = null ;
97
+ try {
98
+ cancelStream = new PG_Stream (PG_HOST , PG_PORT );
99
+ } catch (ConnectException cex ) {
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
+ throw new PSQLException ("postgresql.con.refused" );
104
+ } catch (IOException e ) {
105
+ throw new PSQLException ("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 (IOException e ) {
117
+ throw new PSQLException ("postgresql.con.failed" ,e );
118
+ }
119
+ finally {
120
+ try {
121
+ if (cancelStream != null )
122
+ cancelStream .close ();
123
+ }
124
+ catch (IOException e ) {} // Ignore
125
+ }
126
+ }
127
+
94
128
/*
95
129
* This method actually opens the connection. It is called by Driver.
96
130
*
@@ -266,8 +300,8 @@ protected void openConnection(String host, int port, Properties info, String dat
266
300
switch (beresp )
267
301
{
268
302
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 );
271
305
break ;
272
306
case 'E' :
273
307
case 'N' :
@@ -281,6 +315,16 @@ protected void openConnection(String host, int port, Properties info, String dat
281
315
switch (beresp )
282
316
{
283
317
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 (IOException e ) {
326
+ throw new PSQLException ("postgresql.con.ioerror" ,e );
327
+ }
284
328
break ;
285
329
case 'E' :
286
330
case 'N' :
@@ -448,6 +492,7 @@ public String getURL() throws SQLException
448
492
* @return the user name
449
493
* @exception SQLException just in case...
450
494
*/
495
+ int lastMessage = 0 ;
451
496
public String getUserName () throws SQLException
452
497
{
453
498
return PG_USER ;
0 commit comments