Remove extra prepare in stdlib
This commit is contained in:
@@ -580,14 +580,19 @@ func (c *Conn) getRows(sql string, args []interface{}) *connRows {
|
||||
return r
|
||||
}
|
||||
|
||||
// QueryResultFormats controls the result format (text=0, binary=1) of a query by result column position.
|
||||
type QueryResultFormats []int16
|
||||
|
||||
// QueryResultFormatsByOID controls the result format (text=0, binary=1) of a query by the result column OID.
|
||||
type QueryResultFormatsByOID map[pgtype.OID]int16
|
||||
|
||||
// Query executes sql with args. If there is an error the returned Rows will be returned in an error state. So it is
|
||||
// allowed to ignore the error returned from Query and handle it in Rows.
|
||||
func (c *Conn) Query(ctx context.Context, sql string, args ...interface{}) (Rows, error) {
|
||||
// rows = c.getRows(sql, args)
|
||||
|
||||
var resultFormats QueryResultFormats
|
||||
var resultFormatsByOID QueryResultFormatsByOID
|
||||
|
||||
optionLoop:
|
||||
for len(args) > 0 {
|
||||
@@ -595,6 +600,9 @@ optionLoop:
|
||||
case QueryResultFormats:
|
||||
resultFormats = arg
|
||||
args = args[1:]
|
||||
case QueryResultFormatsByOID:
|
||||
resultFormatsByOID = arg
|
||||
args = args[1:]
|
||||
default:
|
||||
break optionLoop
|
||||
}
|
||||
@@ -655,6 +663,13 @@ optionLoop:
|
||||
}
|
||||
}
|
||||
|
||||
if resultFormatsByOID != nil {
|
||||
resultFormats = make([]int16, len(ps.FieldDescriptions))
|
||||
for i := range resultFormats {
|
||||
resultFormats[i] = resultFormatsByOID[ps.FieldDescriptions[i].DataType]
|
||||
}
|
||||
}
|
||||
|
||||
if resultFormats == nil {
|
||||
resultFormats = make([]int16, len(ps.FieldDescriptions))
|
||||
for i := range resultFormats {
|
||||
|
||||
Reference in New Issue
Block a user