2
0

Remove extra prepare in stdlib

This commit is contained in:
Jack Christensen
2019-04-27 15:45:30 -05:00
parent 71d8503b81
commit 243f9031b3
2 changed files with 37 additions and 62 deletions
+15
View File
@@ -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 {