From e37121d4ea9b7f071a2ae681dd64b4fdfcda0987 Mon Sep 17 00:00:00 2001 From: Jessica Frazelle Date: Fri, 4 Sep 2015 11:16:27 -0700 Subject: introduce ability to pass sqlite_omit_load_extension sqlite_omit_load_extension is a go build tag which behaves much like its C counterpart SQLITE_OMIT_LOAD_EXTENSION Signed-off-by: Jessica Frazelle --- sqlite3_load_extension.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 sqlite3_load_extension.go (limited to 'sqlite3_load_extension.go') diff --git a/sqlite3_load_extension.go b/sqlite3_load_extension.go new file mode 100644 index 0000000..0251016 --- /dev/null +++ b/sqlite3_load_extension.go @@ -0,0 +1,39 @@ +// Copyright (C) 2014 Yasuhiro Matsumoto . +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file. +// +build !sqlite_omit_load_extension + +package sqlite3 + +/* +#include +#include +*/ +import "C" +import ( + "errors" + "unsafe" +) + +func (c *SQLiteConn) loadExtensions(extensions []string) error { + rv := C.sqlite3_enable_load_extension(c.db, 1) + if rv != C.SQLITE_OK { + return errors.New(C.GoString(C.sqlite3_errmsg(c.db))) + } + + for _, extension := range extensions { + cext := C.CString(extension) + defer C.free(unsafe.Pointer(cext)) + rv = C.sqlite3_load_extension(c.db, cext, nil, nil) + if rv != C.SQLITE_OK { + return errors.New(C.GoString(C.sqlite3_errmsg(c.db))) + } + } + + rv = C.sqlite3_enable_load_extension(c.db, 0) + if rv != C.SQLITE_OK { + return errors.New(C.GoString(C.sqlite3_errmsg(c.db))) + } + return nil +} -- cgit v1.2.3