* parseInput subroutine to read a 't' (ParameterDescription) message. * We'll build a new PGresult structure containing the parameter data. * Returns: 0 if processed message successfully, EOF to suspend parsing * (the latter case is not actually used currently). */
| 823 | * (the latter case is not actually used currently). |
| 824 | */ |
| 825 | static int |
| 826 | getParamDescriptions(PGconn *conn, int msgLength) |
| 827 | { |
| 828 | PGresult *result; |
| 829 | const char *errmsg = NULL; /* means "out of memory", see below */ |
| 830 | int nparams; |
| 831 | int i; |
| 832 | |
| 833 | result = PQmakeEmptyPGresult(conn, PGRES_COMMAND_OK); |
| 834 | if (!result) |
| 835 | goto advance_and_error; |
| 836 | |
| 837 | /* parseInput already read the 't' label and message length. */ |
| 838 | /* the next two bytes are the number of parameters */ |
| 839 | if (pqGetInt(&(result->numParameters), 2, conn)) |
| 840 | goto not_enough_data; |
| 841 | nparams = result->numParameters; |
| 842 | |
| 843 | /* allocate space for the parameter descriptors */ |
| 844 | if (nparams > 0) |
| 845 | { |
| 846 | result->paramDescs = (PGresParamDesc *) |
| 847 | pqResultAlloc(result, nparams * sizeof(PGresParamDesc), true); |
| 848 | if (!result->paramDescs) |
| 849 | goto advance_and_error; |
| 850 | MemSet(result->paramDescs, 0, nparams * sizeof(PGresParamDesc)); |
| 851 | } |
| 852 | |
| 853 | /* get parameter info */ |
| 854 | for (i = 0; i < nparams; i++) |
| 855 | { |
| 856 | int typid; |
| 857 | |
| 858 | if (pqGetInt(&typid, 4, conn)) |
| 859 | goto not_enough_data; |
| 860 | result->paramDescs[i].typid = typid; |
| 861 | } |
| 862 | |
| 863 | /* Success! */ |
| 864 | conn->result = result; |
| 865 | |
| 866 | return 0; |
| 867 | |
| 868 | not_enough_data: |
| 869 | errmsg = libpq_gettext("insufficient data in \"t\" message"); |
| 870 | |
| 871 | advance_and_error: |
| 872 | /* Discard unsaved result, if any */ |
| 873 | if (result && result != conn->result) |
| 874 | PQclear(result); |
| 875 | |
| 876 | /* |
| 877 | * Replace partially constructed result with an error result. First |
| 878 | * discard the old result to try to win back some memory. |
| 879 | */ |
| 880 | pqClearAsyncResult(conn); |
| 881 | |
| 882 | /* |
no test coverage detected