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 JSBool rpmseq_Open(JSContext *cx, uintN argc, jsval *vp) { jsval *argv = JS_ARGV(cx , vp); JSObject *obj = JS_NewObjectForConstructor(cx , vp); if(!obj) { JS_ReportError(cx , "Failed to create 'this' object"); return JS_FALSE; } void * ptr = JS_GetInstancePrivate(cx, obj, &rpmseqClass, NULL); DB_SEQUENCE * seq = ptr; JSObject * o = NULL; DB_TXN * _txn = NULL; jsval _kv = JSVAL_NULL; _RPMDBT _k = _RPMDBT_INIT; uint32_t _flags = DB_CREATE; JSBool ok = JS_FALSE; _METHOD_DEBUG_ENTRY(_debug); if (seq == NULL) goto exit; JS_SET_RVAL(cx, vp, JSVAL_FALSE); if (!(ok = JS_ConvertArguments(cx, argc, argv, "ov/u", &o, &_kv, &_flags))) goto exit; if (o && OBJ_IS_RPMTXN(cx, o)) _txn = JS_GetInstancePrivate(cx, o, &rpmtxnClass, NULL); if (rpmdb_v2dbt(cx, _kv, &_k)) goto exit; { int ret = seq->open(seq, _txn, _RPMDBT_PTR(_k), _flags); switch (ret) { default: fprintf(stderr, "DB_SEQUENCE->open: %s\n", db_strerror(ret)); goto exit; break; case 0: JS_SET_RVAL(cx, vp, JSVAL_TRUE); seq->api_internal = obj; break; } } ok = JS_TRUE; exit: return ok; }
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); }