From da9decb965f9e3c0cf528b5c6bc0896d27896d44 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 18 Apr 2016 17:05:24 +0800 Subject: [PATCH] Expose LoadExtension with entry point --- sqlite3_load_extension.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sqlite3_load_extension.go b/sqlite3_load_extension.go index 0251016..55c8ad7 100644 --- a/sqlite3_load_extension.go +++ b/sqlite3_load_extension.go @@ -37,3 +37,27 @@ func (c *SQLiteConn) loadExtensions(extensions []string) error { } return nil } + +func (c *SQLiteConn) LoadExtension(lib string, entry 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))) + } + + clib := C.CString(lib) + defer C.free(unsafe.Pointer(clib)) + centry := C.CString(entry) + defer C.free(unsafe.Pointer(centry)) + + rv = C.sqlite3_load_extension(c.db, clib, centry, 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 +}