class BDB::Sequence

Public Instance Methods

cachesize() click to toggle source
static VALUE
bdb_seq_cachesize(VALUE obj)
{

    bdb_SEQ *seqst;
    int size;

    GetSEQ(obj, seqst);
    bdb_test_error(seqst->seqp->get_cachesize(seqst->seqp, &size));
    return INT2NUM(size);
}
close() click to toggle source
static VALUE
bdb_seq_close(VALUE obj)
{
    bdb_SEQ *seqst;

    GetSEQ(obj, seqst);
    seqst->seqp->close(seqst->seqp, 0);
    seqst->seqp = NULL;
    return Qnil;
}
db() click to toggle source
static VALUE
bdb_seq_db(VALUE obj)
{
    bdb_SEQ *seqst;

    GetSEQ(obj, seqst);
    return seqst->db;
}
flags() click to toggle source
static VALUE
bdb_seq_flags(VALUE obj)
{

    bdb_SEQ *seqst;
    unsigned int flags;

    GetSEQ(obj, seqst);
    bdb_test_error(seqst->seqp->get_flags(seqst->seqp, &flags));
    return INT2NUM(flags);
}
get(p1 = v1, p2 = v2) click to toggle source
static VALUE
bdb_seq_get(int argc, VALUE *argv, VALUE obj)
{
    bdb_SEQ *seqst;
    int delta = 1, flags = 0;
    VALUE a, b;
    db_seq_t val;

    GetSEQ(obj, seqst);
    switch (rb_scan_args(argc, argv, "02", &a, &b)) {
    case 2:
        flags = NUM2INT(b);
        /* ... */
    case 1:
        delta = NUM2INT(a);
    }
    bdb_test_error(seqst->seqp->get(seqst->seqp, seqst->txnid, delta, &val, flags));
    return LONG2NUM(val);
}
key() click to toggle source
static VALUE
bdb_seq_key(VALUE obj)
{
    bdb_SEQ *seqst;
    DBT key;

    GetSEQ(obj, seqst);
    bdb_test_error(seqst->seqp->get_key(seqst->seqp, &key));
    return bdb_test_load_key(seqst->db, &key);
}
range() click to toggle source
static VALUE
bdb_seq_range(VALUE obj)
{
    bdb_SEQ *seqst;
    db_seq_t deb, fin;

    GetSEQ(obj, seqst);
    bdb_test_error(seqst->seqp->get_range(seqst->seqp, &deb, &fin));
    return rb_assoc_new(LONG2NUM(deb), LONG2NUM(fin));
}
remove(p1 = v1) click to toggle source
static VALUE
bdb_seq_remove(int argc, VALUE *argv, VALUE obj)
{
    bdb_SEQ *seqst;
    VALUE a;
    int flags = 0;

    GetSEQ(obj, seqst);
    if (rb_scan_args(argc, argv, "01", &a)) {
        flags = NUM2INT(a);
    }
    if (seqst->seqp->remove(seqst->seqp, seqst->txnid, flags)) {
        rb_raise(rb_eArgError, "invalid argument");
    }
    seqst->seqp = NULL;
    return Qnil;
}
stat(p1 = v1) click to toggle source
static VALUE
bdb_seq_stat(int argc, VALUE *argv, VALUE obj)
{
    bdb_SEQ *seqst;
    int  flags = 0;
    VALUE a, res;
    DB_SEQUENCE_STAT sta;

    GetSEQ(obj, seqst);
    if (rb_scan_args(argc, argv, "01", &a)) {
        flags = NUM2INT(a);
    }
    bdb_test_error(seqst->seqp->stat(seqst->seqp, (void *)&sta, flags));
    res = rb_hash_new();
    rb_hash_aset(res, rb_str_new2("wait"), INT2NUM(sta.st_wait));
    rb_hash_aset(res, rb_str_new2("nowait"), INT2NUM(sta.st_nowait));
    rb_hash_aset(res, rb_str_new2("current"), INT2NUM(sta.st_current));
    rb_hash_aset(res, rb_str_new2("value"), INT2NUM(sta.st_value));
    rb_hash_aset(res, rb_str_new2("last_value"), INT2NUM(sta.st_last_value));
    rb_hash_aset(res, rb_str_new2("min"), INT2NUM(sta.st_min));
    rb_hash_aset(res, rb_str_new2("max"), INT2NUM(sta.st_max));
    rb_hash_aset(res, rb_str_new2("cache_size"), INT2NUM(sta.st_cache_size));
    rb_hash_aset(res, rb_str_new2("flags"), INT2NUM(sta.st_flags));
    return res;
}