diff --git a/ext/lmdb_ext/lmdb_ext.c b/ext/lmdb_ext/lmdb_ext.c index de26fd6..079c99b 100644 --- a/ext/lmdb_ext/lmdb_ext.c +++ b/ext/lmdb_ext/lmdb_ext.c @@ -206,6 +206,8 @@ static void stop_txn_begin(void *arg) static VALUE with_transaction(VALUE venv, VALUE(*fn)(VALUE), VALUE arg, int flags) { ENVIRONMENT(venv, environment); + if(environment->flags & MDB_RDONLY) + flags |= MDB_RDONLY; MDB_txn* txn; TxnArgs txn_args; @@ -490,6 +492,7 @@ static VALUE environment_new(int argc, VALUE *argv, VALUE klass) { environment->env = env; environment->thread_txn_hash = rb_hash_new(); environment->txn_thread_hash = rb_hash_new(); + environment->flags = options.flags; if (options.maxreaders > 0) check(mdb_env_set_maxreaders(env, options.maxreaders)); diff --git a/ext/lmdb_ext/lmdb_ext.h b/ext/lmdb_ext/lmdb_ext.h index cf52b64..7f1a784 100644 --- a/ext/lmdb_ext/lmdb_ext.h +++ b/ext/lmdb_ext/lmdb_ext.h @@ -59,6 +59,7 @@ typedef struct { MDB_env* env; VALUE thread_txn_hash; VALUE txn_thread_hash; + int flags; } Environment; typedef struct {