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

LastInsertId returning wrong id #30

Closed
matrixik opened this issue Dec 6, 2012 · 2 comments
Closed

LastInsertId returning wrong id #30

matrixik opened this issue Dec 6, 2012 · 2 comments

Comments

@matrixik
Copy link
Contributor

matrixik commented Dec 6, 2012

Sample code:

package main

import (
    "database/sql"
    "fmt"
    _ "github.com/mattn/go-sqlite3"
    "os"
)

func main() {
    os.Remove("./foo.db")

    db, err := sql.Open("sqlite3", "./foo.db")
    if err != nil {
        fmt.Println(err)
        return
    }
    defer db.Close()

    sql := "create table foo (id integer PRIMARY KEY AUTOINCREMENT NOT NULL, name text)"

    _, err = db.Exec(sql)
    if err != nil {
        fmt.Printf("%q: %s\n", err, sql)
        return
    }

    result, err := db.Exec("insert into foo(name) values(1)")
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println(result.LastInsertId())
    return
}

printing 4294967296 <nil>, should print 1 <nil>.

Can someone else confirm it?

Windows 7 x32, Go 1.0.3, last go-sqlite3.

Best regards

@mattn
Copy link
Owner

mattn commented Dec 7, 2012

Try in latest.

@matrixik
Copy link
Contributor Author

matrixik commented Dec 7, 2012

Working, thank you.

@matrixik matrixik closed this as completed Dec 7, 2012
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