doucong1992
2017-10-30 06:15
浏览 976

如何在golang中获取mySQL错误类型?

I'm really confused how to get the error type from a failed query line with the mySQL import. There is no real documentation on it, so it has me real confused.

Currently i have:

result, err := db.Exec("INSERT INTO users (username,password,email) VALUES (?,?,?)", username, hashedPassword, email)
if err != nil {
    // handle different types of errors here
    return
}

I could print err but its just a string, not liking the idea of peeking at strings to know what went wrong, is there no feedback to get an error code to perform a switch on or something along those lines? How do you do it?

图片转代码服务由CSDN问答提供 功能建议

我真的很困惑如何使用mySQL导入从失败的查询行中获取错误类型。 </ p>

目前我没有:</ p>

 结果,错误:= db  .Exec(“插入用户(用户名,密码,电子邮件)值(?,?,?)”,用户名,hashedPassword,电子邮件)
if err!= nil {
 //在此处处理不同类型的错误
返回 
} 
 </ code> </ pre> 
 
 

我可以打印err,但是它只是一个字符串,而不喜欢偷看字符串以了解出了什么问题的想法,没有反馈可以得到 一个错误代码来执行 switch </ code>或类似的操作? 你如何做到的?</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题