Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PingGao89 opened this issue Oct 10, 2017 · 3 comments
Closed

Comments

@PingGao89
Copy link

Issue description

Use sql.RawBytes to get an error:
The error appears :values := 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

@julienschmidt
Copy link
Member

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

@PingGao89

This comment has been minimized.

@cuishuang

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants