* PQsendQueryGuts * Common code for sending a query with extended query protocol * PQsendQueryStart should be done already * * command may be NULL to indicate we use an already-prepared statement */
| 1739 | * command may be NULL to indicate we use an already-prepared statement |
| 1740 | */ |
| 1741 | static int |
| 1742 | PQsendQueryGuts(PGconn *conn, |
| 1743 | const char *command, |
| 1744 | const char *stmtName, |
| 1745 | int nParams, |
| 1746 | const Oid *paramTypes, |
| 1747 | const char *const *paramValues, |
| 1748 | const int *paramLengths, |
| 1749 | const int *paramFormats, |
| 1750 | int resultFormat) |
| 1751 | { |
| 1752 | int i; |
| 1753 | PGcmdQueueEntry *entry; |
| 1754 | |
| 1755 | entry = pqAllocCmdQueueEntry(conn); |
| 1756 | if (entry == NULL) |
| 1757 | return 0; /* error msg already set */ |
| 1758 | |
| 1759 | /* |
| 1760 | * We will send Parse (if needed), Bind, Describe Portal, Execute, Sync |
| 1761 | * (if not in pipeline mode), using specified statement name and the |
| 1762 | * unnamed portal. |
| 1763 | */ |
| 1764 | |
| 1765 | if (command) |
| 1766 | { |
| 1767 | /* construct the Parse message */ |
| 1768 | if (pqPutMsgStart('P', conn) < 0 || |
| 1769 | pqPuts(stmtName, conn) < 0 || |
| 1770 | pqPuts(command, conn) < 0) |
| 1771 | goto sendFailed; |
| 1772 | if (nParams > 0 && paramTypes) |
| 1773 | { |
| 1774 | if (pqPutInt(nParams, 2, conn) < 0) |
| 1775 | goto sendFailed; |
| 1776 | for (i = 0; i < nParams; i++) |
| 1777 | { |
| 1778 | if (pqPutInt(paramTypes[i], 4, conn) < 0) |
| 1779 | goto sendFailed; |
| 1780 | } |
| 1781 | } |
| 1782 | else |
| 1783 | { |
| 1784 | if (pqPutInt(0, 2, conn) < 0) |
| 1785 | goto sendFailed; |
| 1786 | } |
| 1787 | if (pqPutMsgEnd(conn) < 0) |
| 1788 | goto sendFailed; |
| 1789 | } |
| 1790 | |
| 1791 | /* Construct the Bind message */ |
| 1792 | if (pqPutMsgStart('B', conn) < 0 || |
| 1793 | pqPuts("", conn) < 0 || |
| 1794 | pqPuts(stmtName, conn) < 0) |
| 1795 | goto sendFailed; |
| 1796 | |
| 1797 | /* Send parameter formats */ |
| 1798 | if (nParams > 0 && paramFormats) |
no test coverage detected