| 1658 | */ |
| 1659 | |
| 1660 | bool |
| 1661 | PQsendQueryStart(PGconn *conn, bool newQuery) |
| 1662 | { |
| 1663 | if (!conn) |
| 1664 | return false; |
| 1665 | |
| 1666 | /* |
| 1667 | * If this is the beginning of a query cycle, reset the error buffer. |
| 1668 | */ |
| 1669 | if (newQuery) |
| 1670 | resetPQExpBuffer(&conn->errorMessage); |
| 1671 | |
| 1672 | /* Don't try to send if we know there's no live connection. */ |
| 1673 | if (conn->status != CONNECTION_OK) |
| 1674 | { |
| 1675 | appendPQExpBufferStr(&conn->errorMessage, |
| 1676 | libpq_gettext("no connection to the server\n")); |
| 1677 | return false; |
| 1678 | } |
| 1679 | |
| 1680 | /* Can't send while already busy, either, unless enqueuing for later */ |
| 1681 | if (conn->asyncStatus != PGASYNC_IDLE && |
| 1682 | conn->pipelineStatus == PQ_PIPELINE_OFF) |
| 1683 | { |
| 1684 | appendPQExpBufferStr(&conn->errorMessage, |
| 1685 | libpq_gettext("another command is already in progress\n")); |
| 1686 | return false; |
| 1687 | } |
| 1688 | |
| 1689 | if (conn->pipelineStatus != PQ_PIPELINE_OFF) |
| 1690 | { |
| 1691 | /* |
| 1692 | * When enqueuing commands we don't change much of the connection |
| 1693 | * state since it's already in use for the current command. The |
| 1694 | * connection state will get updated when pqPipelineProcessQueue() |
| 1695 | * advances to start processing the queued message. |
| 1696 | * |
| 1697 | * Just make sure we can safely enqueue given the current connection |
| 1698 | * state. We can enqueue behind another queue item, or behind a |
| 1699 | * non-queue command (one that sends its own sync), but we can't |
| 1700 | * enqueue if the connection is in a copy state. |
| 1701 | */ |
| 1702 | switch (conn->asyncStatus) |
| 1703 | { |
| 1704 | case PGASYNC_IDLE: |
| 1705 | case PGASYNC_READY: |
| 1706 | case PGASYNC_READY_MORE: |
| 1707 | case PGASYNC_BUSY: |
| 1708 | /* ok to queue */ |
| 1709 | break; |
| 1710 | case PGASYNC_COPY_IN: |
| 1711 | case PGASYNC_COPY_OUT: |
| 1712 | case PGASYNC_COPY_BOTH: |
| 1713 | appendPQExpBufferStr(&conn->errorMessage, |
| 1714 | libpq_gettext("cannot queue commands during COPY\n")); |
| 1715 | return false; |
| 1716 | } |
| 1717 | } |
no test coverage detected