* PQsendPrepare * Submit a Parse message, but don't wait for it to finish * * Returns: 1 if successfully submitted * 0 if error (conn->errorMessage is set) */
| 1515 | * 0 if error (conn->errorMessage is set) |
| 1516 | */ |
| 1517 | int |
| 1518 | PQsendPrepare(PGconn *conn, |
| 1519 | const char *stmtName, const char *query, |
| 1520 | int nParams, const Oid *paramTypes) |
| 1521 | { |
| 1522 | PGcmdQueueEntry *entry = NULL; |
| 1523 | |
| 1524 | if (!PQsendQueryStart(conn, true)) |
| 1525 | return 0; |
| 1526 | |
| 1527 | /* check the arguments */ |
| 1528 | if (!stmtName) |
| 1529 | { |
| 1530 | appendPQExpBufferStr(&conn->errorMessage, |
| 1531 | libpq_gettext("statement name is a null pointer\n")); |
| 1532 | return 0; |
| 1533 | } |
| 1534 | if (!query) |
| 1535 | { |
| 1536 | appendPQExpBufferStr(&conn->errorMessage, |
| 1537 | libpq_gettext("command string is a null pointer\n")); |
| 1538 | return 0; |
| 1539 | } |
| 1540 | if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT) |
| 1541 | { |
| 1542 | appendPQExpBuffer(&conn->errorMessage, |
| 1543 | libpq_gettext("number of parameters must be between 0 and %d\n"), |
| 1544 | PQ_QUERY_PARAM_MAX_LIMIT); |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | entry = pqAllocCmdQueueEntry(conn); |
| 1549 | if (entry == NULL) |
| 1550 | return 0; /* error msg already set */ |
| 1551 | |
| 1552 | /* construct the Parse message */ |
| 1553 | if (pqPutMsgStart('P', conn) < 0 || |
| 1554 | pqPuts(stmtName, conn) < 0 || |
| 1555 | pqPuts(query, conn) < 0) |
| 1556 | goto sendFailed; |
| 1557 | |
| 1558 | if (nParams > 0 && paramTypes) |
| 1559 | { |
| 1560 | int i; |
| 1561 | |
| 1562 | if (pqPutInt(nParams, 2, conn) < 0) |
| 1563 | goto sendFailed; |
| 1564 | for (i = 0; i < nParams; i++) |
| 1565 | { |
| 1566 | if (pqPutInt(paramTypes[i], 4, conn) < 0) |
| 1567 | goto sendFailed; |
| 1568 | } |
| 1569 | } |
| 1570 | else |
| 1571 | { |
| 1572 | if (pqPutInt(0, 2, conn) < 0) |
| 1573 | goto sendFailed; |
| 1574 | } |