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) 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 { type PreparedStatementDescription struct {
Name string Name string
SQL string SQL string
ParamOIDs []uint32 ParamOIDs []uint32
Fields []FieldDescription Fields []pgproto3.FieldDescription
} }
// Prepare creates a prepared statement. // 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)) psd.ParamOIDs = make([]uint32, len(msg.ParameterOIDs))
copy(psd.ParamOIDs, msg.ParameterOIDs) copy(psd.ParamOIDs, msg.ParameterOIDs)
case *pgproto3.RowDescription: case *pgproto3.RowDescription:
psd.Fields = make([]FieldDescription, len(msg.Fields)) psd.Fields = make([]pgproto3.FieldDescription, len(msg.Fields))
for i := range msg.Fields { copy(psd.Fields, msg.Fields)
pgproto3FieldDescriptionToPgconnFieldDescription(&msg.Fields[i], &psd.Fields[i])
}
case *pgproto3.ErrorResponse: case *pgproto3.ErrorResponse:
return nil, errorResponseToPgError(msg) return nil, errorResponseToPgError(msg)
} }

View File

@ -8,7 +8,7 @@ import (
) )
type CommandComplete struct { type CommandComplete struct {
CommandTag []byte CommandTag string
} }
func (*CommandComplete) Backend() {} func (*CommandComplete) Backend() {}
@ -19,7 +19,7 @@ func (dst *CommandComplete) Decode(src []byte) error {
return &invalidMessageFormatErr{messageType: "CommandComplete"} return &invalidMessageFormatErr{messageType: "CommandComplete"}
} }
dst.CommandTag = src[:idx] dst.CommandTag = string(src[:idx])
return nil return nil
} }
@ -43,6 +43,6 @@ func (src *CommandComplete) MarshalJSON() ([]byte, error) {
CommandTag string CommandTag string
}{ }{
Type: "CommandComplete", Type: "CommandComplete",
CommandTag: string(src.CommandTag), CommandTag: src.CommandTag,
}) })
} }

View File

@ -14,7 +14,7 @@ const (
) )
type FieldDescription struct { type FieldDescription struct {
Name []byte Name string
TableOID uint32 TableOID uint32
TableAttributeNumber uint16 TableAttributeNumber uint16
DataTypeOID uint32 DataTypeOID uint32
@ -45,7 +45,7 @@ func (dst *RowDescription) Decode(src []byte) error {
if err != nil { if err != nil {
return err 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 // Since buf.Next() doesn't return an error if we hit the end of the buffer
// check Len ahead of time // check Len ahead of time