diff --git a/pgconn/pgconn.go b/pgconn/pgconn.go index e22a0de8..ee8127bf 100644 --- a/pgconn/pgconn.go +++ b/pgconn/pgconn.go @@ -814,33 +814,11 @@ func (pgConn *PgConn) ExecPrepared(ctx context.Context, stmtName string, paramVa return pgConn.bufferLastResult(ctx) } -type FieldDescription struct { - Name string - TableOID uint32 - TableAttributeNumber uint16 - DataTypeOID uint32 - DataTypeSize int16 - TypeModifier int32 - FormatCode int16 -} - -// pgproto3FieldDescriptionToPgconnFieldDescription copies and converts the data from a pgproto3.FieldDescription to a -// FieldDescription. -func pgproto3FieldDescriptionToPgconnFieldDescription(src *pgproto3.FieldDescription, dst *FieldDescription) { - dst.Name = string(src.Name) - dst.TableOID = src.TableOID - dst.TableAttributeNumber = src.TableAttributeNumber - dst.DataTypeOID = src.DataTypeOID - dst.DataTypeSize = src.DataTypeSize - dst.TypeModifier = src.TypeModifier - dst.FormatCode = src.Format -} - type PreparedStatementDescription struct { Name string SQL string ParamOIDs []uint32 - Fields []FieldDescription + Fields []pgproto3.FieldDescription } // Prepare creates a prepared statement. @@ -877,10 +855,8 @@ func (pgConn *PgConn) Prepare(ctx context.Context, name, sql string, paramOIDs [ psd.ParamOIDs = make([]uint32, len(msg.ParameterOIDs)) copy(psd.ParamOIDs, msg.ParameterOIDs) case *pgproto3.RowDescription: - psd.Fields = make([]FieldDescription, len(msg.Fields)) - for i := range msg.Fields { - pgproto3FieldDescriptionToPgconnFieldDescription(&msg.Fields[i], &psd.Fields[i]) - } + psd.Fields = make([]pgproto3.FieldDescription, len(msg.Fields)) + copy(psd.Fields, msg.Fields) case *pgproto3.ErrorResponse: return nil, errorResponseToPgError(msg) } diff --git a/pgproto3/command_complete.go b/pgproto3/command_complete.go index ba5a6a63..85848532 100644 --- a/pgproto3/command_complete.go +++ b/pgproto3/command_complete.go @@ -8,7 +8,7 @@ import ( ) type CommandComplete struct { - CommandTag []byte + CommandTag string } func (*CommandComplete) Backend() {} @@ -19,7 +19,7 @@ func (dst *CommandComplete) Decode(src []byte) error { return &invalidMessageFormatErr{messageType: "CommandComplete"} } - dst.CommandTag = src[:idx] + dst.CommandTag = string(src[:idx]) return nil } @@ -43,6 +43,6 @@ func (src *CommandComplete) MarshalJSON() ([]byte, error) { CommandTag string }{ Type: "CommandComplete", - CommandTag: string(src.CommandTag), + CommandTag: src.CommandTag, }) } diff --git a/pgproto3/row_description.go b/pgproto3/row_description.go index c7f3477f..7deba379 100644 --- a/pgproto3/row_description.go +++ b/pgproto3/row_description.go @@ -14,7 +14,7 @@ const ( ) type FieldDescription struct { - Name []byte + Name string TableOID uint32 TableAttributeNumber uint16 DataTypeOID uint32 @@ -45,7 +45,7 @@ func (dst *RowDescription) Decode(src []byte) error { if err != nil { return err } - fd.Name = bName[:len(bName)-1] + fd.Name = string(bName[:len(bName)-1]) // Since buf.Next() doesn't return an error if we hit the end of the buffer // check Len ahead of time