always open databases read/write

This commit is contained in:
mappu 2017-05-21 16:47:28 +12:00
parent d2ec12798e
commit 9fb5bdad78
2 changed files with 3 additions and 32 deletions

31
main.go
View File

@ -24,36 +24,9 @@ func GetMagic() int64 {
return Magic return Magic
} }
//export Bolt_Options_New
func Bolt_Options_New() ObjectReference {
b := *bolt.DefaultOptions
return gms.Put(&b)
}
//export Bolt_Options_New_Readonly
func Bolt_Options_New_Readonly() ObjectReference {
b := *bolt.DefaultOptions
b.ReadOnly = true
return gms.Put(&b)
}
//export Bolt_Open //export Bolt_Open
func Bolt_Open(path string, mode uint32, opts ObjectReference) (ObjectReference, *C.char, int) { func Bolt_Open(path string) (ObjectReference, *C.char, int) {
optsIFC, ok := gms.Get(opts) ptrDB, err := bolt.Open(path, os.FileMode(0644), bolt.DefaultOptions)
if !ok {
errMsg := NullObjectReference.Error()
return 0, C.CString(errMsg), len(errMsg)
}
ptrBoltOps, ok := optsIFC.(*bolt.Options)
if !ok {
errMsg := NullObjectReference.Error()
return 0, C.CString(errMsg), len(errMsg)
}
ptrDB, err := bolt.Open(path, os.FileMode(mode), ptrBoltOps)
if err != nil { if err != nil {
errMsg := err.Error() errMsg := err.Error()
return 0, C.CString(errMsg), len(errMsg) return 0, C.CString(errMsg), len(errMsg)

View File

@ -9,12 +9,10 @@ BoltDB::BoltDB()
BoltDB* BoltDB::createFrom(QString filePath, QString &errorOut) BoltDB* BoltDB::createFrom(QString filePath, QString &errorOut)
{ {
auto opts = ::Bolt_Options_New_Readonly();
QByteArray filePathBytes(filePath.toUtf8()); QByteArray filePathBytes(filePath.toUtf8());
GoString filePathGS = Interop::toGoString_WeakRef(&filePathBytes); GoString filePathGS = Interop::toGoString_WeakRef(&filePathBytes);
auto open_ret = ::Bolt_Open(filePathGS, 0444, opts); auto open_ret = ::Bolt_Open(filePathGS);
if (open_ret.r2 != 0) { if (open_ret.r2 != 0) {
errorOut = QString::fromUtf8(open_ret.r1, open_ret.r2); errorOut = QString::fromUtf8(open_ret.r1, open_ret.r2);
free(open_ret.r1); free(open_ret.r1);