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

Runtime error in LastInsertId & RowsAffected when using multiple goroutines #31

Closed
iragsdale opened this issue Dec 6, 2012 · 7 comments

Comments

@iragsdale
Copy link

I sometimes get errors when using the driver with multiple goroutines, from the LastInsertId & RowsAffected methods - it appears that sometimes the db field of the SQLiteConn structure is nil:

goroutine 9 [syscall]:
github.com/mattn/go-sqlite3._Cfunc_sqlite3_changes(0x0, 0xf8402f2400)
github.com/mattn/go-sqlite3/_obj/_cgo_defun.c:114 +0x2f
github.com/mattn/go-sqlite3.(_SQLiteResult).RowsAffected(0xf840248c40, 0xf84024b390, 0x0, 0x0)
github.com/mattn/go-sqlite3/_obj/sqlite3.cgo1.go:265 +0x2e
database/sql.(_result).RowsAffected(0xf84024b390, 0xf8401b1a00, 0xfc, 0xf8402f2400)
/usr/local/go/src/pkg/database/sql/convert.go:0 +0x43
github.com/coopernurse/gorp.update(0xf840070d80, 0xf8400960c0, 0xf840070d80, 0x2568f90, 0x100000001, ...)
/Users/gutter/dev/poundsmtp/src/github.com/coopernurse/gorp/gorp.go:1095 +0x386
github.com/coopernurse/gorp.(*DbMap).Update(0xf840070d80, 0x2568f90, 0x100000001, 0xf8400ac510, 0x20ede0, ...)
/Users/gutter/dev/poundsmtp/src/github.com/coopernurse/gorp/gorp.go:658 +0x6e
main.validateMessages(0xf840110c60, 0xf8401adb40, 0x0, 0x0)
/Users/gutter/dev/poundsmtp/src/validate.go:325 +0x4ad
created by main.checkAccount
/Users/gutter/dev/poundsmtp/src/validate.go:84 +0x370

@iragsdale
Copy link
Author

BTW, I'm using gorp (https://github.com/coopernurse/gorp). There doesn't seem to be much happening between the exec & the RowsAffected call:

    res, err := exec.Exec(bi.query, bi.args...)
    if err != nil {
        return -1, err
    }

    rows, err := res.RowsAffected()
    if err != nil {
        return -1, err
    }

@mattn
Copy link
Owner

mattn commented Dec 7, 2012

Could you please show me the code you have?

@iragsdale
Copy link
Author

My code is just calling the Update method on a DBMap struct from the Gorp library, which really just seems to do an Exec & then call RowsAffected on the result. It also happens with the Insert method and LastInsertId.

Code is here: https://github.com/coopernurse/gorp/blob/master/gorp.go

If you want to look at my code, I'm happy to add you to the project - I'm planning on open sourcing it, just waiting on approval from the client.

@mattn
Copy link
Owner

mattn commented Dec 8, 2012

I was fixed about LastInsertId in yesterday. Please check latest.

@mattn mattn closed this as completed Dec 31, 2012
@iragsdale
Copy link
Author

Sorry to take so long to test this out. That doesn't seem to have resolved the issue:

goroutine 21 [syscall]:
github.com/mattn/go-sqlite3._Cfunc__sqlite3_changes(0x0, 0xf840397a00)
github.com/mattn/go-sqlite3/_obj/_cgo_defun.c:58 +0x2f
github.com/mattn/go-sqlite3.(_SQLiteResult).RowsAffected(0xf84039e8f8, 0xf8406dc160, 0x0, 0x0)
github.com/mattn/go-sqlite3/_obj/sqlite3.cgo1.go:264 +0x2e
database/sql.(_result).RowsAffected(0xf8406dc160, 0xf8400a2f00, 0xfc, 0xf840397a00)
/usr/local/go/src/pkg/database/sql/convert.go:0 +0x43

Any other suggestions?

@mattn
Copy link
Owner

mattn commented Jan 4, 2013

github.com/mattn/go-sqlite3._Cfunc__sqlite3_changes(0x0, 0xf840397a00)

It seems that statement object is 0x0. Could you please show me your code?

@iragsdale
Copy link
Author

I'm using the Gorp library. Code for the update method can be found here:
https://github.com/coopernurse/gorp/blob/master/gorp.go#L1078

I don't see any way for the result to be nil unless it somehow returns a nil result with a nil error - is that possible?

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