Fix pipeline prepare query without row results

pull/1281/head
Jack Christensen 2022-07-09 08:32:12 -05:00
parent 76946fb5a3
commit ba58e3d5d2
2 changed files with 24 additions and 0 deletions

View File

@ -1871,6 +1871,11 @@ func (p *Pipeline) getResultsPrepare() (*StatementDescription, error) {
copy(psd.Fields, msg.Fields)
return psd, nil
// NoData is returned instead of RowDescription when there is no expected result. e.g. An INSERT without a RETURNING
// clause.
case *pgproto3.NoData:
return psd, nil
// These should never happen here. But don't take chances that could lead to a deadlock.
case *pgproto3.ErrorResponse:
pgErr := ErrorResponseToPgError(msg)

View File

@ -2102,10 +2102,15 @@ func TestPipelinePrepare(t *testing.T) {
require.NoError(t, err)
defer closeConn(t, pgConn)
result := pgConn.ExecParams(context.Background(), `create temporary table t (id text primary key)`, nil, nil, nil, nil).Read()
require.NoError(t, result.Err)
pipeline := pgConn.StartPipeline(context.Background())
pipeline.SendPrepare("selectInt", "select $1::bigint as a", nil)
pipeline.SendPrepare("selectText", "select $1::text as b", nil)
pipeline.SendPrepare("selectNoParams", "select 42 as c", nil)
pipeline.SendPrepare("insertNoResults", "insert into t (id) values ($1)", nil)
pipeline.SendPrepare("insertNoParamsOrResults", "insert into t (id) values ('foo')", nil)
err = pipeline.Sync()
require.NoError(t, err)
@ -2133,6 +2138,20 @@ func TestPipelinePrepare(t *testing.T) {
require.Equal(t, string(sd.Fields[0].Name), "c")
require.Equal(t, []uint32{}, sd.ParamOIDs)
results, err = pipeline.GetResults()
require.NoError(t, err)
sd, ok = results.(*pgconn.StatementDescription)
require.Truef(t, ok, "expected StatementDescription, got: %#v", results)
require.Len(t, sd.Fields, 0)
require.Equal(t, []uint32{pgtype.TextOID}, sd.ParamOIDs)
results, err = pipeline.GetResults()
require.NoError(t, err)
sd, ok = results.(*pgconn.StatementDescription)
require.Truef(t, ok, "expected StatementDescription, got: %#v", results)
require.Len(t, sd.Fields, 0)
require.Len(t, sd.ParamOIDs, 0)
results, err = pipeline.GetResults()
require.NoError(t, err)
_, ok = results.(*pgconn.PipelineSync)