-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Prepared statement are broken after sqlite error #150
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
Comments
Once you get error for the statement, you need to make it again. |
but you can make this transparently right? Otherwise i have to do it all over the code. This would not be DRY. |
Hmm, this driver doesn't know whether the code need to make same statement again. |
I implemented a mechanism in my pull request. Please review. |
_, e1 := stmt.Exec("test")
if e1 != nil {
return e1
} We may not want to repair statement. Sorry this is a spec of my driver. |
MySQL and ProstgreSQL don't behave like this. I think it breaks the go database/sql interface. |
BTW, why e4 should be error? When e3 is nil, test1 is inserted. So e4 should not be nil, I think. |
If that e4 is not nil is right behavior, this issue will be fixed by below's patch. diff --git a/sqlite3.go b/sqlite3.go
index abfc2fe..c5c25ed 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -425,10 +425,12 @@ func (r *SQLiteResult) RowsAffected() (int64, error) {
// Execute the statement with arguments. Return result object.
func (s *SQLiteStmt) Exec(args []driver.Value) (driver.Result, error) {
if err := s.bind(args); err != nil {
+ C.sqlite3_reset(s.s)
return nil, err
}
rv := C.sqlite3_step(s.s)
if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE {
+ C.sqlite3_reset(s.s)
return nil, s.c.lastError()
}
|
Correct, if e2 doesn't break the stmt, e3 will not be set and e4 will then be an error. If the diff you proposes fixes the problem I would appreciate the change. I could tell you then if it works like MySQL and PostgreSQL. |
This got me stuck for a while. I updated because of this thread, and now it works fine. Thanks! |
I created a prepared statement for an
INSERT
. If the insert failed, e.g. because aUNIQUE
constraint was violated, the prepared statement is broken and needs to be recreated in order to work again.I have an example project, here where you can find the code to recreate the statement. If i remove it, my tests fail. I created a simple version of the problem here:
The text was updated successfully, but these errors were encountered: