mirror of https://github.com/jackc/pgx.git
Remove unused code
parent
acd15cf589
commit
2f948c5249
37
conn.go
37
conn.go
|
@ -155,10 +155,6 @@ func ConnectConfig(ctx context.Context, connConfig *ConnConfig) (*Conn, error) {
|
||||||
return connect(ctx, connConfig, minimalConnInfo)
|
return connect(ctx, connConfig, minimalConnInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultDialer() *net.Dialer {
|
|
||||||
return &net.Dialer{KeepAlive: 5 * time.Minute}
|
|
||||||
}
|
|
||||||
|
|
||||||
func connect(ctx context.Context, config *ConnConfig, connInfo *pgtype.ConnInfo) (c *Conn, err error) {
|
func connect(ctx context.Context, config *ConnConfig, connInfo *pgtype.ConnInfo) (c *Conn, err error) {
|
||||||
c = new(Conn)
|
c = new(Conn)
|
||||||
|
|
||||||
|
@ -561,17 +557,6 @@ func (c *Conn) CauseOfDeath() error {
|
||||||
return c.causeOfDeath
|
return c.causeOfDeath
|
||||||
}
|
}
|
||||||
|
|
||||||
// fatalWriteError takes the response of a net.Conn.Write and determines if it is fatal
|
|
||||||
func fatalWriteErr(bytesWritten int, err error) bool {
|
|
||||||
// Partial writes break the connection
|
|
||||||
if bytesWritten > 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
netErr, is := err.(net.Error)
|
|
||||||
return !(is && netErr.Timeout())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Processes messages that are not exclusive to one context such as
|
// Processes messages that are not exclusive to one context such as
|
||||||
// authentication or query response. The response to these messages is the same
|
// authentication or query response. The response to these messages is the same
|
||||||
// regardless of when they occur. It also ignores messages that are only
|
// regardless of when they occur. It also ignores messages that are only
|
||||||
|
@ -615,28 +600,6 @@ func (c *Conn) rxErrorResponse(msg *pgproto3.ErrorResponse) *pgconn.PgError {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) rxRowDescription(msg *pgproto3.RowDescription) []FieldDescription {
|
|
||||||
fields := make([]FieldDescription, len(msg.Fields))
|
|
||||||
for i := 0; i < len(fields); i++ {
|
|
||||||
fields[i].Name = string(msg.Fields[i].Name)
|
|
||||||
fields[i].Table = pgtype.OID(msg.Fields[i].TableOID)
|
|
||||||
fields[i].AttributeNumber = msg.Fields[i].TableAttributeNumber
|
|
||||||
fields[i].DataType = pgtype.OID(msg.Fields[i].DataTypeOID)
|
|
||||||
fields[i].DataTypeSize = msg.Fields[i].DataTypeSize
|
|
||||||
fields[i].Modifier = msg.Fields[i].TypeModifier
|
|
||||||
fields[i].FormatCode = msg.Fields[i].Format
|
|
||||||
}
|
|
||||||
return fields
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) rxParameterDescription(msg *pgproto3.ParameterDescription) []pgtype.OID {
|
|
||||||
parameters := make([]pgtype.OID, len(msg.ParameterOIDs))
|
|
||||||
for i := 0; i < len(parameters); i++ {
|
|
||||||
parameters[i] = pgtype.OID(msg.ParameterOIDs[i])
|
|
||||||
}
|
|
||||||
return parameters
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) die(err error) {
|
func (c *Conn) die(err error) {
|
||||||
c.mux.Lock()
|
c.mux.Lock()
|
||||||
defer c.mux.Unlock()
|
defer c.mux.Unlock()
|
||||||
|
|
102
messages.go
102
messages.go
|
@ -78,93 +78,6 @@ func (fd FieldDescription) Type() reflect.Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// appendParse appends a PostgreSQL wire protocol parse message to buf and returns it.
|
|
||||||
func appendParse(buf []byte, name string, query string, parameterOIDs []pgtype.OID) []byte {
|
|
||||||
buf = append(buf, 'P')
|
|
||||||
sp := len(buf)
|
|
||||||
buf = pgio.AppendInt32(buf, -1)
|
|
||||||
buf = append(buf, name...)
|
|
||||||
buf = append(buf, 0)
|
|
||||||
buf = append(buf, query...)
|
|
||||||
buf = append(buf, 0)
|
|
||||||
|
|
||||||
buf = pgio.AppendInt16(buf, int16(len(parameterOIDs)))
|
|
||||||
for _, oid := range parameterOIDs {
|
|
||||||
buf = pgio.AppendUint32(buf, uint32(oid))
|
|
||||||
}
|
|
||||||
pgio.SetInt32(buf[sp:], int32(len(buf[sp:])))
|
|
||||||
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
|
|
||||||
// appendDescribe appends a PostgreSQL wire protocol describe message to buf and returns it.
|
|
||||||
func appendDescribe(buf []byte, objectType byte, name string) []byte {
|
|
||||||
buf = append(buf, 'D')
|
|
||||||
sp := len(buf)
|
|
||||||
buf = pgio.AppendInt32(buf, -1)
|
|
||||||
buf = append(buf, objectType)
|
|
||||||
buf = append(buf, name...)
|
|
||||||
buf = append(buf, 0)
|
|
||||||
pgio.SetInt32(buf[sp:], int32(len(buf[sp:])))
|
|
||||||
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
|
|
||||||
// appendSync appends a PostgreSQL wire protocol sync message to buf and returns it.
|
|
||||||
func appendSync(buf []byte) []byte {
|
|
||||||
buf = append(buf, 'S')
|
|
||||||
buf = pgio.AppendInt32(buf, 4)
|
|
||||||
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
|
|
||||||
// appendBind appends a PostgreSQL wire protocol bind message to buf and returns it.
|
|
||||||
func appendBind(
|
|
||||||
buf []byte,
|
|
||||||
destinationPortal,
|
|
||||||
preparedStatement string,
|
|
||||||
connInfo *pgtype.ConnInfo,
|
|
||||||
parameterOIDs []pgtype.OID,
|
|
||||||
arguments []interface{},
|
|
||||||
resultFormatCodes []int16,
|
|
||||||
) ([]byte, error) {
|
|
||||||
buf = append(buf, 'B')
|
|
||||||
sp := len(buf)
|
|
||||||
buf = pgio.AppendInt32(buf, -1)
|
|
||||||
buf = append(buf, destinationPortal...)
|
|
||||||
buf = append(buf, 0)
|
|
||||||
buf = append(buf, preparedStatement...)
|
|
||||||
buf = append(buf, 0)
|
|
||||||
|
|
||||||
var err error
|
|
||||||
arguments, err = convertDriverValuers(arguments)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = pgio.AppendInt16(buf, int16(len(parameterOIDs)))
|
|
||||||
for i, oid := range parameterOIDs {
|
|
||||||
buf = pgio.AppendInt16(buf, chooseParameterFormatCode(connInfo, oid, arguments[i]))
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = pgio.AppendInt16(buf, int16(len(arguments)))
|
|
||||||
for i, oid := range parameterOIDs {
|
|
||||||
var err error
|
|
||||||
buf, err = encodePreparedStatementArgument(connInfo, buf, oid, arguments[i])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = pgio.AppendInt16(buf, int16(len(resultFormatCodes)))
|
|
||||||
for _, fc := range resultFormatCodes {
|
|
||||||
buf = pgio.AppendInt16(buf, fc)
|
|
||||||
}
|
|
||||||
pgio.SetInt32(buf[sp:], int32(len(buf[sp:])))
|
|
||||||
|
|
||||||
return buf, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertDriverValuers(args []interface{}) ([]interface{}, error) {
|
func convertDriverValuers(args []interface{}) ([]interface{}, error) {
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
switch arg := arg.(type) {
|
switch arg := arg.(type) {
|
||||||
|
@ -181,21 +94,6 @@ func convertDriverValuers(args []interface{}) ([]interface{}, error) {
|
||||||
return args, nil
|
return args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// appendExecute appends a PostgreSQL wire protocol execute message to buf and returns it.
|
|
||||||
func appendExecute(buf []byte, portal string, maxRows uint32) []byte {
|
|
||||||
buf = append(buf, 'E')
|
|
||||||
sp := len(buf)
|
|
||||||
buf = pgio.AppendInt32(buf, -1)
|
|
||||||
|
|
||||||
buf = append(buf, portal...)
|
|
||||||
buf = append(buf, 0)
|
|
||||||
buf = pgio.AppendUint32(buf, maxRows)
|
|
||||||
|
|
||||||
pgio.SetInt32(buf[sp:], int32(len(buf[sp:])))
|
|
||||||
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
|
|
||||||
// appendQuery appends a PostgreSQL wire protocol query message to buf and returns it.
|
// appendQuery appends a PostgreSQL wire protocol query message to buf and returns it.
|
||||||
func appendQuery(buf []byte, query string) []byte {
|
func appendQuery(buf []byte, query string) []byte {
|
||||||
buf = append(buf, 'Q')
|
buf = append(buf, 'Q')
|
||||||
|
|
20
query.go
20
query.go
|
@ -497,26 +497,6 @@ func (c *Conn) Query(ctx context.Context, sql string, optionsAndArgs ...interfac
|
||||||
return rows, rows.err
|
return rows, rows.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) buildOneRoundTripQueryEx(buf []byte, sql string, options *QueryExOptions, arguments []interface{}) ([]byte, error) {
|
|
||||||
if len(arguments) != len(options.ParameterOIDs) {
|
|
||||||
return nil, errors.Errorf("mismatched number of arguments (%d) and options.ParameterOIDs (%d)", len(arguments), len(options.ParameterOIDs))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(options.ParameterOIDs) > 65535 {
|
|
||||||
return nil, errors.Errorf("Number of QueryExOptions ParameterOIDs must be between 0 and 65535, received %d", len(options.ParameterOIDs))
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = appendParse(buf, "", sql, options.ParameterOIDs)
|
|
||||||
buf = appendDescribe(buf, 'S', "")
|
|
||||||
buf, err := appendBind(buf, "", "", c.ConnInfo, options.ParameterOIDs, arguments, options.ResultFormatCodes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buf = appendExecute(buf, "", 0)
|
|
||||||
|
|
||||||
return buf, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) sanitizeForSimpleQuery(sql string, args ...interface{}) (string, error) {
|
func (c *Conn) sanitizeForSimpleQuery(sql string, args ...interface{}) (string, error) {
|
||||||
if c.pgConn.ParameterStatus("standard_conforming_strings") != "on" {
|
if c.pgConn.ParameterStatus("standard_conforming_strings") != "on" {
|
||||||
return "", errors.New("simple protocol queries must be run with standard_conforming_strings=on")
|
return "", errors.New("simple protocol queries must be run with standard_conforming_strings=on")
|
||||||
|
|
Loading…
Reference in New Issue