serbaut / go-mysql Goto Github PK
View Code? Open in Web Editor NEWMySQL driver for Go database/sql
License: MIT License
MySQL driver for Go database/sql
License: MIT License
A small mistake, like using Query instead of Exec, can lead to hard to debug situations because the next request will then panic in strange ways if within a transaction.
If possible, the driver should handle those situations better.
To reproduce, insert the following code into mysql_test.go for 2 different crashes that can be seen (there may be other cases) :
func TestUsageError1(t *testing.T) {
_testUsageError(t, 1)
}
func TestUsageError2(t *testing.T) {
_testUsageError(t, 2)
}
func _testUsageError(t *testing.T, testCase int) {
db, err := sql.Open("mysql", dsn2)
if err != nil {
t.Fatal(err)
}
defer db.Close()
if _, err = db.Exec("create temporary table gotest (id int)"); err != nil {
t.Fatal(err)
}
tx, err := db.Begin()
if err != nil {
t.Fatal(err)
}
if _, err = tx.Exec("insert into gotest values (1),(1),(2)"); err != nil {
t.Fatal(err)
}
switch testCase {
case 1:
if _, err := tx.Query("select * from gotest where id = ?", 4); err != nil {
t.Fatal(err)
}
var id int
if err = tx.QueryRow("select * from gotest where id = ?", 1).Scan(&id); err != nil {
t.Fatal(err)
}
case 2:
if _, err := tx.Query("select * from gotest where id = ?", 1); err != nil {
t.Fatal(err)
}
var id int
if err = tx.QueryRow("select * from gotest where id = ?", 1).Scan(&id); err != nil {
t.Fatal(err)
}
}
err = tx.Rollback()
if err != nil {
t.Fatal(err)
}
}
Table has "Nullable" integer column
and Selected row include Null value at integer colunm.
error log :
sql: Scan error on column index 3: converting string "" to a int64: strconv.ParseInt: parsing "": invalid syntax
http://golang.org/pkg/time/#Time
The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC. As this time is unlikely to come up in practice, the IsZero method gives a simple way of detecting a time that has not been initialized explicitly.
CREATE TABLE times (
typeId INT,
datetime TIMESTAMP
);
INSERT INTO times (typeId, datetime)
VALUES(1, '0001-01-01T00:00:00Z');
query: "SELECT * FROM times WHERE typeId = 1"
sql: Scan error on column index 1: unsupported driver -> Scan pair: -> *time.Time
I think the driver should return a nil interface{} rather than a time.Time{}, it makes checking for nulls in an application easier, because it can be done more generally without knowing the column type.
Tim
see:
func (p *packet) ReadValue(coltype byte, flags uint16, isnull bool) (v interface{}, err error) {
if isnull {
switch coltype {
case MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATE, MYSQL_TYPE_NEWDATE:
return time.Time{}, nil
case MYSQL_TYPE_TIME:
return time.Duration(0), nil
default:
return nil, nil
}
}
It does not allows conections via sockets:
panic: invalid scheme: neo@unix(/var/run/mysqld/mysqld.sock)/foo_test
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.