Added error return to ConnectHook and fixed extension example

The ConnectHook field of an SQLiteDriver should return an error in
case something bad happened during the hook.

The extension example needs to load the extension in a ConnectHook,
otherwise the extension is only loaded in a single connection in the pool.
By putting the extension loading in the ConnectHook, its called for every
connection that is opened by the sql.DB.
This commit is contained in:
Carlos Castillo
2013-08-24 20:04:51 -07:00
parent 248e51c050
commit 976f43861f
2 changed files with 36 additions and 4 deletions

View File

@@ -78,7 +78,7 @@ func init() {
// Driver struct.
type SQLiteDriver struct {
EnableLoadExtension bool
ConnectHook func(*SQLiteConn)
ConnectHook func(*SQLiteConn) error
}
// Conn struct.
@@ -194,7 +194,9 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
conn := &SQLiteConn{db}
if d.ConnectHook != nil {
d.ConnectHook(conn)
if err := d.ConnectHook(conn); err != nil {
return nil, err
}
}
return conn, nil