|
8 | 8 | importorg.postgresql.fastpath.*;
|
9 | 9 | importorg.postgresql.largeobject.*;
|
10 | 10 | importorg.postgresql.util.*;
|
11 |
| -importorg.postgresql.core.Encoding; |
| 11 | +importorg.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 |
| -publicjava.sql.ResultSetExecSQL(Stringsql,java.sql.Statementstat)throwsSQLException |
| 351 | +publicjava.sql.ResultSetExecSQL(Stringsql,java.sql.Statementstat)throwsSQLException |
352 | 352 | {
|
353 |
| -// added Jan 30 2001 to correct maxrows per statement |
354 |
| -intmaxrows=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 |
| -Vectortuples =newVector(); |
371 |
| -byte[]buf =null; |
372 |
| -intfqp =0; |
373 |
| -booleanhfr =false; |
374 |
| -Stringrecv_status =null,msg; |
375 |
| -intupdate_count =1; |
376 |
| -intinsert_oid =0; |
377 |
| -SQLExceptionfinal_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 (IOExceptione) { |
387 |
| -thrownewPSQLException("postgresql.con.ioerror",e); |
388 |
| -} |
389 |
| - |
390 |
| -while (!hfr ||fqp >0) |
391 |
| -{ |
392 |
| -Objecttup=null;// holds rows as they are recieved |
393 |
| - |
394 |
| -intc =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 |
| -thrownewPSQLException("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(NumberFormatExceptionnfe) { |
418 |
| -thrownewPSQLException("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(NumberFormatExceptionnfe) { |
424 |
| -thrownewPSQLException("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 (IOExceptione) { |
439 |
| -thrownewPSQLException("postgresql.con.ioerror",e); |
440 |
| -} |
441 |
| -fqp++; |
442 |
| -} |
443 |
| -break; |
444 |
| -case'D':// Text Data Transfer |
445 |
| -if (fields ==null) |
446 |
| -thrownewPSQLException("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 =newSQLException(msg); |
455 |
| -hfr =true; |
456 |
| -break; |
457 |
| -case'I':// Empty Query |
458 |
| -intt =pg_stream.ReceiveChar(); |
459 |
| - |
460 |
| -if (t !=0) |
461 |
| -thrownewPSQLException("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 |
| -Stringpname =pg_stream.ReceiveString(encoding); |
472 |
| -break; |
473 |
| -case'T':// MetaData Field Description |
474 |
| -if (fields !=null) |
475 |
| -thrownewPSQLException("postgresql.con.multres"); |
476 |
| -fields =ReceiveFields(); |
477 |
| -break; |
478 |
| -case'Z':// backend ready for query, ignore for now :-) |
479 |
| -break; |
480 |
| -default: |
481 |
| -thrownewPSQLException("postgresql.con.type",newCharacter((char)c)); |
482 |
| -} |
483 |
| -} |
484 |
| -if (final_error !=null) |
485 |
| -throwfinal_error; |
486 |
| - |
487 |
| -returngetResultSet(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 |
| -privateField[]ReceiveFields()throwsSQLException |
498 |
| - { |
499 |
| -intnf =pg_stream.ReceiveIntegerR(2),i; |
500 |
| -Field[]fields =newField[nf]; |
501 |
| - |
502 |
| -for (i =0 ;i <nf ; ++i) |
503 |
| - { |
504 |
| -Stringtypname =pg_stream.ReceiveString(encoding); |
505 |
| -inttypid =pg_stream.ReceiveIntegerR(4); |
506 |
| -inttyplen =pg_stream.ReceiveIntegerR(2); |
507 |
| -inttypmod =pg_stream.ReceiveIntegerR(4); |
508 |
| -fields[i] =newField(this,typname,typid,typlen,typmod); |
509 |
| - } |
510 |
| -returnfields; |
| 353 | +returnnewQueryExecutor(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 |
| -protectedabstractjava.sql.ResultSetgetResultSet(org.postgresql.Connectionconn,java.sql.Statementstat,Field[]fields,Vectortuples,Stringstatus,intupdateCount,intinsertOID)throwsSQLException; |
| 639 | +publicabstractjava.sql.ResultSetgetResultSet(org.postgresql.Connectionconn,java.sql.Statementstat,Field[]fields,Vectortuples,Stringstatus,intupdateCount,intinsertOID)throwsSQLException; |
797 | 640 |
|
798 | 641 | /**
|
799 | 642 | * In some cases, it is desirable to immediately release a Connection's
|
|