|
8 | 8 | import org.postgresql.fastpath.*;
|
9 | 9 | import org.postgresql.largeobject.*;
|
10 | 10 | import org.postgresql.util.*;
|
11 |
| -import org.postgresql.core.Encoding; |
| 11 | +import org.postgresql.core.*; |
12 | 12 |
|
13 | 13 | /**
|
14 |
| - * $Id: Connection.java,v 1.26 2001/08/24 16:50:12 momjian Exp $ |
| 14 | + * $Id: Connection.java,v 1.27 2001/09/06 03:13:34 momjian 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.
|
@@ -348,166 +348,9 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
|
348 | 348 | * @return a ResultSet holding the results
|
349 | 349 | * @exception SQLException if a database error occurs
|
350 | 350 | */
|
351 |
| - public java.sql.ResultSet ExecSQL(String sql,java.sql.Statement stat) throws SQLException |
| 351 | + public java.sql.ResultSet ExecSQL(String sql, java.sql.Statement stat) throws SQLException |
352 | 352 | {
|
353 |
| - // added Jan 30 2001 to correct maxrows per statement |
354 |
| - int maxrows=0; |
355 |
| - if(stat!=null) |
356 |
| - maxrows=stat.getMaxRows(); |
357 |
| - |
358 |
| - // added Oct 7 1998 to give us thread safety. |
359 |
| - synchronized(pg_stream) { |
360 |
| - // Deallocate all resources in the stream associated |
361 |
| - // with a previous request. |
362 |
| - // This will let the driver reuse byte arrays that has already |
363 |
| - // been allocated instead of allocating new ones in order |
364 |
| - // to gain performance improvements. |
365 |
| - // PM 17/01/01: Commented out due to race bug. See comments in |
366 |
| - // PG_Stream |
367 |
| - //pg_stream.deallocate(); |
368 |
| - |
369 |
| - Field[] fields = null; |
370 |
| - Vector tuples = new Vector(); |
371 |
| - byte[] buf = null; |
372 |
| - int fqp = 0; |
373 |
| - boolean hfr = false; |
374 |
| - String recv_status = null, msg; |
375 |
| - int update_count = 1; |
376 |
| - int insert_oid = 0; |
377 |
| - SQLException final_error = null; |
378 |
| - |
379 |
| - buf = encoding.encode(sql); |
380 |
| - try |
381 |
| - { |
382 |
| - pg_stream.SendChar('Q'); |
383 |
| - pg_stream.Send(buf); |
384 |
| - pg_stream.SendChar(0); |
385 |
| - pg_stream.flush(); |
386 |
| - } catch (IOException e) { |
387 |
| - throw new PSQLException("postgresql.con.ioerror",e); |
388 |
| - } |
389 |
| - |
390 |
| - while (!hfr || fqp > 0) |
391 |
| - { |
392 |
| - Object tup=null; // holds rows as they are recieved |
393 |
| - |
394 |
| - int c = pg_stream.ReceiveChar(); |
395 |
| - |
396 |
| - switch (c) |
397 |
| - { |
398 |
| - case 'A': // Asynchronous Notify |
399 |
| - pid = pg_stream.ReceiveInteger(4); |
400 |
| - msg = pg_stream.ReceiveString(encoding); |
401 |
| - break; |
402 |
| - case 'B': // Binary Data Transfer |
403 |
| - if (fields == null) |
404 |
| - throw new PSQLException("postgresql.con.tuple"); |
405 |
| - tup = pg_stream.ReceiveTuple(fields.length, true); |
406 |
| - // This implements Statement.setMaxRows() |
407 |
| - if(maxrows==0 || tuples.size()<maxrows) |
408 |
| - tuples.addElement(tup); |
409 |
| - break; |
410 |
| - case 'C': // Command Status |
411 |
| - recv_status = pg_stream.ReceiveString(encoding); |
412 |
| - |
413 |
| - // Now handle the update count correctly. |
414 |
| - if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE") || recv_status.startsWith("DELETE") || recv_status.startsWith("MOVE")) { |
415 |
| - try { |
416 |
| - update_count = Integer.parseInt(recv_status.substring(1+recv_status.lastIndexOf(' '))); |
417 |
| - } catch(NumberFormatException nfe) { |
418 |
| - throw new PSQLException("postgresql.con.fathom",recv_status); |
419 |
| - } |
420 |
| - if(recv_status.startsWith("INSERT")) { |
421 |
| - try { |
422 |
| - insert_oid = Integer.parseInt(recv_status.substring(1+recv_status.indexOf(' '),recv_status.lastIndexOf(' '))); |
423 |
| - } catch(NumberFormatException nfe) { |
424 |
| - throw new PSQLException("postgresql.con.fathom",recv_status); |
425 |
| - } |
426 |
| - } |
427 |
| - } |
428 |
| - if (fields != null) |
429 |
| - hfr = true; |
430 |
| - else |
431 |
| - { |
432 |
| - try |
433 |
| - { |
434 |
| - pg_stream.SendChar('Q'); |
435 |
| - pg_stream.SendChar(' '); |
436 |
| - pg_stream.SendChar(0); |
437 |
| - pg_stream.flush(); |
438 |
| - } catch (IOException e) { |
439 |
| - throw new PSQLException("postgresql.con.ioerror",e); |
440 |
| - } |
441 |
| - fqp++; |
442 |
| - } |
443 |
| - break; |
444 |
| - case 'D': // Text Data Transfer |
445 |
| - if (fields == null) |
446 |
| - throw new PSQLException("postgresql.con.tuple"); |
447 |
| - tup = pg_stream.ReceiveTuple(fields.length, false); |
448 |
| - // This implements Statement.setMaxRows() |
449 |
| - if(maxrows==0 || tuples.size()<maxrows) |
450 |
| - tuples.addElement(tup); |
451 |
| - break; |
452 |
| - case 'E': // Error Message |
453 |
| - msg = pg_stream.ReceiveString(encoding); |
454 |
| - final_error = new SQLException(msg); |
455 |
| - hfr = true; |
456 |
| - break; |
457 |
| - case 'I': // Empty Query |
458 |
| - int t = pg_stream.ReceiveChar(); |
459 |
| - |
460 |
| - if (t != 0) |
461 |
| - throw new PSQLException("postgresql.con.garbled"); |
462 |
| - if (fqp > 0) |
463 |
| - fqp--; |
464 |
| - if (fqp == 0) |
465 |
| - hfr = true; |
466 |
| - break; |
467 |
| - case 'N': // Error Notification |
468 |
| - addWarning(pg_stream.ReceiveString(encoding)); |
469 |
| - break; |
470 |
| - case 'P': // Portal Name |
471 |
| - String pname = pg_stream.ReceiveString(encoding); |
472 |
| - break; |
473 |
| - case 'T': // MetaData Field Description |
474 |
| - if (fields != null) |
475 |
| - throw new PSQLException("postgresql.con.multres"); |
476 |
| - fields = ReceiveFields(); |
477 |
| - break; |
478 |
| - case 'Z': // backend ready for query, ignore for now :-) |
479 |
| - break; |
480 |
| - default: |
481 |
| - throw new PSQLException("postgresql.con.type",new Character((char)c)); |
482 |
| - } |
483 |
| - } |
484 |
| - if (final_error != null) |
485 |
| - throw final_error; |
486 |
| - |
487 |
| - return getResultSet(this, stat, fields, tuples, recv_status, update_count, insert_oid); |
488 |
| - } |
489 |
| - } |
490 |
| - |
491 |
| - /** |
492 |
| - * Receive the field descriptions from the back end |
493 |
| - * |
494 |
| - * @return an array of the Field object describing the fields |
495 |
| - * @exception SQLException if a database error occurs |
496 |
| - */ |
497 |
| - private Field[] ReceiveFields() throws SQLException |
498 |
| - { |
499 |
| - int nf = pg_stream.ReceiveIntegerR(2), i; |
500 |
| - Field[] fields = new Field[nf]; |
501 |
| - |
502 |
| - for (i = 0 ; i < nf ; ++i) |
503 |
| - { |
504 |
| - String typname = pg_stream.ReceiveString(encoding); |
505 |
| - int typid = pg_stream.ReceiveIntegerR(4); |
506 |
| - int typlen = pg_stream.ReceiveIntegerR(2); |
507 |
| - int typmod = pg_stream.ReceiveIntegerR(4); |
508 |
| - fields[i] = new Field(this, typname, typid, typlen, typmod); |
509 |
| - } |
510 |
| - return fields; |
| 353 | + return new QueryExecutor(sql, stat, pg_stream, this).execute(); |
511 | 354 | }
|
512 | 355 |
|
513 | 356 | /**
|
@@ -793,7 +636,7 @@ private void initObjectTypes()
|
793 | 636 | * This returns a resultset. It must be overridden, so that the correct
|
794 | 637 | * version (from jdbc1 or jdbc2) are returned.
|
795 | 638 | */
|
796 |
| - protected abstract java.sql.ResultSet getResultSet(org.postgresql.Connection conn,java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount,int insertOID) throws SQLException; |
| 639 | + public abstract java.sql.ResultSet getResultSet(org.postgresql.Connection conn,java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount,int insertOID) throws SQLException; |
797 | 640 |
|
798 | 641 | /**
|
799 | 642 | * In some cases, it is desirable to immediately release a Connection's
|
|
0 commit comments