mirror of https://github.com/mattn/go-sqlite3.git
load extensions using the C API instead of SQL
This fixes the problem of loading ICU, which needs to replace existing functions. Replacing existing functions are prohibited when a VM is running.
This commit is contained in:
parent
a141177ca6
commit
0486deea0d
16
sqlite3.go
16
sqlite3.go
|
@ -287,21 +287,15 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
|||
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 {
|
||||
if _, err = stmt.Exec([]driver.Value{extension}); err != nil {
|
||||
return nil, err
|
||||
cext := C.CString(extension)
|
||||
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)
|
||||
if rv != C.SQLITE_OK {
|
||||
return nil, errors.New(C.GoString(C.sqlite3_errmsg(db)))
|
||||
|
|
Loading…
Reference in New Issue