8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.144 2003/08/13 16:29:03 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.145 2003/08/13 18:56:21 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -647,6 +647,9 @@ PQsendQuery(PGconn *conn, const char *query)
647
647
return 0 ;
648
648
}
649
649
650
+ /* remember we are using simple query protocol */
651
+ conn -> ext_query = false;
652
+
650
653
/*
651
654
* Give the data a push. In nonblock mode, don't complain if we're
652
655
* unable to send it all; PQgetResult() will do any additional
@@ -901,6 +904,9 @@ PQsendQueryGuts(PGconn *conn,
901
904
pqPutMsgEnd (conn ) < 0 )
902
905
goto sendFailed ;
903
906
907
+ /* remember we are using extended query protocol */
908
+ conn -> ext_query = true;
909
+
904
910
/*
905
911
* Give the data a push. In nonblock mode, don't complain if we're
906
912
* unable to send it all; PQgetResult() will do any additional
@@ -1187,29 +1193,28 @@ PQexecStart(PGconn *conn)
1187
1193
*/
1188
1194
while ((result = PQgetResult (conn )) != NULL )
1189
1195
{
1190
- if (result -> resultStatus == PGRES_COPY_IN )
1196
+ ExecStatusType resultStatus = result -> resultStatus ;
1197
+
1198
+ PQclear (result ); /* only need its status */
1199
+ if (resultStatus == PGRES_COPY_IN )
1191
1200
{
1192
1201
if (PG_PROTOCOL_MAJOR (conn -> pversion ) >= 3 )
1193
1202
{
1194
1203
/* In protocol 3, we can get out of a COPY IN state */
1195
1204
if (PQputCopyEnd (conn ,
1196
1205
libpq_gettext ("COPY terminated by new PQexec" )) < 0 )
1197
- {
1198
- PQclear (result );
1199
1206
return false;
1200
- }
1201
1207
/* keep waiting to swallow the copy's failure message */
1202
1208
}
1203
1209
else
1204
1210
{
1205
1211
/* In older protocols we have to punt */
1206
- PQclear (result );
1207
1212
printfPQExpBuffer (& conn -> errorMessage ,
1208
1213
libpq_gettext ("COPY IN state must be terminated first\n" ));
1209
1214
return false;
1210
1215
}
1211
1216
}
1212
- else if (result -> resultStatus == PGRES_COPY_OUT )
1217
+ else if (resultStatus == PGRES_COPY_OUT )
1213
1218
{
1214
1219
if (PG_PROTOCOL_MAJOR (conn -> pversion ) >= 3 )
1215
1220
{
@@ -1224,13 +1229,11 @@ PQexecStart(PGconn *conn)
1224
1229
else
1225
1230
{
1226
1231
/* In older protocols we have to punt */
1227
- PQclear (result );
1228
1232
printfPQExpBuffer (& conn -> errorMessage ,
1229
1233
libpq_gettext ("COPY OUT state must be terminated first\n" ));
1230
1234
return false;
1231
1235
}
1232
1236
}
1233
- PQclear (result );
1234
1237
}
1235
1238
1236
1239
/* OK to send a command */
@@ -1409,6 +1412,16 @@ PQputCopyEnd(PGconn *conn, const char *errormsg)
1409
1412
pqPutMsgEnd (conn ) < 0 )
1410
1413
return -1 ;
1411
1414
}
1415
+ /*
1416
+ * If we sent the COPY command in extended-query mode, we must
1417
+ * issue a Sync as well.
1418
+ */
1419
+ if (conn -> ext_query )
1420
+ {
1421
+ if (pqPutMsgStart ('S' , false, conn ) < 0 ||
1422
+ pqPutMsgEnd (conn ) < 0 )
1423
+ return -1 ;
1424
+ }
1412
1425
}
1413
1426
else
1414
1427
{
@@ -2055,12 +2068,15 @@ PQgetisnull(const PGresult *res, int tup_num, int field_num)
2055
2068
int
2056
2069
PQsetnonblocking (PGconn * conn , int arg )
2057
2070
{
2071
+ bool barg ;
2072
+
2058
2073
if (!conn || conn -> status == CONNECTION_BAD )
2059
2074
return -1 ;
2060
2075
2061
- arg = (arg == TRUE) ? 1 : 0 ;
2076
+ barg = (arg ? TRUE : FALSE);
2077
+
2062
2078
/* early out if the socket is already in the state requested */
2063
- if (arg == conn -> nonblocking )
2079
+ if (barg == conn -> nonblocking )
2064
2080
return (0 );
2065
2081
2066
2082
/*
@@ -2074,7 +2090,7 @@ PQsetnonblocking(PGconn *conn, int arg)
2074
2090
if (pqFlush (conn ))
2075
2091
return (-1 );
2076
2092
2077
- conn -> nonblocking = arg ;
2093
+ conn -> nonblocking = barg ;
2078
2094
2079
2095
return (0 );
2080
2096
}
0 commit comments