2
0

Restore simple protocol support

This commit is contained in:
Jack Christensen
2019-02-02 13:27:18 -06:00
parent bd181764bf
commit 4ed4e0122d
+45 -31
View File
@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/jackc/pgx/internal/sanitize"
"github.com/jackc/pgx/pgconn" "github.com/jackc/pgx/pgconn"
"github.com/jackc/pgx/pgtype" "github.com/jackc/pgx/pgtype"
) )
@@ -56,7 +57,8 @@ type Rows struct {
unlockConn bool unlockConn bool
closed bool closed bool
resultReader *pgconn.ResultReader resultReader *pgconn.ResultReader
multiResultReader *pgconn.MultiResultReader
} }
func (rows *Rows) FieldDescriptions() []FieldDescription { func (rows *Rows) FieldDescriptions() []FieldDescription {
@@ -84,6 +86,13 @@ func (rows *Rows) Close() {
} }
} }
if rows.multiResultReader != nil {
closeErr := rows.multiResultReader.Close()
if rows.err == nil {
rows.err = closeErr
}
}
if rows.err == nil { if rows.err == nil {
if rows.conn.shouldLog(LogLevelInfo) { if rows.conn.shouldLog(LogLevelInfo) {
endTime := time.Now() endTime := time.Now()
@@ -373,16 +382,25 @@ func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions,
// return rows, rows.err // return rows, rows.err
// } // }
// if (options == nil && c.config.PreferSimpleProtocol) || (options != nil && options.SimpleProtocol) { if (options == nil && c.config.PreferSimpleProtocol) || (options != nil && options.SimpleProtocol) {
// c.lastStmtSent = true sql, err = c.sanitizeForSimpleQuery(sql, args...)
// err = c.sanitizeAndSendSimpleQuery(sql, args...) if err != nil {
// if err != nil { rows.fatal(err)
// rows.fatal(err) return rows, err
// return rows, err }
// }
// return rows, nil c.lastStmtSent = true
// } rows.multiResultReader = c.pgConn.Exec(ctx, sql)
if rows.multiResultReader.NextResult() {
rows.resultReader = rows.multiResultReader.ResultReader()
} else {
err = rows.multiResultReader.Close()
rows.fatal(err)
return rows, err
}
return rows, nil
}
// if options != nil && len(options.ParameterOIDs) > 0 { // if options != nil && len(options.ParameterOIDs) > 0 {
@@ -513,30 +531,26 @@ func (c *Conn) buildOneRoundTripQueryEx(buf []byte, sql string, options *QueryEx
return buf, nil return buf, nil
} }
// func (c *Conn) sanitizeAndSendSimpleQuery(sql string, args ...interface{}) (err 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")
// } }
// if c.pgConn.ParameterStatus("client_encoding") != "UTF8" { if c.pgConn.ParameterStatus("client_encoding") != "UTF8" {
// return errors.New("simple protocol queries must be run with client_encoding=UTF8") return "", errors.New("simple protocol queries must be run with client_encoding=UTF8")
// } }
// valueArgs := make([]interface{}, len(args)) var err error
// for i, a := range args { valueArgs := make([]interface{}, len(args))
// valueArgs[i], err = convertSimpleArgument(c.ConnInfo, a) for i, a := range args {
// if err != nil { valueArgs[i], err = convertSimpleArgument(c.ConnInfo, a)
// return err if err != nil {
// } return "", err
// } }
}
// sql, err = sanitize.SanitizeSQL(sql, valueArgs...) return sanitize.SanitizeSQL(sql, valueArgs...)
// if err != nil { }
// return err
// }
// return c.sendSimpleQuery(sql)
// }
func (c *Conn) QueryRowEx(ctx context.Context, sql string, options *QueryExOptions, args ...interface{}) *Row { func (c *Conn) QueryRowEx(ctx context.Context, sql string, options *QueryExOptions, args ...interface{}) *Row {
rows, _ := c.QueryEx(ctx, sql, options, args...) rows, _ := c.QueryEx(ctx, sql, options, args...)