第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 golang 中獲取 MySQL 的 BIT(64)

如何在 golang 中獲取 MySQL 的 BIT(64)

Go
絕地?zé)o雙 2022-06-27 17:30:03
我是新手,正在嘗試從 MySQL 讀取數(shù)據(jù)。架構(gòu):“id:INT(11),頭部:TEXT,過濾器:BIT(64)”我試圖以常見的方式做到這一點(diǎn):type News struct {    Id      int    `field:"id"`    Head    string `field:"head"`    Filter  uint64 `field:"filter"`}...rows.Scan(&item.Id, &item.Head, &item.Filter)并得到:Scan error on column index 2, name "filter": converting NULL to uint64 is unsupported我嘗試了一些帶有反射的示例,但沒有結(jié)果。我試過像這里一樣制作自己的類型(真的不明白這個(gè)):type BitMask uint64func (bits *BitMask) Scan(src interface{}) error {    str, ok := src.(string)    if !ok {        return fmt.Errorf("Unexpected type for BitMask: %T\n", src)    }    fmt.Println(str)    //var v uint64 = 0    //*bits = v // <- Also have error here    return nil}并得到類似的錯(cuò)誤:“BitMask 的意外類型:< nil>”
查看完整描述

1 回答

?
哈士奇WWW

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊

我做出這個(gè)答案只是為了結(jié)束問題并總結(jié)結(jié)果。所以有2種方式:


1 編寫自己的類型:


type BitMask sql.NullInt64


func (bits *BitMask) Scan(src interface{}) error {

  if src == nil {

    bits.Int64 = 0

    bits.Valid = false

    return nil

  }

  buf, ok := src.([]byte)

  if !ok {

    return fmt.Errorf("Unexpected type for BitMask: %T\n", src)

  }

  if len(buf) != 8 {

    bits.Int64 = 0

    bits.Valid = false

    return errors.New("Size of bit filed is not 8 bytes\n")

  }

  bits.Int64 = 0

  for i := range buf {

    bits.Int64 *= 256

    bits.Int64 = int64(buf[i])

  }

  bits.Valid = true

  return nil

}

不要使用BIT(64),UNSIGNED BIGINT而是。因?yàn)闆]有優(yōu)勢(shì),只有問題。(這就是我要做的)


查看完整回答
反對(duì) 回復(fù) 2022-06-27
  • 1 回答
  • 0 關(guān)注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)