Merge pull request #170 from tajtiattila/master

load extensions using the C API instead of SQL
This commit is contained in:
mattn 2015-01-27 09:19:21 +09:00
commit 25d045f12a
1 changed files with 5 additions and 11 deletions

View File

@ -287,21 +287,15 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
return nil, errors.New(C.GoString(C.sqlite3_errmsg(db))) return nil, errors.New(C.GoString(C.sqlite3_errmsg(db)))
} }
stmt, err := conn.Prepare("SELECT load_extension(?);")
if err != nil {
return nil, err
}
for _, extension := range d.Extensions { for _, extension := range d.Extensions {
if _, err = stmt.Exec([]driver.Value{extension}); err != nil { cext := C.CString(extension)
return nil, err defer C.free(unsafe.Pointer(cext))
rv = C.sqlite3_load_extension(db, cext, nil, nil)
if rv != C.SQLITE_OK {
return nil, errors.New(C.GoString(C.sqlite3_errmsg(db)))
} }
} }
if err = stmt.Close(); err != nil {
return nil, err
}
rv = C.sqlite3_enable_load_extension(db, 0) rv = C.sqlite3_enable_load_extension(db, 0)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return nil, errors.New(C.GoString(C.sqlite3_errmsg(db))) return nil, errors.New(C.GoString(C.sqlite3_errmsg(db)))