mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Fix batch query with query syntax error
This commit is contained in:
parent
dde965bc9d
commit
79517aaa0e
15
batch.go
15
batch.go
@ -167,25 +167,28 @@ func (b *Batch) ExecResults() (CommandTag, error) {
|
|||||||
// QueryResults reads the results from the next query in the batch as if the
|
// QueryResults reads the results from the next query in the batch as if the
|
||||||
// query has been sent with Query.
|
// query has been sent with Query.
|
||||||
func (b *Batch) QueryResults() (*Rows, error) {
|
func (b *Batch) QueryResults() (*Rows, error) {
|
||||||
|
rows := b.conn.getRows("batch query", nil)
|
||||||
|
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return nil, b.err
|
rows.fatal(b.err)
|
||||||
|
return rows, b.err
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-b.ctx.Done():
|
case <-b.ctx.Done():
|
||||||
b.die(b.ctx.Err())
|
b.die(b.ctx.Err())
|
||||||
return nil, b.ctx.Err()
|
rows.fatal(b.err)
|
||||||
|
return rows, b.ctx.Err()
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
b.resultsRead++
|
b.resultsRead++
|
||||||
|
|
||||||
rows := b.conn.getRows("batch query", nil)
|
|
||||||
|
|
||||||
fieldDescriptions, err := b.conn.readUntilRowDescription()
|
fieldDescriptions, err := b.conn.readUntilRowDescription()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.die(b.ctx.Err())
|
b.die(err)
|
||||||
return nil, err
|
rows.fatal(b.err)
|
||||||
|
return rows, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rows.batch = b
|
rows.batch = b
|
||||||
|
@ -442,3 +442,37 @@ func TestConnBeginBatchQueryError(t *testing.T) {
|
|||||||
t.Error("conn should be dead, but was alive")
|
t.Error("conn should be dead, but was alive")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConnBeginBatchQuerySyntaxError(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
conn := mustConnect(t, *defaultConnConfig)
|
||||||
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
batch := conn.BeginBatch()
|
||||||
|
batch.Queue("select 1 1",
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
[]int16{pgx.BinaryFormatCode},
|
||||||
|
)
|
||||||
|
|
||||||
|
err := batch.Send(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var n int32
|
||||||
|
err = batch.QueryRowResults().Scan(&n)
|
||||||
|
if pgErr, ok := err.(pgx.PgError); !(ok && pgErr.Code == "42601") {
|
||||||
|
t.Errorf("rows.Err() => %v, want error code %v", err, 42601)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = batch.Close()
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Expected error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if conn.IsAlive() {
|
||||||
|
t.Error("conn should be dead, but was alive")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user