Method: PG::Connection#notifies

Defined in:
ext/pg_connection.c

#notifiesObject

Returns a hash of the unprocessed notifications. If there is no unprocessed notifier, it returns nil.


2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
# File 'ext/pg_connection.c', line 2199

static VALUE
pgconn_notifies(VALUE self)
{
	t_pg_connection *this = pg_get_connection_safe( self );
	PGnotify *notification;
	VALUE hash;
	VALUE sym_relname, sym_be_pid, sym_extra;
	VALUE relname, be_pid, extra;

	sym_relname = ID2SYM(rb_intern("relname"));
	sym_be_pid = ID2SYM(rb_intern("be_pid"));
	sym_extra = ID2SYM(rb_intern("extra"));

	notification = gvl_PQnotifies(this->pgconn);
	if (notification == NULL) {
		return Qnil;
	}

	hash = rb_hash_new();
	relname = rb_str_new2(notification->relname);
	be_pid = INT2NUM(notification->be_pid);
	extra = rb_str_new2(notification->extra);
	PG_ENCODING_SET_NOCHECK( relname, this->enc_idx );
	PG_ENCODING_SET_NOCHECK( extra, this->enc_idx );

	rb_hash_aset(hash, sym_relname, relname);
	rb_hash_aset(hash, sym_be_pid, be_pid);
	rb_hash_aset(hash, sym_extra, extra);

	PQfreemem(notification);
	return hash;
}