Giter Site home page Giter Site logo

go-mysql's People

Contributors

serbaut avatar vanackere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

vanackere timob

go-mysql's Issues

Bad driver usage can lead to hard to debug panic

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)
    }
}

Nullable integer column parsing problem

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

Does not handle times to zero

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

Null datetime column should result in nil interface{}

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
}
}

Conection to socket

It does not allows conections via sockets:

panic: invalid scheme: neo@unix(/var/run/mysqld/mysqld.sock)/foo_test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.