dsn5510 2018-03-13 22:57
浏览 63

如何在GoLang中从Oracle(长原始格式)读取图像

I am trying to read images (in long raw datatype) from external Oracle database using Golang code.

When sql's row.Next() is called following error is caught: ORA-01406: fetched column value was truncated

row.Next works fine for reading blob images from mssql DB.

Example code:

db, err := sql.Open("oci8", getDSN()) //function to get connection details 
    if err != nil {
        fmt.Println(err)
        return
    }
    defer db.Close()
    rows, err := db.Query("SELECT image FROM sysadm.all_images")
    if err != nil {
        fmt.Println(err)
        return
    }
    defer rows.Close()
    for rows.Next() {
       var id string
       var data []byte
       rows.Scan(&id, &data)    
    }
    fmt.Println("Total errors", rows.Err())
}

I hope someone can help me to fix this issue or pinpoint to problem area.

  • 写回答

1条回答 默认 最新

  • dscrb00804 2018-03-14 04:39
    关注

    I assume you are using go-oci8 as the driver.

    Based on this issue https://github.com/mattn/go-oci8/pull/71 there are someone who get the same error like yours, and then managed to fix it by modifying some codes on the driver.

    As per this commit, the problem is already solved by increasing the value of oci8cols[i].size on file $GOPATH/src/github.com/mattn/go-oci8/oci8.go. I think in your case you have bigger blob data, that's why the revision is still not working.

    case C.SQLT_NUM:
        oci8cols[i].kind = C.SQLT_CHR
        oci8cols[i].size = int(lp * 4) // <==== THIS VALUE
        oci8cols[i].pbuf = C.malloc(C.size_t(oci8cols[i].size) + 1)
    

    So, try to increase the multiplier, like:

    oci8cols[i].size = int(lp * 12) // <==== OR GREATER
    
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题