Method: PG::Connection#set_notice_processor
- Defined in:
- ext/pg_connection.c
#set_notice_processor {|message| ... } ⇒ Proc
See #set_notice_receiver for the description of what this and the notice_processor methods do.
This function takes a new block to act as the notice processor and returns the Proc object previously set, or nil if it was previously the default. The block should accept a single String object.
If you pass no arguments, it will reset the handler to the default.
3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 |
# File 'ext/pg_connection.c', line 3037
static VALUE
pgconn_set_notice_processor(VALUE self)
{
VALUE proc, old_proc;
t_pg_connection *this = pg_get_connection_safe( self );
rb_check_frozen(self);
/* If default_notice_processor is unset, assume that the current
* notice processor is the default, and save it to a global variable.
* This should not be a problem because the default processor is
* always the same, so won't vary among connections.
*/
if(this->default_notice_processor == NULL)
this->default_notice_processor = PQsetNoticeProcessor(this->pgconn, NULL, NULL);
old_proc = this->notice_processor;
if( rb_block_given_p() ) {
proc = rb_block_proc();
PQsetNoticeProcessor(this->pgconn, gvl_notice_processor_proxy, (void *)self);
} else {
/* if no block is given, set back to default */
proc = Qnil;
PQsetNoticeProcessor(this->pgconn, this->default_notice_processor, NULL);
}
RB_OBJ_WRITE(self, &this->notice_processor, proc);
return old_proc;
}
|