static int btreeSeqCreate( sqlite3_context *context, Btree *p, SEQ_COOKIE *cookie) { BtShared *pBt; DBT key; DB_SEQUENCE *seq; char seq_key[BT_MAX_SEQ_NAME]; int ret, seq_len; u_int32_t flags; pBt = p->pBt; if (cookie->cache != 0) { if ((ret = db_sequence_create(&seq, pBt->metadb, 0)) != 0) return ret; if (cookie->cache > 0) seq->set_cachesize(seq, cookie->cache); if (cookie->decrementing != 0) seq->set_flags(seq, DB_SEQ_DEC); /* Always set min_val and max_val */ if ((ret = seq->set_range(seq, cookie->min_val, cookie->max_val)) != 0) return ret; if ((ret = seq->initial_value(seq, cookie->start_val)) != 0) return ret; flags = DB_CREATE; #ifndef BDBSQL_SINGLE_THREAD flags |= DB_THREAD; #endif sqlite3_snprintf( BT_MAX_SEQ_NAME, seq_key, "%s_db", cookie->name); seq_len = (int)strlen(seq_key); memset(&key, 0, sizeof(key)); key.data = seq_key; key.size = key.ulen = seq_len; key.flags = DB_DBT_USERMEM; if ((ret = seq->open(seq, p->savepoint_txn, &key, flags)) != 0) return ret; cookie->handle = seq; } else { cookie->handle = NULL; cookie->val = cookie->start_val; if ((cookie->decrementing && cookie->start_val < cookie->min_val) || (!cookie->decrementing && cookie->start_val > cookie->max_val) || cookie->min_val == cookie->max_val) return EINVAL; } if ((ret = btreeSeqPutCookie(context, p, cookie, DB_NOOVERWRITE)) != 0) return (ret); return (0); }
static int btreeSeqOpen( sqlite3_context *context, Btree *p, SEQ_COOKIE *cookie) { BtShared *pBt; DBT key; DB_SEQUENCE *seq; char seq_key[BT_MAX_SEQ_NAME]; int ret, seq_len; u_int32_t flags; pBt = p->pBt; if ((ret = btreeSeqGetCookie(context, p, cookie, 0)) != 0) return (ret); if (cookie->cache != 0) { if ((ret = db_sequence_create(&seq, pBt->metadb, 0)) != 0) return ret; seq->set_cachesize(seq, cookie->cache); flags = 0; #ifdef BDBSQL_SINGLE_THREAD flags |= DB_THREAD; #endif sqlite3_snprintf( BT_MAX_SEQ_NAME, seq_key, "%s_db", cookie->name); seq_len = (int)strlen(seq_key); memset(&key, 0, sizeof(key)); key.data = seq_key; key.size = key.ulen = seq_len; key.flags = DB_DBT_USERMEM; if ((ret = seq->open( seq, NULL, &key, flags)) != 0) { (void)seq->close(seq, 0); return ret; } cookie->handle = seq; } return (0); }
static JSBool rpmseq_setprop(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmseqClass, NULL); DB_SEQUENCE * seq = ptr; jsval idval; JS_IdToValue(cx, id, &idval); jsint tiny = JSVAL_TO_INT(idval); jsdouble d = 0; int ret; /* XXX the class has ptr == NULL, instances have ptr != NULL. */ if (ptr == NULL) return JS_TRUE; switch (tiny) { case _DEBUG: if (!JS_ValueToInt32(cx, *vp, &_debug)) break; break; case _CACHESIZE: { int32_t _i = 0; if (seq->api_internal != NULL || !JS_ValueToNumber(cx, *vp, &d)) { *vp = JSVAL_FALSE; break; } _i = d; ret = seq->set_cachesize(seq, _i); *vp = (!ret ? JSVAL_TRUE : JSVAL_FALSE); } break; case _FLAGS: { uint32_t _u = 0; if (seq->api_internal != NULL || !JS_ValueToNumber(cx, *vp, &d)) { *vp = JSVAL_FALSE; break; } _u = d; ret = seq->set_flags(seq, _u); *vp = (!ret ? JSVAL_TRUE : JSVAL_FALSE); } break; case _INITVAL: { db_seq_t _ival = 0; if (seq->api_internal != NULL || !JS_ValueToNumber(cx, *vp, &d)) { *vp = JSVAL_FALSE; break; } _ival = d; ret = seq->initial_value(seq, _ival); *vp = (!ret ? JSVAL_TRUE : JSVAL_FALSE); } break; case _RANGEMIN: case _RANGEMAX: { db_seq_t _min = 0; db_seq_t _max = 0; if (seq->api_internal != NULL || !JS_ValueToNumber(cx, *vp, &d)) { *vp = JSVAL_FALSE; break; } if ((ret = seq->get_range(seq, &_min, &_max)) != 0) { *vp = JSVAL_VOID; break; } switch (tiny) { case _RANGEMIN: _min = d; break; case _RANGEMAX: _max = d; break; } ret = seq->set_range(seq, _min, _max); *vp = (!ret ? JSVAL_TRUE : JSVAL_FALSE); } break; default: break; } return JS_TRUE; }