-
Notifications
You must be signed in to change notification settings - Fork 8
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
sqlite: implement driver.SessionResetter and driver.Validator #72
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,6 +275,32 @@ func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, e | |
// Raw is so ConnInitFunc can cast to SQLConn. | ||
func (c *conn) Raw(fn func(any) error) error { return fn(c) } | ||
|
||
// ResetSession is called prior to executing a query on the connection | ||
// if the connection has been used before. If the driver returns ErrBadConn | ||
// the connection is discarded. | ||
func (c *conn) ResetSession(ctx context.Context) error { | ||
if c.txState != txStateNone { | ||
return errors.New("cannot ResetSession on a connection with an active transaction") | ||
} | ||
|
||
// 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is almost right. in practice it would basically work. but the problem are statements created with |
||
if err := s.resetAndClear(); err != nil { | ||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this return ErrBadConn? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the above case we could and probably should. In this particular case, that's unclear because:
If we have potentially completed a tx we can not disambiguate between these conditions so we should not match BadConn. |
||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// IsValid is called prior to placing the connection into the | ||
// connection pool. The connection will be discarded if false is returned. | ||
func (c *conn) IsValid() bool { | ||
return true | ||
} | ||
|
||
type readOnlyKey struct{} | ||
|
||
// ReadOnly applies the query_only pragma to the connection. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nil check is redundant because a range over a nil map does nothing