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

get two field from MSSQL by db.Query will get the same field sometimes. #11

Open
zsying opened this issue Jun 27, 2013 · 2 comments
Open

Comments

@zsying
Copy link

zsying commented Jun 27, 2013

In sqlserver2008, as the code sample below, I select "name""name1" from the test table, if the "name1" is NULL, the "name1" value will be the same as "name"

// the code sample
func testDB(db *sql.DB) {
    db.Exec("if object_id(N'test',N'U') is not null drop table test")
    db.Exec("create table test(id int not null primary key, name varchar(20), name1 varchar(20) )")
    for i := 0; i < 4; i++ {
        name := "name" + strconv.Itoa(i)
        name1 := strconv.Itoa(i)
        if i%2 == 1 {
            db.Exec("insert into test(id, name, name1) values(?, ?, ?)", i, name, name1)
        } else {
            db.Exec("insert into test(id, name) values(?, ?)", i, name)
        }
    }

    rows, _ := db.Query("select * from test")
    for rows.Next() {
        var id int
        var name, name1 string
        rows.Scan(&id, &name, &name1)
        log.Printf("result: %d, %s, %s ", id, name, name1)
    }
}
@mattn
Copy link
Owner

mattn commented Aug 24, 2013

Sorry for delay. I'll look into it later.

@mattn
Copy link
Owner

mattn commented Aug 20, 2014

Hmm, I can't reproduce it. Could you please show me what results did you get?

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

2 participants