/* call-seq:
* trace { |sql| ... }
* trace(Class.new { def call sql; end }.new)
*
* Installs (or removes) a block that will be invoked for every SQL
* statement executed. The block receives one parameter: the SQL statement
* executed. If the block is +nil+, any existing tracer will be uninstalled.
*/
static VALUE trace(int argc, VALUE *argv, VALUE self)
{
sqlite3RubyPtr ctx;
VALUE block;
Data_Get_Struct(self, sqlite3Ruby, ctx);
REQUIRE_OPEN_DB(ctx);
rb_scan_args(argc, argv, "01", &block);
if(NIL_P(block) && rb_block_given_p()) block = rb_block_proc();
rb_iv_set(self, "@tracefunc", block);
sqlite3_trace(ctx->db, NIL_P(block) ? NULL : tracefunc, (void *)self);
return self;
}