英文:
Is there any solution to the not authorized error?
问题
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())
}
当我尝试将spatialite扩展加载到sqlite3中时,它返回一个未授权的错误,我不知道如何修复它。
panic: not authorized
goroutine 1 [running]:
main.main()
/Users/u/project/project/golang_project/pack/sql/main.go:42 +0x145
exit status 2
英文:
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
答案1
得分: 1
你需要使用SQLiteDriver的Extensions字段来注册扩展:
sql.Register("sqlite3_TestExtensionsError",
&sqlite3.SQLiteDriver{
Extensions: []string{
"foobar",
},
},
)
可以参考这个示例:https://github.com/mattn/go-sqlite3/blob/1157a4212dcb650962563f67cd405794e9115b45/sqlite3_load_extension_test.go#L15
英文:
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
答案2
得分: 0
sql.Register("sqlite3_with_extensions",
&sqlite3.SQLiteDriver{
Extensions: []string{
"mod_spatialite",
},
})
db, err := sql.Open("sqlite3_with_extensions", "./map.gpkg")
if err != nil {
panic(err.Error())
}
我将代码更改如上所示,我的代码正常工作。
英文:
sql.Register("sqlite3_with_extensions",
&sqlite3.SQLiteDriver{
Extensions: []string{
"mod_spatialite",
},
})
db, err := sql.Open("sqlite3_with_extensions", "./map.gpkg")
if err != nil {
panic(err.Error())
}
i changed code as above and my code working fine.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论