7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.21 1996/12/15 09:05:53 bryanh Exp $
10
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.22 1996/12/20 20:34:38 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -362,16 +362,13 @@ PGresult*
362
362
PQexec (PGconn * conn ,const char * query )
363
363
{
364
364
PGresult * result ;
365
- int id , clear , error ;
365
+ int id ;
366
366
char buffer [MAX_MESSAGE_LEN ];
367
367
char cmdStatus [MAX_MESSAGE_LEN ];
368
368
char pname [MAX_MESSAGE_LEN ];/* portal name */
369
369
PGnotify * newNotify ;
370
370
FILE * pfin ,* pfout ,* pfdebug ;
371
-
372
- #ifdef PQ_NOTIFY_PATCH
373
- int isCommand = 0 ;/* DZ - 31-8-1996 */
374
- #endif
371
+ int emptiesSent = 0 ;
375
372
376
373
pname [0 ]= '\0' ;
377
374
@@ -412,7 +409,7 @@ PQexec(PGconn* conn, const char* query)
412
409
"-- fprintf to Pfout failed: errno=%d\n%s\n" ,
413
410
query ,errno ,strerror (errno ));
414
411
return NULL ;
415
- }
412
+ }
416
413
417
414
/* loop forever because multiple messages, especially NOTICES,
418
415
can come back from the backend
@@ -458,38 +455,12 @@ PQexec(PGconn* conn, const char* query)
458
455
// send an empty query down, and keep reading out of the pipe
459
456
// until an 'I' is received.
460
457
*/
461
- clear = 0 ;
462
- error = 0 ;
463
-
464
458
pqPuts ("Q " ,pfout ,pfdebug );/* send an empty query */
465
- #ifdef PQ_NOTIFY_PATCH
466
459
/*
467
- *Set a flag and process messages in the usual way because
460
+ *Increment a flag and process messages in the usual way because
468
461
* there may be async notifications pending. DZ - 31-8-1996
469
462
*/
470
- isCommand = 1 ;
471
- #else
472
- while (!clear )
473
- {
474
- if (pqGets (buffer ,ERROR_MSG_LENGTH ,pfin ,pfdebug )== 1 )
475
- clear = 1 ;
476
- /*
477
- // Rules can create error messages while we are waiting
478
- // for the 'I'.
479
- */
480
- if (buffer [0 ]== 'E' ) {
481
- strcpy (conn -> errorMessage ,& buffer [1 ]);
482
- error ++ ;
483
- }
484
- clear = (buffer [0 ]== 'I' );
485
- }
486
- if (error ) {
487
- return (PGresult * )NULL ;
488
- }
489
- result = makeEmptyPGresult (conn ,PGRES_COMMAND_OK );
490
- strncpy (result -> cmdStatus ,cmdStatus ,CMDSTATUS_LEN - 1 );
491
- return result ;
492
- #endif
463
+ emptiesSent ++ ;
493
464
}
494
465
break ;
495
466
case 'E' :/* error return */
@@ -507,17 +478,21 @@ PQexec(PGconn* conn, const char* query)
507
478
if ((c = pqGetc (pfin ,pfdebug ))!= '\0' ) {
508
479
fprintf (stderr ,"error!, unexpected character %c following 'I'\n" ,c );
509
480
}
510
- if (isCommand ) {
511
- /*
512
- * If this is the result of a portal query command set the
513
- * command status and message accordingly. DZ - 31-8-1996
514
- */
515
- result = makeEmptyPGresult (conn ,PGRES_COMMAND_OK );
516
- strncpy (result -> cmdStatus ,cmdStatus ,CMDSTATUS_LEN - 1 );
481
+ if (emptiesSent ) {
482
+ if (-- emptiesSent == 0 ) {/* is this the last one? */
483
+ /*
484
+ * If this is the result of a portal query command set the
485
+ * command status and message accordingly. DZ - 31-8-1996
486
+ */
487
+ result = makeEmptyPGresult (conn ,PGRES_COMMAND_OK );
488
+ strncpy (result -> cmdStatus ,cmdStatus ,CMDSTATUS_LEN - 1 );
489
+ return result ;
490
+ }
491
+ }
492
+ else {
493
+ result = makeEmptyPGresult (conn ,PGRES_EMPTY_QUERY );
517
494
return result ;
518
495
}
519
- result = makeEmptyPGresult (conn ,PGRES_EMPTY_QUERY );
520
- return result ;
521
496
}
522
497
break ;
523
498
case 'N' :/* notices from the backend */
@@ -548,8 +523,7 @@ PQexec(PGconn* conn, const char* query)
548
523
id );
549
524
return (PGresult * )NULL ;
550
525
}/* switch */
551
- }/* while (1)*/
552
-
526
+ }/* while (1)*/
553
527
}
554
528
555
529
/*