From bf88663d691b9f2fbc87966e8aada869fd80bd0b Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Tue, 11 Jun 2024 13:45:55 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20tx=20pgx?= =?UTF-8?q?.Tx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- postgres_pgx/postgres_pgx.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/postgres_pgx/postgres_pgx.go b/postgres_pgx/postgres_pgx.go index 97501bdf..7751c191 100644 --- a/postgres_pgx/postgres_pgx.go +++ b/postgres_pgx/postgres_pgx.go @@ -349,28 +349,28 @@ func GetConnection_WithApplicationName(ApplicationName string) *pgx.Conn { } // RawMultipleSQL - выполняет текст запроса, отдельно для каждого запроса -func RawMultipleSQL(db *pgx.Conn, TextSQL string) (pgx.Rows, error) { +func RawMultipleSQL(tx pgx.Tx, TextSQL string) (pgx.Rows, error) { var Rows pgx.Rows var err error - if db == nil { - TextError := "RawMultipleSQL() error: db =nil" + if tx == nil { + TextError := "RawMultipleSQL() error: tx =nil" log.Error(TextError) err = errors.New(TextError) return Rows, err } - if db.IsClosed() { - TextError := "RawMultipleSQL() error: db is closed" - log.Error(TextError) - err = errors.New(TextError) - return Rows, err - } + //if tx.IsClosed() { + // TextError := "RawMultipleSQL() error: tx is closed" + // log.Error(TextError) + // err = errors.New(TextError) + // return Rows, err + //} ctx := contextmain.GetContext() //запустим транзакцию - //tx, err := db.Begin(ctx) + //tx, err := tx.Begin(ctx) //if err != nil { // log.Error(err) // return Rows, err @@ -386,9 +386,9 @@ func RawMultipleSQL(db *pgx.Conn, TextSQL string) (pgx.Rows, error) { if pos1 > 0 { TextSQL1 = TextSQL[0:pos1] TextSQL2 = TextSQL[pos1:] - _, err := db.Exec(ctx, TextSQL1) + _, err := tx.Exec(ctx, TextSQL1) if err != nil { - TextError := fmt.Sprint("db.Exec() error: ", err, ", TextSQL: \n", TextSQL1) + TextError := fmt.Sprint("tx.Exec() error: ", err, ", TextSQL: \n", TextSQL1) err = errors.New(TextError) log.Error(err) return Rows, err @@ -396,9 +396,9 @@ func RawMultipleSQL(db *pgx.Conn, TextSQL string) (pgx.Rows, error) { } //запустим последний запрос, с возвратом результата - Rows, err = db.Query(ctx, TextSQL2) + Rows, err = tx.Query(ctx, TextSQL2) if err != nil { - TextError := fmt.Sprint("db.Raw() error: ", err, ", TextSQL: \n", TextSQL2) + TextError := fmt.Sprint("tx.Raw() error: ", err, ", TextSQL: \n", TextSQL2) err = errors.New(TextError) return Rows, err }