sqlite: implement driver.SessionResetter and driver.Validator#72
sqlite: implement driver.SessionResetter and driver.Validator#72
Conversation
These implementations enable us to maintain connections in database/sql pools. Fixes #70
| if c.stmts != nil { | ||
| for _, s := range c.stmts { | ||
| if err := s.resetAndClear(); err != nil { | ||
| return err |
There was a problem hiding this comment.
Should this return ErrBadConn?
There was a problem hiding this comment.
In the above case we could and probably should. In this particular case, that's unclear because:
ErrBadConn should be returned by a driver to signal to the sql package that a driver.Conn is in a bad state (such as the server having earlier closed the connection) and the sql package should retry on a new connection.
To prevent duplicate operations, ErrBadConn should NOT be returned if there's a possibility that the database server might have performed the operation. Even if the server sends back an error, you shouldn't return ErrBadConn.
Errors will be checked using errors.Is. An error may wrap ErrBadConn or implement the Is(error) bool method.
If we have potentially completed a tx we can not disambiguate between these conditions so we should not match BadConn.
crawshaw
left a comment
There was a problem hiding this comment.
can we generate the sort of error that gets database/sql to call ResetSession? if so, can you write a unit test that exercises this code?
| } | ||
|
|
||
| // ensure that all prepared statements are reset and unbound | ||
| if c.stmts != nil { |
There was a problem hiding this comment.
nil check is redundant because a range over a nil map does nothing
|
|
||
| // ensure that all prepared statements are reset and unbound | ||
| if c.stmts != nil { | ||
| for _, s := range c.stmts { |
There was a problem hiding this comment.
this is almost right. in practice it would basically work. but the problem are statements created with persist=false, which don't get put into c.stmts.
|
I can reverse it. It's absent from the docs. We do do have stats showing that we're not retaining cons. Either way yeah, I'll find a way to make some tests. |
These implementations enable us to maintain connections in database/sql pools.
Fixes #70