Mysql: sql.RawBytes undefined (type string has no field or method RawBytes)

Created on 10 Oct 2017  路  3Comments  路  Source: go-sql-driver/mysql

Issue description

Use sql.RawBytes to get an error:
The error appears 锛歷alues := make([]sql.RawBytes, len(c))

Example code

sql := `select * from table`
    if rows, err := td.db.Query(sql); err == nil {
        if c, er := rows.Columns(); er == nil {
            values := make([]sql.RawBytes, len(c))
            scanArgs := make([]interface{}, len(values))
            for i := range values {
                scanArgs[i] = &values[i]
            }
            for rows.Next() {
                if er = rows.Scan(scanArgs...); er == nil {
                    for i, cc := range c {
                         fmt.Println(scanArgs[i])
                    }
                }
            }

        }
    }

Error log

sql.RawBytes undefined (type string has no field or method RawBytes)

Configuration

Driver version (or git SHA):
1.3
Go version: run go version in your console
go1.9
Server version: E.g. MySQL 5.6, MariaDB 10.0.20
MySQL5.5
Server OS: E.g. Debian 8.1 (Jessie), Windows 10
CentOS6

Most helpful comment

you masked the database/sql package here: sql := `select * from table
sql is then a string, not the package. Rename the string e.g. to query and it will work

All 3 comments

you masked the database/sql package here: sql := `select * from table
sql is then a string, not the package. Rename the string e.g. to query and it will work

馃憣

3Q 3Q

Was this page helpful?
0 / 5 - 0 ratings