mirror of
https://github.com/jackc/pgx.git
synced 2025-04-27 13:14:32 +00:00
Fix queryRow leftover message on conn
those leftover messages are tossed by ensureConnectionReadyForQuery but in the batch use case this is not called between each query.
This commit is contained in:
parent
fd7b776540
commit
b4f9d149c1
@ -476,3 +476,52 @@ func TestConnBeginBatchQuerySyntaxError(t *testing.T) {
|
|||||||
t.Error("conn should be dead, but was alive")
|
t.Error("conn should be dead, but was alive")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConnBeginBatchSelectInsert(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
conn := mustConnect(t, *defaultConnConfig)
|
||||||
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
sql := `create temporary table ledger(
|
||||||
|
id serial primary key,
|
||||||
|
description varchar not null,
|
||||||
|
amount int not null
|
||||||
|
);`
|
||||||
|
mustExec(t, conn, sql)
|
||||||
|
|
||||||
|
batch := conn.BeginBatch()
|
||||||
|
batch.Queue("select 1",
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
[]int16{pgx.BinaryFormatCode},
|
||||||
|
)
|
||||||
|
batch.Queue("insert into ledger(description, amount) values($1, $2),($1, $2)",
|
||||||
|
[]interface{}{"q1", 1},
|
||||||
|
[]pgtype.OID{pgtype.VarcharOID, pgtype.Int4OID},
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
err := batch.Send(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var value int
|
||||||
|
err = batch.QueryRowResults().Scan(&value)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ct, err := batch.ExecResults()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if ct.RowsAffected() != 2 {
|
||||||
|
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
batch.Close()
|
||||||
|
|
||||||
|
ensureConnValid(t, conn)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user