From 1a763d61c27a9c845b4325cd942d3ebd4b3696e9 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Tue, 1 Apr 2025 13:57:07 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20defer=20?= =?UTF-8?q?rows.Close()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- postgres_pgx/postgres_pgx.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/postgres_pgx/postgres_pgx.go b/postgres_pgx/postgres_pgx.go index 75b5057e..a254db73 100644 --- a/postgres_pgx/postgres_pgx.go +++ b/postgres_pgx/postgres_pgx.go @@ -401,21 +401,21 @@ func GetConnection_WithApplicationName(ApplicationName string) *pgx.Conn { // RawMultipleSQL - выполняет текст запроса, отдельно для каждого запроса func RawMultipleSQL(tx pgx.Tx, TextSQL string) (pgx.Rows, error) { - var Rows pgx.Rows + var rows pgx.Rows var err error if tx == nil { TextError := "RawMultipleSQL() error: tx =nil" log.Error(TextError) err = errors.New(TextError) - return Rows, err + return rows, err } //if tx.IsClosed() { // TextError := "RawMultipleSQL() error: tx is closed" // log.Error(TextError) // err = errors.New(TextError) - // return Rows, err + // return rows, err //} ctx := contextmain.GetContext() @@ -424,7 +424,7 @@ func RawMultipleSQL(tx pgx.Tx, TextSQL string) (pgx.Rows, error) { //tx, err := tx.Begin(ctx) //if err != nil { // log.Error(err) - // return Rows, err + // return rows, err //} //defer tx.Commit() @@ -442,17 +442,18 @@ func RawMultipleSQL(tx pgx.Tx, TextSQL string) (pgx.Rows, error) { TextError := fmt.Sprint("tx.Exec() error: ", err, ", TextSQL: \n", TextSQL1) err = errors.New(TextError) log.Error(err) - return Rows, err + return rows, err } } //запустим последний запрос, с возвратом результата - Rows, err = tx.Query(ctx, TextSQL2) + rows, err = tx.Query(ctx, TextSQL2) if err != nil { TextError := fmt.Sprint("tx.Raw() error: ", err, ", TextSQL: \n", TextSQL2) err = errors.New(TextError) - return Rows, err + return rows, err } + defer rows.Close() - return Rows, err + return rows, err }