diff --git a/prepare_stmt.go b/prepare_stmt.go index 0f112a7f..e017bb23 100644 --- a/prepare_stmt.go +++ b/prepare_stmt.go @@ -60,6 +60,7 @@ func (db *PreparedStmtDB) ExecContext(ctx context.Context, query string, args .. return stmt.ExecContext(ctx, args...) } else { db.mux.Lock() + stmt.Close() delete(db.Stmts, query) db.mux.Unlock() } @@ -72,6 +73,7 @@ func (db *PreparedStmtDB) QueryContext(ctx context.Context, query string, args . return stmt.QueryContext(ctx, args...) } else { db.mux.Lock() + stmt.Close() delete(db.Stmts, query) db.mux.Unlock() } @@ -84,6 +86,7 @@ func (db *PreparedStmtDB) QueryRowContext(ctx context.Context, query string, arg return stmt.QueryRowContext(ctx, args...) } else { db.mux.Lock() + stmt.Close() delete(db.Stmts, query) db.mux.Unlock() } @@ -101,6 +104,7 @@ func (tx *PreparedStmtTX) ExecContext(ctx context.Context, query string, args .. return tx.Tx.Stmt(stmt).ExecContext(ctx, args...) } else { tx.PreparedStmtDB.mux.Lock() + stmt.Close() delete(tx.PreparedStmtDB.Stmts, query) tx.PreparedStmtDB.mux.Unlock() } @@ -113,6 +117,7 @@ func (tx *PreparedStmtTX) QueryContext(ctx context.Context, query string, args . return tx.Tx.Stmt(stmt).QueryContext(ctx, args...) } else { tx.PreparedStmtDB.mux.Lock() + stmt.Close() delete(tx.PreparedStmtDB.Stmts, query) tx.PreparedStmtDB.mux.Unlock() } @@ -125,6 +130,7 @@ func (tx *PreparedStmtTX) QueryRowContext(ctx context.Context, query string, arg return tx.Tx.Stmt(stmt).QueryRowContext(ctx, args...) } else { tx.PreparedStmtDB.mux.Lock() + stmt.Close() delete(tx.PreparedStmtDB.Stmts, query) tx.PreparedStmtDB.mux.Unlock() } diff --git a/tests/go.mod b/tests/go.mod index c467f34b..3b17feac 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -6,11 +6,11 @@ require ( github.com/google/uuid v1.1.1 github.com/jinzhu/now v1.1.1 github.com/lib/pq v1.6.0 - gorm.io/driver/mysql v0.2.7 - gorm.io/driver/postgres v0.2.4 + gorm.io/driver/mysql v0.2.8 + gorm.io/driver/postgres v0.2.5 gorm.io/driver/sqlite v1.0.8 gorm.io/driver/sqlserver v0.2.4 - gorm.io/gorm v0.2.9 + gorm.io/gorm v0.2.19 ) replace gorm.io/gorm => ../ diff --git a/tests/tests_test.go b/tests/tests_test.go index fa8bad5c..9484b897 100644 --- a/tests/tests_test.go +++ b/tests/tests_test.go @@ -54,7 +54,10 @@ func OpenTestConnection() (db *gorm.DB, err error) { if dbDSN == "" { dbDSN = "user=gorm password=gorm DB.name=gorm port=9920 sslmode=disable TimeZone=Asia/Shanghai" } - db, err = gorm.Open(postgres.Open(dbDSN), &gorm.Config{}) + db, err = gorm.Open(postgres.New(postgres.Config{ + DSN: dbDSN, + PreferSimpleProtocol: true, + }), &gorm.Config{}) case "sqlserver": // CREATE LOGIN gorm WITH PASSWORD = 'LoremIpsum86'; // CREATE DATABASE gorm;