ExecParams and ExecPrepared handle empty query
An empty query does not return CommandComplete. Instead it returns EmptyQueryResponse.
This commit is contained in:
@@ -1406,6 +1406,8 @@ func (rr *ResultReader) receiveMessage() (msg pgproto3.BackendMessage, err error
|
||||
rr.fieldDescriptions = msg.Fields
|
||||
case *pgproto3.CommandComplete:
|
||||
rr.concludeCommand(CommandTag(msg.CommandTag), nil)
|
||||
case *pgproto3.EmptyQueryResponse:
|
||||
rr.concludeCommand(nil, nil)
|
||||
case *pgproto3.ErrorResponse:
|
||||
rr.concludeCommand(nil, ErrorResponseToPgError(msg))
|
||||
}
|
||||
|
||||
@@ -668,6 +668,24 @@ func TestConnExecParamsPrecanceled(t *testing.T) {
|
||||
ensureConnValid(t, pgConn)
|
||||
}
|
||||
|
||||
func TestConnExecParamsEmptySQL(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_CONN_STRING"))
|
||||
require.NoError(t, err)
|
||||
defer closeConn(t, pgConn)
|
||||
|
||||
result := pgConn.ExecParams(ctx, "", nil, nil, nil, nil).Read()
|
||||
assert.Nil(t, result.CommandTag)
|
||||
assert.Len(t, result.Rows, 0)
|
||||
assert.NoError(t, result.Err)
|
||||
|
||||
ensureConnValid(t, pgConn)
|
||||
}
|
||||
|
||||
func TestConnExecPrepared(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -797,6 +815,27 @@ func TestConnExecPreparedPrecanceled(t *testing.T) {
|
||||
ensureConnValid(t, pgConn)
|
||||
}
|
||||
|
||||
func TestConnExecPreparedEmptySQL(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_CONN_STRING"))
|
||||
require.NoError(t, err)
|
||||
defer closeConn(t, pgConn)
|
||||
|
||||
_, err = pgConn.Prepare(ctx, "ps1", "", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
result := pgConn.ExecPrepared(ctx, "ps1", nil, nil, nil).Read()
|
||||
assert.Nil(t, result.CommandTag)
|
||||
assert.Len(t, result.Rows, 0)
|
||||
assert.NoError(t, result.Err)
|
||||
|
||||
ensureConnValid(t, pgConn)
|
||||
}
|
||||
|
||||
func TestConnExecBatch(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user