| 1369 | } |
| 1370 | |
| 1371 | int |
| 1372 | PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery) |
| 1373 | { |
| 1374 | PGcmdQueueEntry *entry = NULL; |
| 1375 | |
| 1376 | if (!PQsendQueryStart(conn, newQuery)) |
| 1377 | return 0; |
| 1378 | |
| 1379 | /* check the argument */ |
| 1380 | if (!query) |
| 1381 | { |
| 1382 | appendPQExpBufferStr(&conn->errorMessage, |
| 1383 | libpq_gettext("command string is a null pointer\n")); |
| 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | entry = pqAllocCmdQueueEntry(conn); |
| 1388 | if (entry == NULL) |
| 1389 | return 0; /* error msg already set */ |
| 1390 | |
| 1391 | /* Send the query message(s) */ |
| 1392 | if (conn->pipelineStatus == PQ_PIPELINE_OFF) |
| 1393 | { |
| 1394 | /* construct the outgoing Query message */ |
| 1395 | if (pqPutMsgStart('Q', conn) < 0 || |
| 1396 | pqPuts(query, conn) < 0 || |
| 1397 | pqPutMsgEnd(conn) < 0) |
| 1398 | { |
| 1399 | /* error message should be set up already */ |
| 1400 | pqRecycleCmdQueueEntry(conn, entry); |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
| 1404 | /* remember we are using simple query protocol */ |
| 1405 | entry->queryclass = PGQUERY_SIMPLE; |
| 1406 | /* and remember the query text too, if possible */ |
| 1407 | entry->query = strdup(query); |
| 1408 | } |
| 1409 | else |
| 1410 | { |
| 1411 | /* |
| 1412 | * In pipeline mode we cannot use the simple protocol, so we send |
| 1413 | * Parse, Bind, Describe Portal, Execute, Close Portal (with the |
| 1414 | * unnamed portal). |
| 1415 | */ |
| 1416 | if (pqPutMsgStart('P', conn) < 0 || |
| 1417 | pqPuts("", conn) < 0 || |
| 1418 | pqPuts(query, conn) < 0 || |
| 1419 | pqPutInt(0, 2, conn) < 0 || |
| 1420 | pqPutMsgEnd(conn) < 0) |
| 1421 | goto sendFailed; |
| 1422 | if (pqPutMsgStart('B', conn) < 0 || |
| 1423 | pqPuts("", conn) < 0 || |
| 1424 | pqPuts("", conn) < 0 || |
| 1425 | pqPutInt(0, 2, conn) < 0 || |
| 1426 | pqPutInt(0, 2, conn) < 0 || |
| 1427 | pqPutInt(0, 2, conn) < 0 || |
| 1428 | pqPutMsgEnd(conn) < 0) |
no test coverage detected