Home > Back-end >  Is there any solution to the not authorized error?
Is there any solution to the not authorized error?

Time:01-25

sqlite3, err := sql.Open("sqlite3", "./map.gpkg")
if err != nil {
    panic(err.Error())
}

_, err = sqlite3.Exec("select load_extension('mod_spatialite');")
if err != nil {
    panic(err.Error())
}

When I try to load spatialite extension into sqlite3, it returns a not authorized error, I don't know how to fix it.

panic: not authorized

goroutine 1 [running]:
main.main()
        /Users/u/project/project/golang_project/pack/sql/main.go:42  0x145
exit status 2

CodePudding user response:

You need to register extension using Extensions field of SQLiteDriver:

sql.Register("sqlite3_TestExtensionsError",
    &sqlite3.SQLiteDriver{
        Extensions: []string{
            "foobar",
        },
    },
)

See this example: https://github.com/mattn/go-sqlite3/blob/1157a4212dcb650962563f67cd405794e9115b45/sqlite3_load_extension_test.go#L15

  •  Tags:  
  • Related