Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
32.13. Notice Processing
Prev UpChapter 32. libpq — C LibraryHome Next

32.13. Notice Processing#

Notice and warning messages generated by the server are not returned by the query execution functions, since they do not imply failure of the query. Instead they are passed to a notice handling function, and execution continues normally after the handler returns. The default notice handling function prints the message onstderr, but the application can override this behavior by supplying its own handling function.

For historical reasons, there are two levels of notice handling, called the notice receiver and notice processor. The default behavior is for the notice receiver to format the notice and pass a string to the notice processor for printing. However, an application that chooses to provide its own notice receiver will typically ignore the notice processor layer and just do all the work in the notice receiver.

The functionPQsetNoticeReceiver sets or examines the current notice receiver for a connection object. Similarly,PQsetNoticeProcessor sets or examines the current notice processor.

typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);PQnoticeReceiverPQsetNoticeReceiver(PGconn *conn,                    PQnoticeReceiver proc,                    void *arg);typedef void (*PQnoticeProcessor) (void *arg, const char *message);PQnoticeProcessorPQsetNoticeProcessor(PGconn *conn,                     PQnoticeProcessor proc,                     void *arg);

Each of these functions returns the previous notice receiver or processor function pointer, and sets the new value. If you supply a null function pointer, no action is taken, but the current pointer is returned.

When a notice or warning message is received from the server, or generated internally bylibpq, the notice receiver function is called. It is passed the message in the form of aPGRES_NONFATAL_ERRORPGresult. (This allows the receiver to extract individual fields usingPQresultErrorField, or obtain a complete preformatted message usingPQresultErrorMessage orPQresultVerboseErrorMessage.) The same void pointer passed toPQsetNoticeReceiver is also passed. (This pointer can be used to access application-specific state if needed.)

The default notice receiver simply extracts the message (usingPQresultErrorMessage) and passes it to the notice processor.

The notice processor is responsible for handling a notice or warning message given in text form. It is passed the string text of the message (including a trailing newline), plus a void pointer that is the same one passed toPQsetNoticeProcessor. (This pointer can be used to access application-specific state if needed.)

The default notice processor is simply:

static voiddefaultNoticeProcessor(void *arg, const char *message){    fprintf(stderr, "%s", message);}

Once you have set a notice receiver or processor, you should expect that that function could be called as long as either thePGconn object orPGresult objects made from it exist. At creation of aPGresult, thePGconn's current notice handling pointers are copied into thePGresult for possible use by functions likePQgetvalue.


Prev Up Next
32.12. Miscellaneous Functions Home 32.14. Event System
pdfepub
Go to PostgreSQL 17
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp