1010import org .postgresql .util .*;
1111
1212/**
13- * $Id: Connection.java,v 1.7 2000/10/08 19:37:54 momjian Exp $
13+ * $Id: Connection.java,v 1.8 2000/10/09 16:48:16 momjian Exp $
1414 *
1515 * This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
1616 * JDBC2 versions of the Connection class.
@@ -81,11 +81,6 @@ public abstract class Connection
8181// The PID an cancellation key we get from the backend process
8282public int pid ;
8383public int ckey ;
84-
85- // This receive_sbuf should be used by the different methods
86- // that call pg_stream.ReceiveString() in this Connection, so
87- // so we avoid uneccesary new allocations.
88- byte receive_sbuf [] =new byte [8192 ];
8984
9085/**
9186 * This is called by Class.forName() from within org.postgresql.Driver
@@ -169,9 +164,8 @@ protected void openConnection(String host, int port, Properties info, String dat
169164// The most common one to be thrown here is:
170165// "User authentication failed"
171166//
172- String msg =pg_stream .ReceiveString (receive_sbuf ,4096 ,
173- getEncoding ());
174- throw new SQLException (msg );
167+ throw new SQLException (pg_stream .ReceiveString
168+ (4096 ,getEncoding ()));
175169
176170case 'R' :
177171// Get the type of request
@@ -242,7 +236,7 @@ protected void openConnection(String host, int port, Properties info, String dat
242236case 'E' :
243237case 'N' :
244238throw new SQLException (pg_stream .ReceiveString
245- (receive_sbuf , 4096 ,getEncoding ()));
239+ (4096 ,getEncoding ()));
246240default :
247241throw new PSQLException ("postgresql.con.setup" );
248242 }
@@ -254,7 +248,7 @@ protected void openConnection(String host, int port, Properties info, String dat
254248break ;
255249case 'E' :
256250case 'N' :
257- throw new SQLException (pg_stream .ReceiveString (receive_sbuf , 4096 , getEncoding () ));
251+ throw new SQLException (pg_stream .ReceiveString (4096 ));
258252default :
259253throw new PSQLException ("postgresql.con.setup" );
260254 }
@@ -269,7 +263,7 @@ protected void openConnection(String host, int port, Properties info, String dat
269263//
270264firstWarning =null ;
271265
272- ExecSQL (null , "set datestyle to 'ISO'" );
266+ ExecSQL ("set datestyle to 'ISO'" );
273267
274268// Initialise object handling
275269initObjectTypes ();
@@ -312,27 +306,23 @@ public void addWarning(String msg)
312306//currentDateStyle=i+1; // this is the index of the format
313307//}
314308 }
315-
316-
309+
317310/**
318311 * Send a query to the backend. Returns one of the ResultSet
319312 * objects.
320313 *
321314 * <B>Note:</B> there does not seem to be any method currently
322315 * in existance to return the update count.
323316 *
324- * @param stmt The statment object.
325317 * @param sql the SQL statement to be executed
326318 * @return a ResultSet holding the results
327319 * @exception SQLException if a database error occurs
328320 */
329- public java .sql .ResultSet ExecSQL (PGStatement stmt ,
330- String sql )throws SQLException
321+ public java .sql .ResultSet ExecSQL (String sql )throws SQLException
331322 {
332323// added Oct 7 1998 to give us thread safety.
333324synchronized (pg_stream ) {
334- pg_stream .setExecutingStatement (stmt );
335-
325+
336326Field []fields =null ;
337327Vector tuples =new Vector ();
338328byte []buf =null ;
@@ -362,7 +352,8 @@ public java.sql.ResultSet ExecSQL(PGStatement stmt,
362352try
363353{
364354pg_stream .SendChar ('Q' );
365- pg_stream .Send (sql .getBytes ());
355+ buf =sql .getBytes ();
356+ pg_stream .Send (buf );
366357pg_stream .SendChar (0 );
367358pg_stream .flush ();
368359}catch (IOException e ) {
@@ -379,8 +370,7 @@ public java.sql.ResultSet ExecSQL(PGStatement stmt,
379370{
380371case 'A' :// Asynchronous Notify
381372pid =pg_stream .ReceiveInteger (4 );
382- msg =pg_stream .ReceiveString (receive_sbuf ,8192 ,
383- getEncoding ());
373+ msg =pg_stream .ReceiveString (8192 );
384374break ;
385375case 'B' :// Binary Data Transfer
386376if (fields ==null )
@@ -391,9 +381,7 @@ public java.sql.ResultSet ExecSQL(PGStatement stmt,
391381tuples .addElement (tup );
392382break ;
393383case 'C' :// Command Status
394- recv_status =
395- pg_stream .ReceiveString (receive_sbuf ,8192 ,
396- getEncoding ());
384+ recv_status =pg_stream .ReceiveString (8192 );
397385
398386// Now handle the update count correctly.
399387if (recv_status .startsWith ("INSERT" ) ||recv_status .startsWith ("UPDATE" ) ||recv_status .startsWith ("DELETE" )) {
@@ -435,8 +423,7 @@ public java.sql.ResultSet ExecSQL(PGStatement stmt,
435423tuples .addElement (tup );
436424break ;
437425case 'E' :// Error Message
438- msg =pg_stream .ReceiveString (receive_sbuf ,4096 ,
439- getEncoding ());
426+ msg =pg_stream .ReceiveString (4096 );
440427final_error =new SQLException (msg );
441428hfr =true ;
442429break ;
@@ -451,14 +438,10 @@ public java.sql.ResultSet ExecSQL(PGStatement stmt,
451438hfr =true ;
452439break ;
453440case 'N' :// Error Notification
454- addWarning (pg_stream .ReceiveString (receive_sbuf ,
455- 4096 ,
456- getEncoding ()));
441+ addWarning (pg_stream .ReceiveString (4096 ));
457442break ;
458443case 'P' :// Portal Name
459- String pname =
460- pg_stream .ReceiveString (receive_sbuf ,8192 ,
461- getEncoding ());
444+ String pname =pg_stream .ReceiveString (8192 );
462445break ;
463446case 'T' :// MetaData Field Description
464447if (fields !=null )
@@ -478,8 +461,6 @@ public java.sql.ResultSet ExecSQL(PGStatement stmt,
478461}
479462 }
480463
481-
482-
483464/**
484465 * Receive the field descriptions from the back end
485466 *
@@ -493,8 +474,7 @@ private Field[] ReceiveFields() throws SQLException
493474
494475for (i =0 ;i <nf ; ++i )
495476 {
496- String typname =pg_stream .ReceiveString (receive_sbuf ,8192 ,
497- getEncoding ());
477+ String typname =pg_stream .ReceiveString (8192 );
498478int typid =pg_stream .ReceiveIntegerR (4 );
499479int typlen =pg_stream .ReceiveIntegerR (2 );
500480int typmod =pg_stream .ReceiveIntegerR (4 );