@@ -39,7 +39,7 @@ type TxnFunc func(SQTransaction) error
3939// LIFECYCLE
4040
4141func OpenPath (path string , flags sqlite3.OpenFlags ) (* Conn , error ) {
42- poolconn := new (Conn )
42+ conn := new (Conn )
4343
4444 // If no create flag then check to make sure database exists
4545 if path != defaultMemory && flags & sqlite3 .SQLITE_OPEN_CREATE == 0 {
@@ -51,22 +51,29 @@ func OpenPath(path string, flags sqlite3.OpenFlags) (*Conn, error) {
5151 }
5252
5353 // Open database with flags
54- if conn , err := sqlite3 .OpenPathEx (path , flags , "" ); err != nil {
54+ if c , err := sqlite3 .OpenPathEx (path , flags , "" ); err != nil {
5555 return nil , err
5656 } else {
57- poolconn .ConnEx = conn
57+ conn .ConnEx = c
58+ }
59+
60+ // Set cache to default size
61+ if flags & sqlite3 .SQLITE_OPEN_CONNCACHE != 0 {
62+ conn .SetCap (defaultCapacity )
63+ } else {
64+ conn .SetCap (0 )
5865 }
5966
6067 // Finalizer to panic when connection not closed before garbage collection
6168 _ , file , line , _ := runtime .Caller (1 )
62- runtime .SetFinalizer (poolconn , func (conn * Conn ) {
69+ runtime .SetFinalizer (conn , func (conn * Conn ) {
6370 if conn .c != nil {
6471 panic (fmt .Sprintf ("%s:%d: missing associated call to Close()" , file , line ))
6572 }
6673 })
6774
6875 // Return success
69- return poolconn , nil
76+ return conn , nil
7077}
7178
7279func (conn * Conn ) Close () error {
@@ -139,13 +146,21 @@ func (conn *Conn) Do(ctx context.Context, flag SQTxnFlag, fn func(SQTransaction)
139146
140147 // Commit or rollback transaction
141148 if result == nil {
142- result = multierror .Append (result , conn .ConnEx .Commit ())
149+ if err := conn .ConnEx .Commit (); err != nil {
150+ result = multierror .Append (result , err )
151+ }
143152 } else {
144- result = multierror .Append (result , conn .ConnEx .Rollback ())
153+ if err := conn .ConnEx .Rollback (); err != nil {
154+ result = multierror .Append (result , err )
155+ }
145156 }
146157
147- // Return foreign key constraints
148- result = multierror .Append (result , conn .SetForeignKeyConstraints (fk ))
158+ // Return foreign key constraints to previous value
159+ if flag & SQLITE_TXN_NO_FOREIGNKEY_CONSTRAINTS != 0 {
160+ if err := conn .SetForeignKeyConstraints (fk ); err != nil {
161+ result = multierror .Append (result , err )
162+ }
163+ }
149164
150165 // Return any errors
151166 return result
0 commit comments