* pqInternalNotice - produce an internally-generated notice message * * A format string and optional arguments can be passed. Note that we do * libpq_gettext() here, so callers need not. * * The supplied text is taken as primary message (ie., it should not include * a trailing newline, and should not be more than one line). */
| 871 | * a trailing newline, and should not be more than one line). |
| 872 | */ |
| 873 | void |
| 874 | pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...) |
| 875 | { |
| 876 | char msgBuf[1024]; |
| 877 | va_list args; |
| 878 | PGresult *res; |
| 879 | |
| 880 | if (hooks->noticeRec == NULL) |
| 881 | return; /* nobody home to receive notice? */ |
| 882 | |
| 883 | /* Format the message */ |
| 884 | va_start(args, fmt); |
| 885 | vsnprintf(msgBuf, sizeof(msgBuf), libpq_gettext(fmt), args); |
| 886 | va_end(args); |
| 887 | msgBuf[sizeof(msgBuf) - 1] = '\0'; /* make real sure it's terminated */ |
| 888 | |
| 889 | /* Make a PGresult to pass to the notice receiver */ |
| 890 | res = PQmakeEmptyPGresult(NULL, PGRES_NONFATAL_ERROR); |
| 891 | if (!res) |
| 892 | return; |
| 893 | res->noticeHooks = *hooks; |
| 894 | |
| 895 | /* |
| 896 | * Set up fields of notice. |
| 897 | */ |
| 898 | pqSaveMessageField(res, PG_DIAG_MESSAGE_PRIMARY, msgBuf); |
| 899 | pqSaveMessageField(res, PG_DIAG_SEVERITY, libpq_gettext("NOTICE")); |
| 900 | pqSaveMessageField(res, PG_DIAG_SEVERITY_NONLOCALIZED, "NOTICE"); |
| 901 | /* XXX should provide a SQLSTATE too? */ |
| 902 | |
| 903 | /* |
| 904 | * Result text is always just the primary message + newline. If we can't |
| 905 | * allocate it, substitute "out of memory", as in pqSetResultError. |
| 906 | */ |
| 907 | res->errMsg = (char *) pqResultAlloc(res, strlen(msgBuf) + 2, false); |
| 908 | if (res->errMsg) |
| 909 | sprintf(res->errMsg, "%s\n", msgBuf); |
| 910 | else |
| 911 | res->errMsg = libpq_gettext("out of memory\n"); |
| 912 | |
| 913 | /* |
| 914 | * Pass to receiver, then free it. |
| 915 | */ |
| 916 | res->noticeHooks.noticeRec(res->noticeHooks.noticeRecArg, res); |
| 917 | PQclear(res); |
| 918 | } |
| 919 | |
| 920 | /* |
| 921 | * pqAddTuple |
no test coverage detected