Comments (3)
Using the delve
debugger, I dug into the go-sql-driver
code and discovered that Row.Scan
calls binaryRows.Next
and Rows.Scan
calls textRows.Next
. This explains why QueryRow
returns the correct types but Query
returns []uint8
for all columns. The question now is why Rows.Scan
doesn't call binaryRows.Next
as well. I will dig on.
from mysql.
Another discovery.
My original code, which makes use of Query
produces the wrong results.
// Query will call the go-sql-driver's textRows.Next function, which presents []uint8 (strings) to all the scanners.
rows, err := db.Query("select * from fruits;")
// err is nil
defer rows.Close()
for rows.Next() {
err := rows.Scan(id_scanner, name_scanner, year_scanner, amount_scanner, price_scanner)
// err is nil, but output is wrong
}
But I can get the right output with Prepare
, calling Query
via the statement object.
statement, err := db.Prepare("select * from fruits;")
// err is ni
rows, err := statement.Query()
// err is nil
defer rows.Close()
for rows.Next() {
err := rows.Scan(id_scanner, name_scanner, year_scanner, amount_scanner, price_scanner)
// err is nil, and output is the same as that produced by Row.Scan
}
The mysqlConn.queyy
returns textRows
while mysqlStmt.query
returns *binaryRows.
from mysql.
Using placeholder makes your query binary.
When implementing Scanner, you should expect many driver.Value
type input, not single consistent one.
See #1452 for mitigations implemented in next release.
from mysql.
Related Issues (20)
- ENUM and SET column types cannot be identified HOT 3
- 'go get' no longer supported HOT 1
- Please update documentation (installation - go get -u github.com/go-sql-driver/mysql fails for newer go versions) HOT 1
- BUG: resource don't release when db.Exec have error. HOT 8
- DSN: support - in database name HOT 2
- context deadline exceeded HOT 1
- panic in escapeStringBackslash HOT 3
- Empty result with max unsigned int value
- For some reason the data is not showing. HOT 1
- Cut a new v1.7.2 release HOT 14
- Potential out of bound access in `(*mysqlConn).handleErrorPacket` HOT 7
- Toggle Click in Leaderboards
- mysql startWatcher panic error HOT 3
- Bizarre hanging issue in rows.Close() HOT 7
- Can't Install, bug in edwards25519/scalar.go HOT 1
- Likely race that can prevent to recycle closed connections HOT 5
- Return timeout error instead of Invalid connection err when read packet network timeout HOT 5
- 保存时报错:Prepared statement contains too many placeholders
- too may ram usage when lost connection HOT 13
- SEGV writing packet HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mysql.