【发布时间】:2022-01-22 21:40:05
【问题描述】:
我正在尝试扫描查询返回的行,但出现此错误
panic: (func() string) 0xc0000ac108
goroutine 1 [running]:
main.main()
C:/Users/User/OneDrive/Dokumente/AIR/go/access/showAccess.go:35 +0x445
exit status 2
,我不明白。所有变量的类型都是正确的,Scan 应该直接转换类型。代码如下:
var (
id int
operation string
time string
operator int
)
// query for all records in accesses table
rows, err := DBClient.Query("SELECT * FROM accesses")
if err != nil {
panic(err.Error)
}
defer rows.Close()
// printing each record formatted
for rows.Next() {
if err := rows.Scan(&id, &operation, &time, &operator); err != nil {
panic(err.Error) // here the error comes
}
fmt.Printf("ID: %3d, operation: %20s, time: %20s, operator: %d\n",
id, operation, time, operator)
}
珍惜你的时间。
【问题讨论】:
-
什么是数据库架构?
-
您将 func Error() 发送到恐慌中而不是对其进行操作,将其更改为
panic(err.Error())以获取实际错误,然后编辑问题以包含错误消息。另外,正如 aureliar 所说,数据库的架构是什么。