This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Bind 字段为NULL时出错 #4
Comments
Golang 預設不能存放 NULL 型態,如果你要對應 NULL 值,假設你有個 String 型態,你需要改用 sql.NullString(因為 Golang 的 String 零值是 |
因為 Golang 裏針對資料庫的 NULL 處理起來會令人棘手,所以通常不建議設計有 NULL 的資料表。
|
这我知道的.我记得xorm null 返回的是 "" ,而不是error。 |
如果要將 NULL 自動轉換成型態的零值⋯⋯那可能就要改一下程式碼了, 我需要稍微看一下 |
好的,非常感谢 |
研究了一下,這個錯誤來自 Reiner 底層的 SQL Driver(go-sql-driver)。
看起來現在底層的 Driver 有強制一項規則:如果欄位有機會是 NULL 值,就必須改用 感覺⋯⋯更棘手啦。 |
辛苦了,我先使用sql.NullString解决当前问题,等空了我查阅资料找找解决办法 |
@YamiOdymel 你好,近期有计划优化性能吗? |
@xiake999 抱歉,目前還沒有打算,可能會在九月之後再來研究 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
@YamiOdymel 数据值为NULL时,Bind 出错:
应该返回为空才对吧? 字段是默认值是NULL,不能因为这个问题程序出错?
The text was updated successfully, but these errors were encountered: