Back out of some over optimization

pull/483/head
Jack Christensen 2019-01-02 18:16:08 -06:00
parent 8af697bacf
commit 381f0ca040
3 changed files with 8 additions and 32 deletions

View File

@ -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)
}

View File

@ -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,
})
}

View File

@ -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