[ruby-oci8-devel] Clear binds

Liming Lian liming.lian at oracle.com
Thu Dec 20 03:31:35 EST 2007


Hi,

As we discussed at the proposal, all existing binds should be clear from 
cursor when new value of max_array_size is set. I have implemented this 
by adding functions to stmt.c. I am not sure if I have fully understood 
the mechanism of how Ruby-OCI8 works. So I want to hear any comments on 
my implementation.

Following is my code added to stmt.c:

static ID id_empty;
static ID id_clear;

static VALUE clear_binds_iterator_proc(VALUE pair, VALUE arg, VALUE self)
{
    VALUE value = RARRAY(pair)->ptr[1];

    if(!NIL_P(value)) {
      oci8_base_free((oci8_base_t*)oci8_get_bind(value));
    }

    return self;
}


static VALUE oci8_stmt_clear_binds(VALUE self)
{
    oci8_stmt_t *stmt = DATA_PTR(self);

    if(!RTEST(rb_funcall(stmt->binds, id_empty, 0)))
    {
      rb_iterate(rb_each, stmt->binds, clear_binds_iterator_proc, 
(VALUE) NULL);
      rb_funcall(stmt->binds,id_clear,0);
    }

    return self;
}

void Init_oci8_stmt(VALUE cOCI8)
{
  ........
  id_empty = rb_intern("empty?");
  id_clear = rb_intern("clear");
  ........
  rb_define_private_method(cOCIStmt, "__clearBinds", 
oci8_stmt_clear_binds, 0);
  ........
}
 



More information about the ruby-oci8-devel mailing list