Renamed pgtype.ConnInfo to pgtype.Map
This commit is contained in:
+1
-1
@@ -918,7 +918,7 @@ func BenchmarkSelectManyRegisteredEnum(b *testing.B) {
|
|||||||
err = conn.QueryRow(context.Background(), "select oid from pg_type where typname=$1;", "color").Scan(&oid)
|
err = conn.QueryRow(context.Background(), "select oid from pg_type where typname=$1;", "color").Scan(&oid)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
|
||||||
conn.ConnInfo().RegisterType(&pgtype.Type{Name: "color", OID: oid, Codec: &pgtype.EnumCodec{}})
|
conn.TypeMap().RegisterType(&pgtype.Type{Name: "color", OID: oid, Codec: &pgtype.EnumCodec{}})
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
var x, y, z string
|
var x, y, z string
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ type Conn struct {
|
|||||||
doneChan chan struct{}
|
doneChan chan struct{}
|
||||||
closedChan chan error
|
closedChan chan error
|
||||||
|
|
||||||
connInfo *pgtype.ConnInfo
|
typeMap *pgtype.Map
|
||||||
|
|
||||||
wbuf []byte
|
wbuf []byte
|
||||||
eqb extendedQueryBuilder
|
eqb extendedQueryBuilder
|
||||||
@@ -202,7 +202,7 @@ func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) {
|
|||||||
|
|
||||||
c = &Conn{
|
c = &Conn{
|
||||||
config: originalConfig,
|
config: originalConfig,
|
||||||
connInfo: pgtype.NewConnInfo(),
|
typeMap: pgtype.NewMap(),
|
||||||
logLevel: config.LogLevel,
|
logLevel: config.LogLevel,
|
||||||
logger: config.Logger,
|
logger: config.Logger,
|
||||||
}
|
}
|
||||||
@@ -375,8 +375,8 @@ func (c *Conn) PgConn() *pgconn.PgConn { return c.pgConn }
|
|||||||
// StatementCache returns the statement cache used for this connection.
|
// StatementCache returns the statement cache used for this connection.
|
||||||
func (c *Conn) StatementCache() stmtcache.Cache { return c.stmtcache }
|
func (c *Conn) StatementCache() stmtcache.Cache { return c.stmtcache }
|
||||||
|
|
||||||
// ConnInfo returns the connection info used for this connection.
|
// TypeMap returns the connection info used for this connection.
|
||||||
func (c *Conn) ConnInfo() *pgtype.ConnInfo { return c.connInfo }
|
func (c *Conn) TypeMap() *pgtype.Map { return c.typeMap }
|
||||||
|
|
||||||
// Config returns a copy of config that was used to establish this connection.
|
// Config returns a copy of config that was used to establish this connection.
|
||||||
func (c *Conn) Config() *ConnConfig { return c.config.Copy() }
|
func (c *Conn) Config() *ConnConfig { return c.config.Copy() }
|
||||||
@@ -476,14 +476,14 @@ func (c *Conn) execParamsAndPreparedPrefix(sd *pgconn.StatementDescription, argu
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range args {
|
for i := range args {
|
||||||
err = c.eqb.AppendParam(c.connInfo, sd.ParamOIDs[i], args[i])
|
err = c.eqb.AppendParam(c.typeMap, sd.ParamOIDs[i], args[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range sd.Fields {
|
for i := range sd.Fields {
|
||||||
c.eqb.AppendResultFormat(c.ConnInfo().FormatCodeForOID(sd.Fields[i].DataTypeOID))
|
c.eqb.AppendResultFormat(c.TypeMap().FormatCodeForOID(sd.Fields[i].DataTypeOID))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -516,7 +516,7 @@ func (c *Conn) getRows(ctx context.Context, sql string, args []interface{}) *con
|
|||||||
|
|
||||||
r.ctx = ctx
|
r.ctx = ctx
|
||||||
r.logger = c
|
r.logger = c
|
||||||
r.connInfo = c.connInfo
|
r.typeMap = c.typeMap
|
||||||
r.startTime = time.Now()
|
r.startTime = time.Now()
|
||||||
r.sql = sql
|
r.sql = sql
|
||||||
r.args = args
|
r.args = args
|
||||||
@@ -622,7 +622,7 @@ optionLoop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range args {
|
for i := range args {
|
||||||
err = c.eqb.AppendParam(c.connInfo, sd.ParamOIDs[i], args[i])
|
err = c.eqb.AppendParam(c.typeMap, sd.ParamOIDs[i], args[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.fatal(err)
|
rows.fatal(err)
|
||||||
return rows, rows.err
|
return rows, rows.err
|
||||||
@@ -638,7 +638,7 @@ optionLoop:
|
|||||||
|
|
||||||
if resultFormats == nil {
|
if resultFormats == nil {
|
||||||
for i := range sd.Fields {
|
for i := range sd.Fields {
|
||||||
c.eqb.AppendResultFormat(c.ConnInfo().FormatCodeForOID(sd.Fields[i].DataTypeOID))
|
c.eqb.AppendResultFormat(c.TypeMap().FormatCodeForOID(sd.Fields[i].DataTypeOID))
|
||||||
}
|
}
|
||||||
|
|
||||||
resultFormats = c.eqb.resultFormats
|
resultFormats = c.eqb.resultFormats
|
||||||
@@ -781,14 +781,14 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) BatchResults {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range args {
|
for i := range args {
|
||||||
err = c.eqb.AppendParam(c.connInfo, sd.ParamOIDs[i], args[i])
|
err = c.eqb.AppendParam(c.typeMap, sd.ParamOIDs[i], args[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &batchResults{ctx: ctx, conn: c, err: err}
|
return &batchResults{ctx: ctx, conn: c, err: err}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range sd.Fields {
|
for i := range sd.Fields {
|
||||||
c.eqb.AppendResultFormat(c.ConnInfo().FormatCodeForOID(sd.Fields[i].DataTypeOID))
|
c.eqb.AppendResultFormat(c.TypeMap().FormatCodeForOID(sd.Fields[i].DataTypeOID))
|
||||||
}
|
}
|
||||||
|
|
||||||
if sd.Name == "" {
|
if sd.Name == "" {
|
||||||
@@ -823,7 +823,7 @@ func (c *Conn) sanitizeForSimpleQuery(sql string, args ...interface{}) (string,
|
|||||||
var err error
|
var err error
|
||||||
valueArgs := make([]interface{}, len(args))
|
valueArgs := make([]interface{}, len(args))
|
||||||
for i, a := range args {
|
for i, a := range args {
|
||||||
valueArgs[i], err = convertSimpleArgument(c.connInfo, a)
|
valueArgs[i], err = convertSimpleArgument(c.typeMap, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -855,7 +855,7 @@ func (c *Conn) LoadType(ctx context.Context, typeName string) (*pgtype.Type, err
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dt, ok := c.ConnInfo().TypeForOID(elementOID)
|
dt, ok := c.TypeMap().TypeForOID(elementOID)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("array element OID not registered")
|
return nil, errors.New("array element OID not registered")
|
||||||
}
|
}
|
||||||
@@ -904,7 +904,7 @@ order by attnum`,
|
|||||||
[]interface{}{typrelid},
|
[]interface{}{typrelid},
|
||||||
[]interface{}{&fieldName, &fieldOID},
|
[]interface{}{&fieldName, &fieldOID},
|
||||||
func(qfr QueryFuncRow) error {
|
func(qfr QueryFuncRow) error {
|
||||||
dt, ok := c.ConnInfo().TypeForOID(fieldOID)
|
dt, ok := c.TypeMap().TypeForOID(fieldOID)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unknown composite type field OID: %v", fieldOID)
|
return fmt.Errorf("unknown composite type field OID: %v", fieldOID)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -829,7 +829,7 @@ func TestIdentifierSanitize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnInitConnInfo(t *testing.T) {
|
func TestConnInitTypeMap(t *testing.T) {
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
@@ -841,11 +841,11 @@ func TestConnInitConnInfo(t *testing.T) {
|
|||||||
"text": pgtype.TextOID,
|
"text": pgtype.TextOID,
|
||||||
}
|
}
|
||||||
for name, oid := range nameOIDs {
|
for name, oid := range nameOIDs {
|
||||||
dtByName, ok := conn.ConnInfo().TypeForName(name)
|
dtByName, ok := conn.TypeMap().TypeForName(name)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("Expected type named %v to be present", name)
|
t.Fatalf("Expected type named %v to be present", name)
|
||||||
}
|
}
|
||||||
dtByOID, ok := conn.ConnInfo().TypeForOID(oid)
|
dtByOID, ok := conn.TypeMap().TypeForOID(oid)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("Expected type OID %v to be present", oid)
|
t.Fatalf("Expected type OID %v to be present", oid)
|
||||||
}
|
}
|
||||||
@@ -891,7 +891,7 @@ func TestDomainType(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("did not find uint64 OID, %v", err)
|
t.Fatalf("did not find uint64 OID, %v", err)
|
||||||
}
|
}
|
||||||
conn.ConnInfo().RegisterType(&pgtype.Type{Name: "uint64", OID: uint64OID, Codec: pgtype.NumericCodec{}})
|
conn.TypeMap().RegisterType(&pgtype.Type{Name: "uint64", OID: uint64OID, Codec: pgtype.NumericCodec{}})
|
||||||
|
|
||||||
var n uint64
|
var n uint64
|
||||||
err = conn.QueryRow(context.Background(), "select $1::uint64", uint64(24)).Scan(&n)
|
err = conn.QueryRow(context.Background(), "select $1::uint64", uint64(24)).Scan(&n)
|
||||||
|
|||||||
+1
-1
@@ -178,7 +178,7 @@ func (ct *copyFrom) buildCopyBuf(buf []byte, sd *pgconn.StatementDescription) (b
|
|||||||
|
|
||||||
buf = pgio.AppendInt16(buf, int16(len(ct.columnNames)))
|
buf = pgio.AppendInt16(buf, int16(len(ct.columnNames)))
|
||||||
for i, val := range values {
|
for i, val := range values {
|
||||||
buf, err = encodePreparedStatementArgument(ct.conn.connInfo, buf, sd.Fields[i].DataTypeOID, val)
|
buf, err = encodePreparedStatementArgument(ct.conn.typeMap, buf, sd.Fields[i].DataTypeOID, val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, err
|
return false, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -256,7 +256,7 @@ func TestConnCopyFromJSON(t *testing.T) {
|
|||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
for _, typeName := range []string{"json", "jsonb"} {
|
for _, typeName := range []string{"json", "jsonb"} {
|
||||||
if _, ok := conn.ConnInfo().TypeForName(typeName); !ok {
|
if _, ok := conn.TypeMap().TypeForName(typeName); !ok {
|
||||||
return // No JSON/JSONB type -- must be running against old PostgreSQL
|
return // No JSON/JSONB type -- must be running against old PostgreSQL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ type extendedQueryBuilder struct {
|
|||||||
resultFormats []int16
|
resultFormats []int16
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eqb *extendedQueryBuilder) AppendParam(ci *pgtype.ConnInfo, oid uint32, arg interface{}) error {
|
func (eqb *extendedQueryBuilder) AppendParam(m *pgtype.Map, oid uint32, arg interface{}) error {
|
||||||
f := chooseParameterFormatCode(ci, oid, arg)
|
f := chooseParameterFormatCode(m, oid, arg)
|
||||||
eqb.paramFormats = append(eqb.paramFormats, f)
|
eqb.paramFormats = append(eqb.paramFormats, f)
|
||||||
|
|
||||||
v, err := eqb.encodeExtendedParamValue(ci, oid, f, arg)
|
v, err := eqb.encodeExtendedParamValue(m, oid, f, arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ func (eqb *extendedQueryBuilder) Reset() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eqb *extendedQueryBuilder) encodeExtendedParamValue(ci *pgtype.ConnInfo, oid uint32, formatCode int16, arg interface{}) ([]byte, error) {
|
func (eqb *extendedQueryBuilder) encodeExtendedParamValue(m *pgtype.Map, oid uint32, formatCode int16, arg interface{}) ([]byte, error) {
|
||||||
if arg == nil {
|
if arg == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -80,11 +80,11 @@ func (eqb *extendedQueryBuilder) encodeExtendedParamValue(ci *pgtype.ConnInfo, o
|
|||||||
// We have already checked that arg is not pointing to nil,
|
// We have already checked that arg is not pointing to nil,
|
||||||
// so it is safe to dereference here.
|
// so it is safe to dereference here.
|
||||||
arg = refVal.Elem().Interface()
|
arg = refVal.Elem().Interface()
|
||||||
return eqb.encodeExtendedParamValue(ci, oid, formatCode, arg)
|
return eqb.encodeExtendedParamValue(m, oid, formatCode, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := ci.TypeForOID(oid); ok {
|
if _, ok := m.TypeForOID(oid); ok {
|
||||||
buf, err := ci.Encode(oid, formatCode, arg, eqb.paramValueBytes)
|
buf, err := m.Encode(oid, formatCode, arg, eqb.paramValueBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ func (eqb *extendedQueryBuilder) encodeExtendedParamValue(ci *pgtype.ConnInfo, o
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strippedArg, ok := stripNamedType(&refVal); ok {
|
if strippedArg, ok := stripNamedType(&refVal); ok {
|
||||||
return eqb.encodeExtendedParamValue(ci, oid, formatCode, strippedArg)
|
return eqb.encodeExtendedParamValue(m, oid, formatCode, strippedArg)
|
||||||
}
|
}
|
||||||
return nil, SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
return nil, SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ func cardinality(dimensions []ArrayDimension) int {
|
|||||||
return elementCount
|
return elementCount
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dst *ArrayHeader) DecodeBinary(ci *ConnInfo, src []byte) (int, error) {
|
func (dst *ArrayHeader) DecodeBinary(m *Map, src []byte) (int, error) {
|
||||||
if len(src) < 12 {
|
if len(src) < 12 {
|
||||||
return 0, fmt.Errorf("array header too short: %d", len(src))
|
return 0, fmt.Errorf("array header too short: %d", len(src))
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-25
@@ -49,7 +49,7 @@ func (c *ArrayCodec) PreferredFormat() int16 {
|
|||||||
return c.ElementType.Codec.PreferredFormat()
|
return c.ElementType.Codec.PreferredFormat()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ArrayCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (c *ArrayCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
arrayValuer, ok := value.(ArrayGetter)
|
arrayValuer, ok := value.(ArrayGetter)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
@@ -57,16 +57,16 @@ func (c *ArrayCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value in
|
|||||||
|
|
||||||
elementType := arrayValuer.IndexType()
|
elementType := arrayValuer.IndexType()
|
||||||
|
|
||||||
elementEncodePlan := ci.PlanEncode(c.ElementType.OID, format, elementType)
|
elementEncodePlan := m.PlanEncode(c.ElementType.OID, format, elementType)
|
||||||
if elementEncodePlan == nil {
|
if elementEncodePlan == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
return &encodePlanArrayCodecBinary{ac: c, ci: ci, oid: oid}
|
return &encodePlanArrayCodecBinary{ac: c, m: m, oid: oid}
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
return &encodePlanArrayCodecText{ac: c, ci: ci, oid: oid}
|
return &encodePlanArrayCodecText{ac: c, m: m, oid: oid}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -74,7 +74,7 @@ func (c *ArrayCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value in
|
|||||||
|
|
||||||
type encodePlanArrayCodecText struct {
|
type encodePlanArrayCodecText struct {
|
||||||
ac *ArrayCodec
|
ac *ArrayCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
oid uint32
|
oid uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ func (p *encodePlanArrayCodecText) Encode(value interface{}, buf []byte) (newBuf
|
|||||||
elemType := reflect.TypeOf(elem)
|
elemType := reflect.TypeOf(elem)
|
||||||
if lastElemType != elemType {
|
if lastElemType != elemType {
|
||||||
lastElemType = elemType
|
lastElemType = elemType
|
||||||
encodePlan = p.ci.PlanEncode(p.ac.ElementType.OID, TextFormatCode, elem)
|
encodePlan = p.m.PlanEncode(p.ac.ElementType.OID, TextFormatCode, elem)
|
||||||
if encodePlan == nil {
|
if encodePlan == nil {
|
||||||
return nil, fmt.Errorf("unable to encode %v", array.Index(i))
|
return nil, fmt.Errorf("unable to encode %v", array.Index(i))
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ func (p *encodePlanArrayCodecText) Encode(value interface{}, buf []byte) (newBuf
|
|||||||
|
|
||||||
type encodePlanArrayCodecBinary struct {
|
type encodePlanArrayCodecBinary struct {
|
||||||
ac *ArrayCodec
|
ac *ArrayCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
oid uint32
|
oid uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ func (p *encodePlanArrayCodecBinary) Encode(value interface{}, buf []byte) (newB
|
|||||||
elemType := reflect.TypeOf(elem)
|
elemType := reflect.TypeOf(elem)
|
||||||
if lastElemType != elemType {
|
if lastElemType != elemType {
|
||||||
lastElemType = elemType
|
lastElemType = elemType
|
||||||
encodePlan = p.ci.PlanEncode(p.ac.ElementType.OID, BinaryFormatCode, elem)
|
encodePlan = p.m.PlanEncode(p.ac.ElementType.OID, BinaryFormatCode, elem)
|
||||||
if encodePlan == nil {
|
if encodePlan == nil {
|
||||||
return nil, fmt.Errorf("unable to encode %v", array.Index(i))
|
return nil, fmt.Errorf("unable to encode %v", array.Index(i))
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ func (p *encodePlanArrayCodecBinary) Encode(value interface{}, buf []byte) (newB
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ArrayCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (c *ArrayCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
arrayScanner, ok := target.(ArraySetter)
|
arrayScanner, ok := target.(ArraySetter)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
@@ -218,22 +218,22 @@ func (c *ArrayCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target int
|
|||||||
|
|
||||||
elementType := arrayScanner.ScanIndexType()
|
elementType := arrayScanner.ScanIndexType()
|
||||||
|
|
||||||
elementScanPlan := ci.PlanScan(c.ElementType.OID, format, elementType)
|
elementScanPlan := m.PlanScan(c.ElementType.OID, format, elementType)
|
||||||
if _, ok := elementScanPlan.(*scanPlanFail); ok {
|
if _, ok := elementScanPlan.(*scanPlanFail); ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &scanPlanArrayCodec{
|
return &scanPlanArrayCodec{
|
||||||
arrayCodec: c,
|
arrayCodec: c,
|
||||||
ci: ci,
|
m: m,
|
||||||
oid: oid,
|
oid: oid,
|
||||||
formatCode: format,
|
formatCode: format,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ArrayCodec) decodeBinary(ci *ConnInfo, arrayOID uint32, src []byte, array ArraySetter) error {
|
func (c *ArrayCodec) decodeBinary(m *Map, arrayOID uint32, src []byte, array ArraySetter) error {
|
||||||
var arrayHeader ArrayHeader
|
var arrayHeader ArrayHeader
|
||||||
rp, err := arrayHeader.DecodeBinary(ci, src)
|
rp, err := arrayHeader.DecodeBinary(m, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -248,9 +248,9 @@ func (c *ArrayCodec) decodeBinary(ci *ConnInfo, arrayOID uint32, src []byte, arr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
elementScanPlan := c.ElementType.Codec.PlanScan(ci, c.ElementType.OID, BinaryFormatCode, array.ScanIndex(0), false)
|
elementScanPlan := c.ElementType.Codec.PlanScan(m, c.ElementType.OID, BinaryFormatCode, array.ScanIndex(0), false)
|
||||||
if elementScanPlan == nil {
|
if elementScanPlan == nil {
|
||||||
elementScanPlan = ci.PlanScan(c.ElementType.OID, BinaryFormatCode, array.ScanIndex(0))
|
elementScanPlan = m.PlanScan(c.ElementType.OID, BinaryFormatCode, array.ScanIndex(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < elementCount; i++ {
|
for i := 0; i < elementCount; i++ {
|
||||||
@@ -271,7 +271,7 @@ func (c *ArrayCodec) decodeBinary(ci *ConnInfo, arrayOID uint32, src []byte, arr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ArrayCodec) decodeText(ci *ConnInfo, arrayOID uint32, src []byte, array ArraySetter) error {
|
func (c *ArrayCodec) decodeText(m *Map, arrayOID uint32, src []byte, array ArraySetter) error {
|
||||||
uta, err := ParseUntypedTextArray(string(src))
|
uta, err := ParseUntypedTextArray(string(src))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -286,9 +286,9 @@ func (c *ArrayCodec) decodeText(ci *ConnInfo, arrayOID uint32, src []byte, array
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
elementScanPlan := c.ElementType.Codec.PlanScan(ci, c.ElementType.OID, TextFormatCode, array.ScanIndex(0), false)
|
elementScanPlan := c.ElementType.Codec.PlanScan(m, c.ElementType.OID, TextFormatCode, array.ScanIndex(0), false)
|
||||||
if elementScanPlan == nil {
|
if elementScanPlan == nil {
|
||||||
elementScanPlan = ci.PlanScan(c.ElementType.OID, TextFormatCode, array.ScanIndex(0))
|
elementScanPlan = m.PlanScan(c.ElementType.OID, TextFormatCode, array.ScanIndex(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, s := range uta.Elements {
|
for i, s := range uta.Elements {
|
||||||
@@ -309,7 +309,7 @@ func (c *ArrayCodec) decodeText(ci *ConnInfo, arrayOID uint32, src []byte, array
|
|||||||
|
|
||||||
type scanPlanArrayCodec struct {
|
type scanPlanArrayCodec struct {
|
||||||
arrayCodec *ArrayCodec
|
arrayCodec *ArrayCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
oid uint32
|
oid uint32
|
||||||
formatCode int16
|
formatCode int16
|
||||||
elementScanPlan ScanPlan
|
elementScanPlan ScanPlan
|
||||||
@@ -317,7 +317,7 @@ type scanPlanArrayCodec struct {
|
|||||||
|
|
||||||
func (spac *scanPlanArrayCodec) Scan(src []byte, dst interface{}) error {
|
func (spac *scanPlanArrayCodec) Scan(src []byte, dst interface{}) error {
|
||||||
c := spac.arrayCodec
|
c := spac.arrayCodec
|
||||||
ci := spac.ci
|
m := spac.m
|
||||||
oid := spac.oid
|
oid := spac.oid
|
||||||
formatCode := spac.formatCode
|
formatCode := spac.formatCode
|
||||||
|
|
||||||
@@ -329,15 +329,15 @@ func (spac *scanPlanArrayCodec) Scan(src []byte, dst interface{}) error {
|
|||||||
|
|
||||||
switch formatCode {
|
switch formatCode {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
return c.decodeBinary(ci, oid, src, array)
|
return c.decodeBinary(m, oid, src, array)
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
return c.decodeText(ci, oid, src, array)
|
return c.decodeText(m, oid, src, array)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown format code %d", formatCode)
|
return fmt.Errorf("unknown format code %d", formatCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ArrayCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c *ArrayCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -354,13 +354,13 @@ func (c *ArrayCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ArrayCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c *ArrayCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var slice []interface{}
|
var slice []interface{}
|
||||||
err := ci.PlanScan(oid, format, &slice).Scan(src, &slice)
|
err := m.PlanScan(oid, format, &slice).Scan(src, &slice)
|
||||||
return slice, err
|
return slice, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -70,7 +70,7 @@ func (BitsCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BitsCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (BitsCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(BitsValuer); !ok {
|
if _, ok := value.(BitsValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ func (encodePlanBitsCodecText) Encode(value interface{}, buf []byte) (newBuf []b
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BitsCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (BitsCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -144,17 +144,17 @@ func (BitsCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interfa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c BitsCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c BitsCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c BitsCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c BitsCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var box Bits
|
var box Bits
|
||||||
err := codecScan(c, ci, oid, format, src, &box)
|
err := codecScan(c, m, oid, format, src, &box)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -106,7 +106,7 @@ func (BoolCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BoolCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (BoolCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -197,7 +197,7 @@ func (encodePlanBoolCodecTextBool) Encode(value interface{}, buf []byte) (newBuf
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BoolCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (BoolCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -219,17 +219,17 @@ func (BoolCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interfa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c BoolCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c BoolCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return c.DecodeValue(ci, oid, format, src)
|
return c.DecodeValue(m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c BoolCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c BoolCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var b bool
|
var b bool
|
||||||
err := codecScan(c, ci, oid, format, src, &b)
|
err := codecScan(c, m, oid, format, src, &b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -71,7 +71,7 @@ func (BoxCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BoxCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (BoxCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(BoxValuer); !ok {
|
if _, ok := value.(BoxValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ func (encodePlanBoxCodecText) Encode(value interface{}, buf []byte) (newBuf []by
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BoxCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (BoxCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -220,17 +220,17 @@ func (scanPlanTextAnyToBoxScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanBox(Box{P: [2]Vec2{{x1, y1}, {x2, y2}}, Valid: true})
|
return scanner.ScanBox(Box{P: [2]Vec2{{x1, y1}, {x2, y2}}, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c BoxCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c BoxCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c BoxCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c BoxCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var box Box
|
var box Box
|
||||||
err := codecScan(c, ci, oid, format, src, &box)
|
err := codecScan(c, m, oid, format, src, &box)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -72,7 +72,7 @@ func (ByteaCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ByteaCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (ByteaCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -147,7 +147,7 @@ func (encodePlanBytesCodecTextBytesValuer) Encode(value interface{}, buf []byte)
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ByteaCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (ByteaCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -237,17 +237,17 @@ func decodeHexBytea(src []byte) ([]byte, error) {
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ByteaCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c ByteaCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ByteaCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c ByteaCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf []byte
|
var buf []byte
|
||||||
err := codecScan(c, ci, oid, format, src, &buf)
|
err := codecScan(c, m, oid, format, src, &buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -72,7 +72,7 @@ func (CircleCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (CircleCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (CircleCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(CircleValuer); !ok {
|
if _, ok := value.(CircleValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ func (encodePlanCircleCodecText) Encode(value interface{}, buf []byte) (newBuf [
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (CircleCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (CircleCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
@@ -142,17 +142,17 @@ func (CircleCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target inter
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CircleCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c CircleCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CircleCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c CircleCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var circle Circle
|
var circle Circle
|
||||||
err := codecScan(c, ci, oid, format, src, &circle)
|
err := codecScan(c, m, oid, format, src, &circle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-36
@@ -54,16 +54,16 @@ func (c *CompositeCodec) PreferredFormat() int16 {
|
|||||||
return TextFormatCode
|
return TextFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompositeCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (c *CompositeCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(CompositeIndexGetter); !ok {
|
if _, ok := value.(CompositeIndexGetter); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
return &encodePlanCompositeCodecCompositeIndexGetterToBinary{cc: c, ci: ci}
|
return &encodePlanCompositeCodecCompositeIndexGetterToBinary{cc: c, m: m}
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
return &encodePlanCompositeCodecCompositeIndexGetterToText{cc: c, ci: ci}
|
return &encodePlanCompositeCodecCompositeIndexGetterToText{cc: c, m: m}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -71,7 +71,7 @@ func (c *CompositeCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, valu
|
|||||||
|
|
||||||
type encodePlanCompositeCodecCompositeIndexGetterToBinary struct {
|
type encodePlanCompositeCodecCompositeIndexGetterToBinary struct {
|
||||||
cc *CompositeCodec
|
cc *CompositeCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *encodePlanCompositeCodecCompositeIndexGetterToBinary) Encode(value interface{}, buf []byte) (newBuf []byte, err error) {
|
func (plan *encodePlanCompositeCodecCompositeIndexGetterToBinary) Encode(value interface{}, buf []byte) (newBuf []byte, err error) {
|
||||||
@@ -81,7 +81,7 @@ func (plan *encodePlanCompositeCodecCompositeIndexGetterToBinary) Encode(value i
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := NewCompositeBinaryBuilder(plan.ci, buf)
|
builder := NewCompositeBinaryBuilder(plan.m, buf)
|
||||||
for i, field := range plan.cc.Fields {
|
for i, field := range plan.cc.Fields {
|
||||||
builder.AppendValue(field.Type.OID, getter.Index(i))
|
builder.AppendValue(field.Type.OID, getter.Index(i))
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ func (plan *encodePlanCompositeCodecCompositeIndexGetterToBinary) Encode(value i
|
|||||||
|
|
||||||
type encodePlanCompositeCodecCompositeIndexGetterToText struct {
|
type encodePlanCompositeCodecCompositeIndexGetterToText struct {
|
||||||
cc *CompositeCodec
|
cc *CompositeCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *encodePlanCompositeCodecCompositeIndexGetterToText) Encode(value interface{}, buf []byte) (newBuf []byte, err error) {
|
func (plan *encodePlanCompositeCodecCompositeIndexGetterToText) Encode(value interface{}, buf []byte) (newBuf []byte, err error) {
|
||||||
@@ -101,7 +101,7 @@ func (plan *encodePlanCompositeCodecCompositeIndexGetterToText) Encode(value int
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b := NewCompositeTextBuilder(plan.ci, buf)
|
b := NewCompositeTextBuilder(plan.m, buf)
|
||||||
for i, field := range plan.cc.Fields {
|
for i, field := range plan.cc.Fields {
|
||||||
b.AppendValue(field.Type.OID, getter.Index(i))
|
b.AppendValue(field.Type.OID, getter.Index(i))
|
||||||
}
|
}
|
||||||
@@ -109,17 +109,17 @@ func (plan *encodePlanCompositeCodecCompositeIndexGetterToText) Encode(value int
|
|||||||
return b.Finish()
|
return b.Finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompositeCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (c *CompositeCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
case CompositeIndexScanner:
|
case CompositeIndexScanner:
|
||||||
return &scanPlanBinaryCompositeToCompositeIndexScanner{cc: c, ci: ci}
|
return &scanPlanBinaryCompositeToCompositeIndexScanner{cc: c, m: m}
|
||||||
}
|
}
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
case CompositeIndexScanner:
|
case CompositeIndexScanner:
|
||||||
return &scanPlanTextCompositeToCompositeIndexScanner{cc: c, ci: ci}
|
return &scanPlanTextCompositeToCompositeIndexScanner{cc: c, m: m}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ func (c *CompositeCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target
|
|||||||
|
|
||||||
type scanPlanBinaryCompositeToCompositeIndexScanner struct {
|
type scanPlanBinaryCompositeToCompositeIndexScanner struct {
|
||||||
cc *CompositeCodec
|
cc *CompositeCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *scanPlanBinaryCompositeToCompositeIndexScanner) Scan(src []byte, target interface{}) error {
|
func (plan *scanPlanBinaryCompositeToCompositeIndexScanner) Scan(src []byte, target interface{}) error {
|
||||||
@@ -138,12 +138,12 @@ func (plan *scanPlanBinaryCompositeToCompositeIndexScanner) Scan(src []byte, tar
|
|||||||
return targetScanner.ScanNull()
|
return targetScanner.ScanNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner := NewCompositeBinaryScanner(plan.ci, src)
|
scanner := NewCompositeBinaryScanner(plan.m, src)
|
||||||
for i, field := range plan.cc.Fields {
|
for i, field := range plan.cc.Fields {
|
||||||
if scanner.Next() {
|
if scanner.Next() {
|
||||||
fieldTarget := targetScanner.ScanIndex(i)
|
fieldTarget := targetScanner.ScanIndex(i)
|
||||||
if fieldTarget != nil {
|
if fieldTarget != nil {
|
||||||
fieldPlan := plan.ci.PlanScan(field.Type.OID, BinaryFormatCode, fieldTarget)
|
fieldPlan := plan.m.PlanScan(field.Type.OID, BinaryFormatCode, fieldTarget)
|
||||||
if fieldPlan == nil {
|
if fieldPlan == nil {
|
||||||
return fmt.Errorf("unable to encode %v into OID %d in binary format", field, field.Type.OID)
|
return fmt.Errorf("unable to encode %v into OID %d in binary format", field, field.Type.OID)
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,7 @@ func (plan *scanPlanBinaryCompositeToCompositeIndexScanner) Scan(src []byte, tar
|
|||||||
|
|
||||||
type scanPlanTextCompositeToCompositeIndexScanner struct {
|
type scanPlanTextCompositeToCompositeIndexScanner struct {
|
||||||
cc *CompositeCodec
|
cc *CompositeCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *scanPlanTextCompositeToCompositeIndexScanner) Scan(src []byte, target interface{}) error {
|
func (plan *scanPlanTextCompositeToCompositeIndexScanner) Scan(src []byte, target interface{}) error {
|
||||||
@@ -177,12 +177,12 @@ func (plan *scanPlanTextCompositeToCompositeIndexScanner) Scan(src []byte, targe
|
|||||||
return targetScanner.ScanNull()
|
return targetScanner.ScanNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner := NewCompositeTextScanner(plan.ci, src)
|
scanner := NewCompositeTextScanner(plan.m, src)
|
||||||
for i, field := range plan.cc.Fields {
|
for i, field := range plan.cc.Fields {
|
||||||
if scanner.Next() {
|
if scanner.Next() {
|
||||||
fieldTarget := targetScanner.ScanIndex(i)
|
fieldTarget := targetScanner.ScanIndex(i)
|
||||||
if fieldTarget != nil {
|
if fieldTarget != nil {
|
||||||
fieldPlan := plan.ci.PlanScan(field.Type.OID, TextFormatCode, fieldTarget)
|
fieldPlan := plan.m.PlanScan(field.Type.OID, TextFormatCode, fieldTarget)
|
||||||
if fieldPlan == nil {
|
if fieldPlan == nil {
|
||||||
return fmt.Errorf("unable to encode %v into OID %d in text format", field, field.Type.OID)
|
return fmt.Errorf("unable to encode %v into OID %d in text format", field, field.Type.OID)
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ func (plan *scanPlanTextCompositeToCompositeIndexScanner) Scan(src []byte, targe
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompositeCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c *CompositeCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -221,18 +221,18 @@ func (c *CompositeCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompositeCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c *CompositeCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
scanner := NewCompositeTextScanner(ci, src)
|
scanner := NewCompositeTextScanner(m, src)
|
||||||
values := make(map[string]interface{}, len(c.Fields))
|
values := make(map[string]interface{}, len(c.Fields))
|
||||||
for i := 0; scanner.Next() && i < len(c.Fields); i++ {
|
for i := 0; scanner.Next() && i < len(c.Fields); i++ {
|
||||||
var v interface{}
|
var v interface{}
|
||||||
fieldPlan := ci.PlanScan(c.Fields[i].Type.OID, TextFormatCode, &v)
|
fieldPlan := m.PlanScan(c.Fields[i].Type.OID, TextFormatCode, &v)
|
||||||
if fieldPlan == nil {
|
if fieldPlan == nil {
|
||||||
return nil, fmt.Errorf("unable to scan OID %d in text format into %v", c.Fields[i].Type.OID, v)
|
return nil, fmt.Errorf("unable to scan OID %d in text format into %v", c.Fields[i].Type.OID, v)
|
||||||
}
|
}
|
||||||
@@ -251,11 +251,11 @@ func (c *CompositeCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src
|
|||||||
|
|
||||||
return values, nil
|
return values, nil
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
scanner := NewCompositeBinaryScanner(ci, src)
|
scanner := NewCompositeBinaryScanner(m, src)
|
||||||
values := make(map[string]interface{}, len(c.Fields))
|
values := make(map[string]interface{}, len(c.Fields))
|
||||||
for i := 0; scanner.Next() && i < len(c.Fields); i++ {
|
for i := 0; scanner.Next() && i < len(c.Fields); i++ {
|
||||||
var v interface{}
|
var v interface{}
|
||||||
fieldPlan := ci.PlanScan(scanner.OID(), BinaryFormatCode, &v)
|
fieldPlan := m.PlanScan(scanner.OID(), BinaryFormatCode, &v)
|
||||||
if fieldPlan == nil {
|
if fieldPlan == nil {
|
||||||
return nil, fmt.Errorf("unable to scan OID %d in binary format into %v", scanner.OID(), v)
|
return nil, fmt.Errorf("unable to scan OID %d in binary format into %v", scanner.OID(), v)
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ func (c *CompositeCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CompositeBinaryScanner struct {
|
type CompositeBinaryScanner struct {
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
rp int
|
rp int
|
||||||
src []byte
|
src []byte
|
||||||
|
|
||||||
@@ -291,7 +291,7 @@ type CompositeBinaryScanner struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCompositeBinaryScanner a scanner over a binary encoded composite balue.
|
// NewCompositeBinaryScanner a scanner over a binary encoded composite balue.
|
||||||
func NewCompositeBinaryScanner(ci *ConnInfo, src []byte) *CompositeBinaryScanner {
|
func NewCompositeBinaryScanner(m *Map, src []byte) *CompositeBinaryScanner {
|
||||||
rp := 0
|
rp := 0
|
||||||
if len(src[rp:]) < 4 {
|
if len(src[rp:]) < 4 {
|
||||||
return &CompositeBinaryScanner{err: fmt.Errorf("Record incomplete %v", src)}
|
return &CompositeBinaryScanner{err: fmt.Errorf("Record incomplete %v", src)}
|
||||||
@@ -301,7 +301,7 @@ func NewCompositeBinaryScanner(ci *ConnInfo, src []byte) *CompositeBinaryScanner
|
|||||||
rp += 4
|
rp += 4
|
||||||
|
|
||||||
return &CompositeBinaryScanner{
|
return &CompositeBinaryScanner{
|
||||||
ci: ci,
|
m: m,
|
||||||
rp: rp,
|
rp: rp,
|
||||||
src: src,
|
src: src,
|
||||||
fieldCount: fieldCount,
|
fieldCount: fieldCount,
|
||||||
@@ -363,7 +363,7 @@ func (cfs *CompositeBinaryScanner) Err() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CompositeTextScanner struct {
|
type CompositeTextScanner struct {
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
rp int
|
rp int
|
||||||
src []byte
|
src []byte
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ type CompositeTextScanner struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCompositeTextScanner a scanner over a text encoded composite value.
|
// NewCompositeTextScanner a scanner over a text encoded composite value.
|
||||||
func NewCompositeTextScanner(ci *ConnInfo, src []byte) *CompositeTextScanner {
|
func NewCompositeTextScanner(m *Map, src []byte) *CompositeTextScanner {
|
||||||
if len(src) < 2 {
|
if len(src) < 2 {
|
||||||
return &CompositeTextScanner{err: fmt.Errorf("Record incomplete %v", src)}
|
return &CompositeTextScanner{err: fmt.Errorf("Record incomplete %v", src)}
|
||||||
}
|
}
|
||||||
@@ -386,7 +386,7 @@ func NewCompositeTextScanner(ci *ConnInfo, src []byte) *CompositeTextScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &CompositeTextScanner{
|
return &CompositeTextScanner{
|
||||||
ci: ci,
|
m: m,
|
||||||
rp: 1,
|
rp: 1,
|
||||||
src: src,
|
src: src,
|
||||||
}
|
}
|
||||||
@@ -459,17 +459,17 @@ func (cfs *CompositeTextScanner) Err() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CompositeBinaryBuilder struct {
|
type CompositeBinaryBuilder struct {
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
buf []byte
|
buf []byte
|
||||||
startIdx int
|
startIdx int
|
||||||
fieldCount uint32
|
fieldCount uint32
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCompositeBinaryBuilder(ci *ConnInfo, buf []byte) *CompositeBinaryBuilder {
|
func NewCompositeBinaryBuilder(m *Map, buf []byte) *CompositeBinaryBuilder {
|
||||||
startIdx := len(buf)
|
startIdx := len(buf)
|
||||||
buf = append(buf, 0, 0, 0, 0) // allocate room for number of fields
|
buf = append(buf, 0, 0, 0, 0) // allocate room for number of fields
|
||||||
return &CompositeBinaryBuilder{ci: ci, buf: buf, startIdx: startIdx}
|
return &CompositeBinaryBuilder{m: m, buf: buf, startIdx: startIdx}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *CompositeBinaryBuilder) AppendValue(oid uint32, field interface{}) {
|
func (b *CompositeBinaryBuilder) AppendValue(oid uint32, field interface{}) {
|
||||||
@@ -484,7 +484,7 @@ func (b *CompositeBinaryBuilder) AppendValue(oid uint32, field interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
plan := b.ci.PlanEncode(oid, BinaryFormatCode, field)
|
plan := b.m.PlanEncode(oid, BinaryFormatCode, field)
|
||||||
if plan == nil {
|
if plan == nil {
|
||||||
b.err = fmt.Errorf("unable to encode %v into OID %d in binary format", field, oid)
|
b.err = fmt.Errorf("unable to encode %v into OID %d in binary format", field, oid)
|
||||||
return
|
return
|
||||||
@@ -516,7 +516,7 @@ func (b *CompositeBinaryBuilder) Finish() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CompositeTextBuilder struct {
|
type CompositeTextBuilder struct {
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
buf []byte
|
buf []byte
|
||||||
startIdx int
|
startIdx int
|
||||||
fieldCount uint32
|
fieldCount uint32
|
||||||
@@ -524,9 +524,9 @@ type CompositeTextBuilder struct {
|
|||||||
fieldBuf [32]byte
|
fieldBuf [32]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCompositeTextBuilder(ci *ConnInfo, buf []byte) *CompositeTextBuilder {
|
func NewCompositeTextBuilder(m *Map, buf []byte) *CompositeTextBuilder {
|
||||||
buf = append(buf, '(') // allocate room for number of fields
|
buf = append(buf, '(') // allocate room for number of fields
|
||||||
return &CompositeTextBuilder{ci: ci, buf: buf}
|
return &CompositeTextBuilder{m: m, buf: buf}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *CompositeTextBuilder) AppendValue(oid uint32, field interface{}) {
|
func (b *CompositeTextBuilder) AppendValue(oid uint32, field interface{}) {
|
||||||
@@ -539,7 +539,7 @@ func (b *CompositeTextBuilder) AppendValue(oid uint32, field interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
plan := b.ci.PlanEncode(oid, TextFormatCode, field)
|
plan := b.m.PlanEncode(oid, TextFormatCode, field)
|
||||||
if plan == nil {
|
if plan == nil {
|
||||||
b.err = fmt.Errorf("unable to encode %v into OID %d in text format", field, oid)
|
b.err = fmt.Errorf("unable to encode %v into OID %d in text format", field, oid)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ create type ct_test as (
|
|||||||
|
|
||||||
dt, err := conn.LoadType(context.Background(), "ct_test")
|
dt, err := conn.LoadType(context.Background(), "ct_test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
conn.ConnInfo().RegisterType(dt)
|
conn.TypeMap().RegisterType(dt)
|
||||||
|
|
||||||
formats := []struct {
|
formats := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -105,7 +105,7 @@ create type point3d as (
|
|||||||
|
|
||||||
dt, err := conn.LoadType(context.Background(), "point3d")
|
dt, err := conn.LoadType(context.Background(), "point3d")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
conn.ConnInfo().RegisterType(dt)
|
conn.TypeMap().RegisterType(dt)
|
||||||
|
|
||||||
formats := []struct {
|
formats := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -140,7 +140,7 @@ create type point3d as (
|
|||||||
|
|
||||||
dt, err := conn.LoadType(context.Background(), "point3d")
|
dt, err := conn.LoadType(context.Background(), "point3d")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
conn.ConnInfo().RegisterType(dt)
|
conn.TypeMap().RegisterType(dt)
|
||||||
|
|
||||||
formats := []struct {
|
formats := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -179,7 +179,7 @@ create type point3d as (
|
|||||||
|
|
||||||
dt, err := conn.LoadType(context.Background(), "point3d")
|
dt, err := conn.LoadType(context.Background(), "point3d")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
conn.ConnInfo().RegisterType(dt)
|
conn.TypeMap().RegisterType(dt)
|
||||||
|
|
||||||
formats := []struct {
|
formats := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
+6
-6
@@ -126,7 +126,7 @@ func (DateCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DateCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (DateCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(DateValuer); !ok {
|
if _, ok := value.(DateValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -196,7 +196,7 @@ func (encodePlanDateCodecText) Encode(value interface{}, buf []byte) (newBuf []b
|
|||||||
return append(buf, s...), nil
|
return append(buf, s...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DateCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (DateCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -265,17 +265,17 @@ func (scanPlanTextAnyToDateScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c DateCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c DateCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c DateCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c DateCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var date Date
|
var date Date
|
||||||
err := codecScan(c, ci, oid, format, src, &date)
|
err := codecScan(c, m, oid, format, src, &date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func (EnumCodec) PreferredFormat() int16 {
|
|||||||
return TextFormatCode
|
return TextFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (EnumCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (EnumCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case TextFormatCode, BinaryFormatCode:
|
case TextFormatCode, BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -38,7 +38,7 @@ func (EnumCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interf
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *EnumCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (c *EnumCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
switch format {
|
switch format {
|
||||||
case TextFormatCode, BinaryFormatCode:
|
case TextFormatCode, BinaryFormatCode:
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
@@ -56,11 +56,11 @@ func (c *EnumCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target inte
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *EnumCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c *EnumCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return c.DecodeValue(ci, oid, format, src)
|
return c.DecodeValue(m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *EnumCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c *EnumCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ create type enum_test as enum ('foo', 'bar', 'baz');`)
|
|||||||
dt, err := conn.LoadType(context.Background(), "enum_test")
|
dt, err := conn.LoadType(context.Background(), "enum_test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
conn.ConnInfo().RegisterType(dt)
|
conn.TypeMap().RegisterType(dt)
|
||||||
|
|
||||||
var s string
|
var s string
|
||||||
err = conn.QueryRow(context.Background(), `select 'foo'::enum_test`).Scan(&s)
|
err = conn.QueryRow(context.Background(), `select 'foo'::enum_test`).Scan(&s)
|
||||||
@@ -58,7 +58,7 @@ create type enum_test as enum ('foo', 'bar', 'baz');`)
|
|||||||
dt, err := conn.LoadType(context.Background(), "enum_test")
|
dt, err := conn.LoadType(context.Background(), "enum_test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
conn.ConnInfo().RegisterType(dt)
|
conn.TypeMap().RegisterType(dt)
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), `select 'foo'::enum_test`)
|
rows, err := conn.Query(context.Background(), `select 'foo'::enum_test`)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
+6
-6
@@ -75,7 +75,7 @@ func (Float4Codec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Float4Codec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (Float4Codec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -145,7 +145,7 @@ func (encodePlanFloat4CodecBinaryInt64Valuer) Encode(value interface{}, buf []by
|
|||||||
return pgio.AppendUint32(buf, math.Float32bits(f)), nil
|
return pgio.AppendUint32(buf, math.Float32bits(f)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Float4Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (Float4Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -247,26 +247,26 @@ func (scanPlanTextAnyToFloat32) Scan(src []byte, dst interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Float4Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c Float4Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n float64
|
var n float64
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Float4Codec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c Float4Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n float32
|
var n float32
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -83,7 +83,7 @@ func (Float8Codec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Float8Codec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (Float8Codec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -183,7 +183,7 @@ func (encodePlanTextInt64Valuer) Encode(value interface{}, buf []byte) (newBuf [
|
|||||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Float8Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (Float8Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -302,17 +302,17 @@ func (scanPlanTextAnyToFloat64Scanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return s.ScanFloat64(Float8{Float: n, Valid: true})
|
return s.ScanFloat64(Float8{Float: n, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Float8Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c Float8Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return c.DecodeValue(ci, oid, format, src)
|
return c.DecodeValue(m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Float8Codec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c Float8Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n float64
|
var n float64
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -72,7 +72,7 @@ func (HstoreCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (HstoreCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (HstoreCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(HstoreValuer); !ok {
|
if _, ok := value.(HstoreValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ func (encodePlanHstoreCodecText) Encode(value interface{}, buf []byte) (newBuf [
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (HstoreCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (HstoreCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -254,17 +254,17 @@ func (scanPlanTextAnyToHstoreScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanHstore(m)
|
return scanner.ScanHstore(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c HstoreCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c HstoreCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c HstoreCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c HstoreCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var hstore Hstore
|
var hstore Hstore
|
||||||
err := codecScan(c, ci, oid, format, src, &hstore)
|
err := codecScan(c, m, oid, format, src, &hstore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func TestHstoreCodec(t *testing.T) {
|
|||||||
t.Skipf("Skipping: cannot find hstore OID")
|
t.Skipf("Skipping: cannot find hstore OID")
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.ConnInfo().RegisterType(&pgtype.Type{Name: "hstore", OID: hstoreOID, Codec: pgtype.HstoreCodec{}})
|
conn.TypeMap().RegisterType(&pgtype.Type{Name: "hstore", OID: hstoreOID, Codec: pgtype.HstoreCodec{}})
|
||||||
|
|
||||||
formats := []struct {
|
formats := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
+6
-6
@@ -75,7 +75,7 @@ func (InetCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (InetCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (InetCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(InetValuer); !ok {
|
if _, ok := value.(InetValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ func (encodePlanInetCodecText) Encode(value interface{}, buf []byte) (newBuf []b
|
|||||||
return append(buf, inet.IPNet.String()...), nil
|
return append(buf, inet.IPNet.String()...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (InetCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (InetCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -158,17 +158,17 @@ func (InetCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interfa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c InetCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c InetCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c InetCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c InetCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var inet Inet
|
var inet Inet
|
||||||
err := codecScan(c, ci, oid, format, src, &inet)
|
err := codecScan(c, m, oid, format, src, &inet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-18
@@ -127,7 +127,7 @@ func (Int2Codec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Int2Codec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (Int2Codec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -206,7 +206,7 @@ func (encodePlanInt2CodecTextInt64Valuer) Encode(value interface{}, buf []byte)
|
|||||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Int2Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (Int2Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -264,26 +264,26 @@ func (Int2Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interfa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Int2Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c Int2Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n int64
|
var n int64
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Int2Codec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c Int2Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n int16
|
var n int16
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -664,7 +664,7 @@ func (Int4Codec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Int4Codec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (Int4Codec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -743,7 +743,7 @@ func (encodePlanInt4CodecTextInt64Valuer) Encode(value interface{}, buf []byte)
|
|||||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Int4Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (Int4Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -801,26 +801,26 @@ func (Int4Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interfa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Int4Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c Int4Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n int64
|
var n int64
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Int4Codec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c Int4Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n int32
|
var n int32
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1212,7 +1212,7 @@ func (Int8Codec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Int8Codec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (Int8Codec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -1291,7 +1291,7 @@ func (encodePlanInt8CodecTextInt64Valuer) Encode(value interface{}, buf []byte)
|
|||||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Int8Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (Int8Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -1349,26 +1349,26 @@ func (Int8Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interfa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Int8Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c Int8Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n int64
|
var n int64
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Int8Codec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c Int8Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n int64
|
var n int64
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -128,7 +128,7 @@ func (Int<%= pg_byte_size %>Codec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Int<%= pg_byte_size %>Codec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (Int<%= pg_byte_size %>Codec) PlanEncode(m *TypeMap, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -207,7 +207,7 @@ func (encodePlanInt<%= pg_byte_size %>CodecTextInt64Valuer) Encode(value interfa
|
|||||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Int<%= pg_byte_size %>Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (Int<%= pg_byte_size %>Codec) PlanScan(m *TypeMap, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -265,26 +265,26 @@ func (Int<%= pg_byte_size %>Codec) PlanScan(ci *ConnInfo, oid uint32, format int
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Int<%= pg_byte_size %>Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c Int<%= pg_byte_size %>Codec) DecodeDatabaseSQLValue(m *TypeMap, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n int64
|
var n int64
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Int<%= pg_byte_size %>Codec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c Int<%= pg_byte_size %>Codec) DecodeValue(m *TypeMap, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n int<%= pg_bit_size %>
|
var n int<%= pg_bit_size %>
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -80,7 +80,7 @@ func (IntervalCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (IntervalCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (IntervalCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(IntervalValuer); !ok {
|
if _, ok := value.(IntervalValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ func (encodePlanIntervalCodecText) Encode(value interface{}, buf []byte) (newBuf
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (IntervalCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (IntervalCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -274,17 +274,17 @@ func (scanPlanTextAnyToIntervalScanner) Scan(src []byte, dst interface{}) error
|
|||||||
return scanner.ScanInterval(Interval{Months: months, Days: days, Microseconds: microseconds, Valid: true})
|
return scanner.ScanInterval(Interval{Months: months, Days: days, Microseconds: microseconds, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c IntervalCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c IntervalCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c IntervalCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c IntervalCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var interval Interval
|
var interval Interval
|
||||||
err := codecScan(c, ci, oid, format, src, &interval)
|
err := codecScan(c, m, oid, format, src, &interval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,7 @@ func (JSONCodec) PreferredFormat() int16 {
|
|||||||
return TextFormatCode
|
return TextFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (JSONCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (JSONCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
case []byte:
|
case []byte:
|
||||||
return encodePlanJSONCodecEitherFormatByteSlice{}
|
return encodePlanJSONCodecEitherFormatByteSlice{}
|
||||||
@@ -49,7 +49,7 @@ func (encodePlanJSONCodecEitherFormatMarshal) Encode(value interface{}, buf []by
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (JSONCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (JSONCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
case *string:
|
case *string:
|
||||||
return scanPlanAnyToString{}
|
return scanPlanAnyToString{}
|
||||||
@@ -110,7 +110,7 @@ func (scanPlanJSONToJSONUnmarshal) Scan(src []byte, dst interface{}) error {
|
|||||||
return json.Unmarshal(src, dst)
|
return json.Unmarshal(src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c JSONCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c JSONCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ func (c JSONCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16
|
|||||||
return dstBuf, nil
|
return dstBuf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c JSONCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c JSONCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -16,15 +16,15 @@ func (JSONBCodec) PreferredFormat() int16 {
|
|||||||
return TextFormatCode
|
return TextFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (JSONBCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (JSONBCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
plan := JSONCodec{}.PlanEncode(ci, oid, TextFormatCode, value)
|
plan := JSONCodec{}.PlanEncode(m, oid, TextFormatCode, value)
|
||||||
if plan != nil {
|
if plan != nil {
|
||||||
return &encodePlanJSONBCodecBinaryWrapper{textPlan: plan}
|
return &encodePlanJSONBCodecBinaryWrapper{textPlan: plan}
|
||||||
}
|
}
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
return JSONCodec{}.PlanEncode(ci, oid, format, value)
|
return JSONCodec{}.PlanEncode(m, oid, format, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -39,15 +39,15 @@ func (plan *encodePlanJSONBCodecBinaryWrapper) Encode(value interface{}, buf []b
|
|||||||
return plan.textPlan.Encode(value, buf)
|
return plan.textPlan.Encode(value, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (JSONBCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (JSONBCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
plan := JSONCodec{}.PlanScan(ci, oid, TextFormatCode, target, actualTarget)
|
plan := JSONCodec{}.PlanScan(m, oid, TextFormatCode, target, actualTarget)
|
||||||
if plan != nil {
|
if plan != nil {
|
||||||
return &scanPlanJSONBCodecBinaryUnwrapper{textPlan: plan}
|
return &scanPlanJSONBCodecBinaryUnwrapper{textPlan: plan}
|
||||||
}
|
}
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
return JSONCodec{}.PlanScan(ci, oid, format, target, actualTarget)
|
return JSONCodec{}.PlanScan(m, oid, format, target, actualTarget)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -73,7 +73,7 @@ func (plan *scanPlanJSONBCodecBinaryUnwrapper) Scan(src []byte, dst interface{})
|
|||||||
return plan.textPlan.Scan(src[1:], dst)
|
return plan.textPlan.Scan(src[1:], dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c JSONBCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c JSONBCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ func (c JSONBCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c JSONBCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c JSONBCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -75,7 +75,7 @@ func (LineCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (LineCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (LineCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(LineValuer); !ok {
|
if _, ok := value.(LineValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ func (encodePlanLineCodecText) Encode(value interface{}, buf []byte) (newBuf []b
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (LineCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (LineCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -207,17 +207,17 @@ func (scanPlanTextAnyToLineScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanLine(Line{A: a, B: b, C: c, Valid: true})
|
return scanner.ScanLine(Line{A: a, B: b, C: c, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c LineCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c LineCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c LineCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c LineCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var line Line
|
var line Line
|
||||||
err := codecScan(c, ci, oid, format, src, &line)
|
err := codecScan(c, m, oid, format, src, &line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import (
|
|||||||
func TestLineTranscode(t *testing.T) {
|
func TestLineTranscode(t *testing.T) {
|
||||||
conn := testutil.MustConnectPgx(t)
|
conn := testutil.MustConnectPgx(t)
|
||||||
defer conn.Close(context.Background())
|
defer conn.Close(context.Background())
|
||||||
if _, ok := conn.ConnInfo().TypeForName("line"); !ok {
|
if _, ok := conn.TypeMap().TypeForName("line"); !ok {
|
||||||
t.Skip("Skipping due to no line type")
|
t.Skip("Skipping due to no line type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -71,7 +71,7 @@ func (LsegCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (LsegCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (LsegCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(LsegValuer); !ok {
|
if _, ok := value.(LsegValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ func (encodePlanLsegCodecText) Encode(value interface{}, buf []byte) (newBuf []b
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (LsegCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (LsegCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -220,17 +220,17 @@ func (scanPlanTextAnyToLsegScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanLseg(Lseg{P: [2]Vec2{{x1, y1}, {x2, y2}}, Valid: true})
|
return scanner.ScanLseg(Lseg{P: [2]Vec2{{x1, y1}, {x2, y2}}, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c LsegCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c LsegCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c LsegCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c LsegCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var lseg Lseg
|
var lseg Lseg
|
||||||
err := codecScan(c, ci, oid, format, src, &lseg)
|
err := codecScan(c, m, oid, format, src, &lseg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -15,7 +15,7 @@ func (MacaddrCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (MacaddrCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (MacaddrCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -78,7 +78,7 @@ func (encodePlanMacaddrCodecTextHardwareAddr) Encode(value interface{}, buf []by
|
|||||||
return append(buf, addr.String()...), nil
|
return append(buf, addr.String()...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (MacaddrCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (MacaddrCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
@@ -144,17 +144,17 @@ func (scanPlanTextMacaddrToHardwareAddr) Scan(src []byte, dst interface{}) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c MacaddrCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c MacaddrCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c MacaddrCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c MacaddrCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var addr net.HardwareAddr
|
var addr net.HardwareAddr
|
||||||
err := codecScan(c, ci, oid, format, src, &addr)
|
err := codecScan(c, m, oid, format, src, &addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -249,7 +249,7 @@ func (NumericCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (NumericCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (NumericCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -501,7 +501,7 @@ func encodeNumericText(n Numeric, buf []byte) (newBuf []byte, err error) {
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (NumericCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (NumericCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -710,7 +710,7 @@ func (scanPlanTextAnyToNumericScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanNumeric(Numeric{Int: num, Exp: exp, Valid: true})
|
return scanner.ScanNumeric(Numeric{Int: num, Exp: exp, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c NumericCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c NumericCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -720,25 +720,25 @@ func (c NumericCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format in
|
|||||||
}
|
}
|
||||||
|
|
||||||
var n Numeric
|
var n Numeric
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := ci.Encode(oid, TextFormatCode, n, nil)
|
buf, err := m.Encode(oid, TextFormatCode, n, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return string(buf), nil
|
return string(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c NumericCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c NumericCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n Numeric
|
var n Numeric
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -73,7 +73,7 @@ func (PathCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (PathCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (PathCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(PathValuer); !ok {
|
if _, ok := value.(PathValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ func (encodePlanPathCodecText) Encode(value interface{}, buf []byte) (newBuf []b
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (PathCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (PathCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -254,17 +254,17 @@ func (scanPlanTextAnyToPathScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanPath(Path{P: points, Closed: closed, Valid: true})
|
return scanner.ScanPath(Path{P: points, Closed: closed, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c PathCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c PathCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c PathCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c PathCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var path Path
|
var path Path
|
||||||
err := codecScan(c, ci, oid, format, src, &path)
|
err := codecScan(c, m, oid, format, src, &path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+159
-157
@@ -141,18 +141,18 @@ type Codec interface {
|
|||||||
|
|
||||||
// PlanEncode returns an Encode plan for encoding value into PostgreSQL format for oid and format. If no plan can be
|
// PlanEncode returns an Encode plan for encoding value into PostgreSQL format for oid and format. If no plan can be
|
||||||
// found then nil is returned.
|
// found then nil is returned.
|
||||||
PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan
|
PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan
|
||||||
|
|
||||||
// PlanScan returns a ScanPlan for scanning a PostgreSQL value into a destination with the same type as target. If
|
// PlanScan returns a ScanPlan for scanning a PostgreSQL value into a destination with the same type as target. If
|
||||||
// actualTarget is true then the returned ScanPlan may be optimized to directly scan into target. If no plan can be
|
// actualTarget is true then the returned ScanPlan may be optimized to directly scan into target. If no plan can be
|
||||||
// found then nil is returned.
|
// found then nil is returned.
|
||||||
PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan
|
PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan
|
||||||
|
|
||||||
// DecodeDatabaseSQLValue returns src decoded into a value compatible with the sql.Scanner interface.
|
// DecodeDatabaseSQLValue returns src decoded into a value compatible with the sql.Scanner interface.
|
||||||
DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error)
|
DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error)
|
||||||
|
|
||||||
// DecodeValue returns src decoded into its default format.
|
// DecodeValue returns src decoded into its default format.
|
||||||
DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error)
|
DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type nullAssignmentError struct {
|
type nullAssignmentError struct {
|
||||||
@@ -169,7 +169,9 @@ type Type struct {
|
|||||||
OID uint32
|
OID uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnInfo struct {
|
// Map is the mapping between PostgreSQL server types and Go type handling logic. It can encode values for
|
||||||
|
// transmission to a PostgreSQL server and scan received values.
|
||||||
|
type Map struct {
|
||||||
oidToType map[uint32]*Type
|
oidToType map[uint32]*Type
|
||||||
nameToType map[string]*Type
|
nameToType map[string]*Type
|
||||||
reflectTypeToName map[reflect.Type]string
|
reflectTypeToName map[reflect.Type]string
|
||||||
@@ -180,19 +182,19 @@ type ConnInfo struct {
|
|||||||
|
|
||||||
// TryWrapEncodePlanFuncs is a slice of functions that will wrap a value that cannot be encoded by the Codec. Every
|
// TryWrapEncodePlanFuncs is a slice of functions that will wrap a value that cannot be encoded by the Codec. Every
|
||||||
// time a wrapper is found the PlanEncode method will be recursively called with the new value. This allows several layers of wrappers
|
// time a wrapper is found the PlanEncode method will be recursively called with the new value. This allows several layers of wrappers
|
||||||
// to be built up. There are default functions placed in this slice by NewConnInfo(). In most cases these functions
|
// to be built up. There are default functions placed in this slice by NewMap(). In most cases these functions
|
||||||
// should run last. i.e. Additional functions should typically be prepended not appended.
|
// should run last. i.e. Additional functions should typically be prepended not appended.
|
||||||
TryWrapEncodePlanFuncs []TryWrapEncodePlanFunc
|
TryWrapEncodePlanFuncs []TryWrapEncodePlanFunc
|
||||||
|
|
||||||
// TryWrapScanPlanFuncs is a slice of functions that will wrap a target that cannot be scanned into by the Codec. Every
|
// TryWrapScanPlanFuncs is a slice of functions that will wrap a target that cannot be scanned into by the Codec. Every
|
||||||
// time a wrapper is found the PlanScan method will be recursively called with the new target. This allows several layers of wrappers
|
// time a wrapper is found the PlanScan method will be recursively called with the new target. This allows several layers of wrappers
|
||||||
// to be built up. There are default functions placed in this slice by NewConnInfo(). In most cases these functions
|
// to be built up. There are default functions placed in this slice by NewMap(). In most cases these functions
|
||||||
// should run last. i.e. Additional functions should typically be prepended not appended.
|
// should run last. i.e. Additional functions should typically be prepended not appended.
|
||||||
TryWrapScanPlanFuncs []TryWrapScanPlanFunc
|
TryWrapScanPlanFuncs []TryWrapScanPlanFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConnInfo() *ConnInfo {
|
func NewMap() *Map {
|
||||||
ci := &ConnInfo{
|
m := &Map{
|
||||||
oidToType: make(map[uint32]*Type),
|
oidToType: make(map[uint32]*Type),
|
||||||
nameToType: make(map[string]*Type),
|
nameToType: make(map[string]*Type),
|
||||||
reflectTypeToName: make(map[reflect.Type]string),
|
reflectTypeToName: make(map[reflect.Type]string),
|
||||||
@@ -218,121 +220,121 @@ func NewConnInfo() *ConnInfo {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ci.RegisterType(&Type{Name: "aclitem", OID: ACLItemOID, Codec: &TextFormatOnlyCodec{TextCodec{}}})
|
m.RegisterType(&Type{Name: "aclitem", OID: ACLItemOID, Codec: &TextFormatOnlyCodec{TextCodec{}}})
|
||||||
ci.RegisterType(&Type{Name: "bit", OID: BitOID, Codec: BitsCodec{}})
|
m.RegisterType(&Type{Name: "bit", OID: BitOID, Codec: BitsCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "bool", OID: BoolOID, Codec: BoolCodec{}})
|
m.RegisterType(&Type{Name: "bool", OID: BoolOID, Codec: BoolCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "box", OID: BoxOID, Codec: BoxCodec{}})
|
m.RegisterType(&Type{Name: "box", OID: BoxOID, Codec: BoxCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "bpchar", OID: BPCharOID, Codec: TextCodec{}})
|
m.RegisterType(&Type{Name: "bpchar", OID: BPCharOID, Codec: TextCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "bytea", OID: ByteaOID, Codec: ByteaCodec{}})
|
m.RegisterType(&Type{Name: "bytea", OID: ByteaOID, Codec: ByteaCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "char", OID: QCharOID, Codec: QCharCodec{}})
|
m.RegisterType(&Type{Name: "char", OID: QCharOID, Codec: QCharCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "cid", OID: CIDOID, Codec: Uint32Codec{}})
|
m.RegisterType(&Type{Name: "cid", OID: CIDOID, Codec: Uint32Codec{}})
|
||||||
ci.RegisterType(&Type{Name: "cidr", OID: CIDROID, Codec: InetCodec{}})
|
m.RegisterType(&Type{Name: "cidr", OID: CIDROID, Codec: InetCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "circle", OID: CircleOID, Codec: CircleCodec{}})
|
m.RegisterType(&Type{Name: "circle", OID: CircleOID, Codec: CircleCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "date", OID: DateOID, Codec: DateCodec{}})
|
m.RegisterType(&Type{Name: "date", OID: DateOID, Codec: DateCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "float4", OID: Float4OID, Codec: Float4Codec{}})
|
m.RegisterType(&Type{Name: "float4", OID: Float4OID, Codec: Float4Codec{}})
|
||||||
ci.RegisterType(&Type{Name: "float8", OID: Float8OID, Codec: Float8Codec{}})
|
m.RegisterType(&Type{Name: "float8", OID: Float8OID, Codec: Float8Codec{}})
|
||||||
ci.RegisterType(&Type{Name: "inet", OID: InetOID, Codec: InetCodec{}})
|
m.RegisterType(&Type{Name: "inet", OID: InetOID, Codec: InetCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "int2", OID: Int2OID, Codec: Int2Codec{}})
|
m.RegisterType(&Type{Name: "int2", OID: Int2OID, Codec: Int2Codec{}})
|
||||||
ci.RegisterType(&Type{Name: "int4", OID: Int4OID, Codec: Int4Codec{}})
|
m.RegisterType(&Type{Name: "int4", OID: Int4OID, Codec: Int4Codec{}})
|
||||||
ci.RegisterType(&Type{Name: "int8", OID: Int8OID, Codec: Int8Codec{}})
|
m.RegisterType(&Type{Name: "int8", OID: Int8OID, Codec: Int8Codec{}})
|
||||||
ci.RegisterType(&Type{Name: "interval", OID: IntervalOID, Codec: IntervalCodec{}})
|
m.RegisterType(&Type{Name: "interval", OID: IntervalOID, Codec: IntervalCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "json", OID: JSONOID, Codec: JSONCodec{}})
|
m.RegisterType(&Type{Name: "json", OID: JSONOID, Codec: JSONCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "jsonb", OID: JSONBOID, Codec: JSONBCodec{}})
|
m.RegisterType(&Type{Name: "jsonb", OID: JSONBOID, Codec: JSONBCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "line", OID: LineOID, Codec: LineCodec{}})
|
m.RegisterType(&Type{Name: "line", OID: LineOID, Codec: LineCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "lseg", OID: LsegOID, Codec: LsegCodec{}})
|
m.RegisterType(&Type{Name: "lseg", OID: LsegOID, Codec: LsegCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "macaddr", OID: MacaddrOID, Codec: MacaddrCodec{}})
|
m.RegisterType(&Type{Name: "macaddr", OID: MacaddrOID, Codec: MacaddrCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "name", OID: NameOID, Codec: TextCodec{}})
|
m.RegisterType(&Type{Name: "name", OID: NameOID, Codec: TextCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "numeric", OID: NumericOID, Codec: NumericCodec{}})
|
m.RegisterType(&Type{Name: "numeric", OID: NumericOID, Codec: NumericCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "oid", OID: OIDOID, Codec: Uint32Codec{}})
|
m.RegisterType(&Type{Name: "oid", OID: OIDOID, Codec: Uint32Codec{}})
|
||||||
ci.RegisterType(&Type{Name: "path", OID: PathOID, Codec: PathCodec{}})
|
m.RegisterType(&Type{Name: "path", OID: PathOID, Codec: PathCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "point", OID: PointOID, Codec: PointCodec{}})
|
m.RegisterType(&Type{Name: "point", OID: PointOID, Codec: PointCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "polygon", OID: PolygonOID, Codec: PolygonCodec{}})
|
m.RegisterType(&Type{Name: "polygon", OID: PolygonOID, Codec: PolygonCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "record", OID: RecordOID, Codec: RecordCodec{}})
|
m.RegisterType(&Type{Name: "record", OID: RecordOID, Codec: RecordCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "text", OID: TextOID, Codec: TextCodec{}})
|
m.RegisterType(&Type{Name: "text", OID: TextOID, Codec: TextCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "tid", OID: TIDOID, Codec: TIDCodec{}})
|
m.RegisterType(&Type{Name: "tid", OID: TIDOID, Codec: TIDCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "time", OID: TimeOID, Codec: TimeCodec{}})
|
m.RegisterType(&Type{Name: "time", OID: TimeOID, Codec: TimeCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "timestamp", OID: TimestampOID, Codec: TimestampCodec{}})
|
m.RegisterType(&Type{Name: "timestamp", OID: TimestampOID, Codec: TimestampCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "timestamptz", OID: TimestamptzOID, Codec: TimestamptzCodec{}})
|
m.RegisterType(&Type{Name: "timestamptz", OID: TimestamptzOID, Codec: TimestamptzCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "unknown", OID: UnknownOID, Codec: TextCodec{}})
|
m.RegisterType(&Type{Name: "unknown", OID: UnknownOID, Codec: TextCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "uuid", OID: UUIDOID, Codec: UUIDCodec{}})
|
m.RegisterType(&Type{Name: "uuid", OID: UUIDOID, Codec: UUIDCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "varbit", OID: VarbitOID, Codec: BitsCodec{}})
|
m.RegisterType(&Type{Name: "varbit", OID: VarbitOID, Codec: BitsCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "varchar", OID: VarcharOID, Codec: TextCodec{}})
|
m.RegisterType(&Type{Name: "varchar", OID: VarcharOID, Codec: TextCodec{}})
|
||||||
ci.RegisterType(&Type{Name: "xid", OID: XIDOID, Codec: Uint32Codec{}})
|
m.RegisterType(&Type{Name: "xid", OID: XIDOID, Codec: Uint32Codec{}})
|
||||||
|
|
||||||
ci.RegisterType(&Type{Name: "daterange", OID: DaterangeOID, Codec: &RangeCodec{ElementType: ci.oidToType[DateOID]}})
|
m.RegisterType(&Type{Name: "daterange", OID: DaterangeOID, Codec: &RangeCodec{ElementType: m.oidToType[DateOID]}})
|
||||||
ci.RegisterType(&Type{Name: "int4range", OID: Int4rangeOID, Codec: &RangeCodec{ElementType: ci.oidToType[Int4OID]}})
|
m.RegisterType(&Type{Name: "int4range", OID: Int4rangeOID, Codec: &RangeCodec{ElementType: m.oidToType[Int4OID]}})
|
||||||
ci.RegisterType(&Type{Name: "int8range", OID: Int8rangeOID, Codec: &RangeCodec{ElementType: ci.oidToType[Int8OID]}})
|
m.RegisterType(&Type{Name: "int8range", OID: Int8rangeOID, Codec: &RangeCodec{ElementType: m.oidToType[Int8OID]}})
|
||||||
ci.RegisterType(&Type{Name: "numrange", OID: NumrangeOID, Codec: &RangeCodec{ElementType: ci.oidToType[NumericOID]}})
|
m.RegisterType(&Type{Name: "numrange", OID: NumrangeOID, Codec: &RangeCodec{ElementType: m.oidToType[NumericOID]}})
|
||||||
ci.RegisterType(&Type{Name: "tsrange", OID: TsrangeOID, Codec: &RangeCodec{ElementType: ci.oidToType[TimestampOID]}})
|
m.RegisterType(&Type{Name: "tsrange", OID: TsrangeOID, Codec: &RangeCodec{ElementType: m.oidToType[TimestampOID]}})
|
||||||
ci.RegisterType(&Type{Name: "tstzrange", OID: TstzrangeOID, Codec: &RangeCodec{ElementType: ci.oidToType[TimestamptzOID]}})
|
m.RegisterType(&Type{Name: "tstzrange", OID: TstzrangeOID, Codec: &RangeCodec{ElementType: m.oidToType[TimestamptzOID]}})
|
||||||
|
|
||||||
ci.RegisterType(&Type{Name: "_aclitem", OID: ACLItemArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[ACLItemOID]}})
|
m.RegisterType(&Type{Name: "_aclitem", OID: ACLItemArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[ACLItemOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_bit", OID: BitArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[BitOID]}})
|
m.RegisterType(&Type{Name: "_bit", OID: BitArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[BitOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_bool", OID: BoolArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[BoolOID]}})
|
m.RegisterType(&Type{Name: "_bool", OID: BoolArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[BoolOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_box", OID: BoxArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[BoxOID]}})
|
m.RegisterType(&Type{Name: "_box", OID: BoxArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[BoxOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_bpchar", OID: BPCharArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[BPCharOID]}})
|
m.RegisterType(&Type{Name: "_bpchar", OID: BPCharArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[BPCharOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_bytea", OID: ByteaArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[ByteaOID]}})
|
m.RegisterType(&Type{Name: "_bytea", OID: ByteaArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[ByteaOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_char", OID: QCharArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[QCharOID]}})
|
m.RegisterType(&Type{Name: "_char", OID: QCharArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[QCharOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_cid", OID: CIDArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[CIDOID]}})
|
m.RegisterType(&Type{Name: "_cid", OID: CIDArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[CIDOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_cidr", OID: CIDRArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[CIDROID]}})
|
m.RegisterType(&Type{Name: "_cidr", OID: CIDRArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[CIDROID]}})
|
||||||
ci.RegisterType(&Type{Name: "_circle", OID: CircleArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[CircleOID]}})
|
m.RegisterType(&Type{Name: "_circle", OID: CircleArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[CircleOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_date", OID: DateArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[DateOID]}})
|
m.RegisterType(&Type{Name: "_date", OID: DateArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[DateOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_daterange", OID: DaterangeArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[DaterangeOID]}})
|
m.RegisterType(&Type{Name: "_daterange", OID: DaterangeArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[DaterangeOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_float4", OID: Float4ArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[Float4OID]}})
|
m.RegisterType(&Type{Name: "_float4", OID: Float4ArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[Float4OID]}})
|
||||||
ci.RegisterType(&Type{Name: "_float8", OID: Float8ArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[Float8OID]}})
|
m.RegisterType(&Type{Name: "_float8", OID: Float8ArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[Float8OID]}})
|
||||||
ci.RegisterType(&Type{Name: "_inet", OID: InetArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[InetOID]}})
|
m.RegisterType(&Type{Name: "_inet", OID: InetArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[InetOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_int2", OID: Int2ArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[Int2OID]}})
|
m.RegisterType(&Type{Name: "_int2", OID: Int2ArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[Int2OID]}})
|
||||||
ci.RegisterType(&Type{Name: "_int4", OID: Int4ArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[Int4OID]}})
|
m.RegisterType(&Type{Name: "_int4", OID: Int4ArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[Int4OID]}})
|
||||||
ci.RegisterType(&Type{Name: "_int4range", OID: Int4rangeArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[Int4rangeOID]}})
|
m.RegisterType(&Type{Name: "_int4range", OID: Int4rangeArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[Int4rangeOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_int8", OID: Int8ArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[Int8OID]}})
|
m.RegisterType(&Type{Name: "_int8", OID: Int8ArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[Int8OID]}})
|
||||||
ci.RegisterType(&Type{Name: "_int8range", OID: Int8rangeArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[Int8rangeOID]}})
|
m.RegisterType(&Type{Name: "_int8range", OID: Int8rangeArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[Int8rangeOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_interval", OID: IntervalArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[IntervalOID]}})
|
m.RegisterType(&Type{Name: "_interval", OID: IntervalArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[IntervalOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_json", OID: JSONArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[JSONOID]}})
|
m.RegisterType(&Type{Name: "_json", OID: JSONArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[JSONOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_jsonb", OID: JSONBArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[JSONBOID]}})
|
m.RegisterType(&Type{Name: "_jsonb", OID: JSONBArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[JSONBOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_line", OID: LineArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[LineOID]}})
|
m.RegisterType(&Type{Name: "_line", OID: LineArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[LineOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_lseg", OID: LsegArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[LsegOID]}})
|
m.RegisterType(&Type{Name: "_lseg", OID: LsegArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[LsegOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_macaddr", OID: MacaddrArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[MacaddrOID]}})
|
m.RegisterType(&Type{Name: "_macaddr", OID: MacaddrArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[MacaddrOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_name", OID: NameArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[NameOID]}})
|
m.RegisterType(&Type{Name: "_name", OID: NameArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[NameOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_numeric", OID: NumericArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[NumericOID]}})
|
m.RegisterType(&Type{Name: "_numeric", OID: NumericArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[NumericOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_numrange", OID: NumrangeArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[NumrangeOID]}})
|
m.RegisterType(&Type{Name: "_numrange", OID: NumrangeArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[NumrangeOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_oid", OID: OIDArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[OIDOID]}})
|
m.RegisterType(&Type{Name: "_oid", OID: OIDArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[OIDOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_path", OID: PathArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[PathOID]}})
|
m.RegisterType(&Type{Name: "_path", OID: PathArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[PathOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_point", OID: PointArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[PointOID]}})
|
m.RegisterType(&Type{Name: "_point", OID: PointArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[PointOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_polygon", OID: PolygonArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[PolygonOID]}})
|
m.RegisterType(&Type{Name: "_polygon", OID: PolygonArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[PolygonOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_record", OID: RecordArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[RecordOID]}})
|
m.RegisterType(&Type{Name: "_record", OID: RecordArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[RecordOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_text", OID: TextArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[TextOID]}})
|
m.RegisterType(&Type{Name: "_text", OID: TextArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[TextOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_tid", OID: TIDArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[TIDOID]}})
|
m.RegisterType(&Type{Name: "_tid", OID: TIDArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[TIDOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_time", OID: TimeArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[TimeOID]}})
|
m.RegisterType(&Type{Name: "_time", OID: TimeArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[TimeOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_timestamp", OID: TimestampArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[TimestampOID]}})
|
m.RegisterType(&Type{Name: "_timestamp", OID: TimestampArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[TimestampOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_timestamptz", OID: TimestamptzArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[TimestamptzOID]}})
|
m.RegisterType(&Type{Name: "_timestamptz", OID: TimestamptzArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[TimestamptzOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_tsrange", OID: TsrangeArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[TsrangeOID]}})
|
m.RegisterType(&Type{Name: "_tsrange", OID: TsrangeArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[TsrangeOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_tstzrange", OID: TstzrangeArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[TstzrangeOID]}})
|
m.RegisterType(&Type{Name: "_tstzrange", OID: TstzrangeArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[TstzrangeOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_uuid", OID: UUIDArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[UUIDOID]}})
|
m.RegisterType(&Type{Name: "_uuid", OID: UUIDArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[UUIDOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_varbit", OID: VarbitArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[VarbitOID]}})
|
m.RegisterType(&Type{Name: "_varbit", OID: VarbitArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[VarbitOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_varchar", OID: VarcharArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[VarcharOID]}})
|
m.RegisterType(&Type{Name: "_varchar", OID: VarcharArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[VarcharOID]}})
|
||||||
ci.RegisterType(&Type{Name: "_xid", OID: XIDArrayOID, Codec: &ArrayCodec{ElementType: ci.oidToType[XIDOID]}})
|
m.RegisterType(&Type{Name: "_xid", OID: XIDArrayOID, Codec: &ArrayCodec{ElementType: m.oidToType[XIDOID]}})
|
||||||
|
|
||||||
registerDefaultPgTypeVariants := func(name, arrayName string, value interface{}) {
|
registerDefaultPgTypeVariants := func(name, arrayName string, value interface{}) {
|
||||||
// T
|
// T
|
||||||
ci.RegisterDefaultPgType(value, name)
|
m.RegisterDefaultPgType(value, name)
|
||||||
|
|
||||||
// *T
|
// *T
|
||||||
valueType := reflect.TypeOf(value)
|
valueType := reflect.TypeOf(value)
|
||||||
ci.RegisterDefaultPgType(reflect.New(valueType).Interface(), name)
|
m.RegisterDefaultPgType(reflect.New(valueType).Interface(), name)
|
||||||
|
|
||||||
// []T
|
// []T
|
||||||
sliceType := reflect.SliceOf(valueType)
|
sliceType := reflect.SliceOf(valueType)
|
||||||
ci.RegisterDefaultPgType(reflect.MakeSlice(sliceType, 0, 0).Interface(), arrayName)
|
m.RegisterDefaultPgType(reflect.MakeSlice(sliceType, 0, 0).Interface(), arrayName)
|
||||||
|
|
||||||
// *[]T
|
// *[]T
|
||||||
ci.RegisterDefaultPgType(reflect.New(sliceType).Interface(), arrayName)
|
m.RegisterDefaultPgType(reflect.New(sliceType).Interface(), arrayName)
|
||||||
|
|
||||||
// []*T
|
// []*T
|
||||||
sliceOfPointerType := reflect.SliceOf(reflect.TypeOf(reflect.New(valueType).Interface()))
|
sliceOfPointerType := reflect.SliceOf(reflect.TypeOf(reflect.New(valueType).Interface()))
|
||||||
ci.RegisterDefaultPgType(reflect.MakeSlice(sliceOfPointerType, 0, 0).Interface(), arrayName)
|
m.RegisterDefaultPgType(reflect.MakeSlice(sliceOfPointerType, 0, 0).Interface(), arrayName)
|
||||||
|
|
||||||
// *[]*T
|
// *[]*T
|
||||||
ci.RegisterDefaultPgType(reflect.New(sliceOfPointerType).Interface(), arrayName)
|
m.RegisterDefaultPgType(reflect.New(sliceOfPointerType).Interface(), arrayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Integer types that directly map to a PostgreSQL type
|
// Integer types that directly map to a PostgreSQL type
|
||||||
@@ -358,57 +360,57 @@ func NewConnInfo() *ConnInfo {
|
|||||||
registerDefaultPgTypeVariants("inet", "_inet", net.IP{})
|
registerDefaultPgTypeVariants("inet", "_inet", net.IP{})
|
||||||
registerDefaultPgTypeVariants("cidr", "_cidr", net.IPNet{})
|
registerDefaultPgTypeVariants("cidr", "_cidr", net.IPNet{})
|
||||||
|
|
||||||
return ci
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ci *ConnInfo) RegisterType(t *Type) {
|
func (m *Map) RegisterType(t *Type) {
|
||||||
ci.oidToType[t.OID] = t
|
m.oidToType[t.OID] = t
|
||||||
ci.nameToType[t.Name] = t
|
m.nameToType[t.Name] = t
|
||||||
ci.oidToFormatCode[t.OID] = t.Codec.PreferredFormat()
|
m.oidToFormatCode[t.OID] = t.Codec.PreferredFormat()
|
||||||
ci.reflectTypeToType = nil // Invalidated by type registration
|
m.reflectTypeToType = nil // Invalidated by type registration
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterDefaultPgType registers a mapping of a Go type to a PostgreSQL type name. Typically the data type to be
|
// RegisterDefaultPgType registers a mapping of a Go type to a PostgreSQL type name. Typically the data type to be
|
||||||
// encoded or decoded is determined by the PostgreSQL OID. But if the OID of a value to be encoded or decoded is
|
// encoded or decoded is determined by the PostgreSQL OID. But if the OID of a value to be encoded or decoded is
|
||||||
// unknown, this additional mapping will be used by TypeForValue to determine a suitable data type.
|
// unknown, this additional mapping will be used by TypeForValue to determine a suitable data type.
|
||||||
func (ci *ConnInfo) RegisterDefaultPgType(value interface{}, name string) {
|
func (m *Map) RegisterDefaultPgType(value interface{}, name string) {
|
||||||
ci.reflectTypeToName[reflect.TypeOf(value)] = name
|
m.reflectTypeToName[reflect.TypeOf(value)] = name
|
||||||
ci.reflectTypeToType = nil // Invalidated by registering a default type
|
m.reflectTypeToType = nil // Invalidated by registering a default type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ci *ConnInfo) TypeForOID(oid uint32) (*Type, bool) {
|
func (m *Map) TypeForOID(oid uint32) (*Type, bool) {
|
||||||
dt, ok := ci.oidToType[oid]
|
dt, ok := m.oidToType[oid]
|
||||||
return dt, ok
|
return dt, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ci *ConnInfo) TypeForName(name string) (*Type, bool) {
|
func (m *Map) TypeForName(name string) (*Type, bool) {
|
||||||
dt, ok := ci.nameToType[name]
|
dt, ok := m.nameToType[name]
|
||||||
return dt, ok
|
return dt, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ci *ConnInfo) buildReflectTypeToType() {
|
func (m *Map) buildReflectTypeToType() {
|
||||||
ci.reflectTypeToType = make(map[reflect.Type]*Type)
|
m.reflectTypeToType = make(map[reflect.Type]*Type)
|
||||||
|
|
||||||
for reflectType, name := range ci.reflectTypeToName {
|
for reflectType, name := range m.reflectTypeToName {
|
||||||
if dt, ok := ci.nameToType[name]; ok {
|
if dt, ok := m.nameToType[name]; ok {
|
||||||
ci.reflectTypeToType[reflectType] = dt
|
m.reflectTypeToType[reflectType] = dt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeForValue finds a data type suitable for v. Use RegisterType to register types that can encode and decode
|
// TypeForValue finds a data type suitable for v. Use RegisterType to register types that can encode and decode
|
||||||
// themselves. Use RegisterDefaultPgType to register that can be handled by a registered data type.
|
// themselves. Use RegisterDefaultPgType to register that can be handled by a registered data type.
|
||||||
func (ci *ConnInfo) TypeForValue(v interface{}) (*Type, bool) {
|
func (m *Map) TypeForValue(v interface{}) (*Type, bool) {
|
||||||
if ci.reflectTypeToType == nil {
|
if m.reflectTypeToType == nil {
|
||||||
ci.buildReflectTypeToType()
|
m.buildReflectTypeToType()
|
||||||
}
|
}
|
||||||
|
|
||||||
dt, ok := ci.reflectTypeToType[reflect.TypeOf(v)]
|
dt, ok := m.reflectTypeToType[reflect.TypeOf(v)]
|
||||||
return dt, ok
|
return dt, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ci *ConnInfo) FormatCodeForOID(oid uint32) int16 {
|
func (m *Map) FormatCodeForOID(oid uint32) int16 {
|
||||||
fc, ok := ci.oidToFormatCode[oid]
|
fc, ok := m.oidToFormatCode[oid]
|
||||||
if ok {
|
if ok {
|
||||||
return fc
|
return fc
|
||||||
}
|
}
|
||||||
@@ -431,13 +433,13 @@ type ScanPlan interface {
|
|||||||
|
|
||||||
type scanPlanCodecSQLScanner struct {
|
type scanPlanCodecSQLScanner struct {
|
||||||
c Codec
|
c Codec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
oid uint32
|
oid uint32
|
||||||
formatCode int16
|
formatCode int16
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *scanPlanCodecSQLScanner) Scan(src []byte, dst interface{}) error {
|
func (plan *scanPlanCodecSQLScanner) Scan(src []byte, dst interface{}) error {
|
||||||
value, err := plan.c.DecodeDatabaseSQLValue(plan.ci, plan.oid, plan.formatCode, src)
|
value, err := plan.c.DecodeDatabaseSQLValue(plan.m, plan.oid, plan.formatCode, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -876,13 +878,13 @@ func (plan *wrapByteSliceScanPlan) Scan(src []byte, dst interface{}) error {
|
|||||||
|
|
||||||
type pointerEmptyInterfaceScanPlan struct {
|
type pointerEmptyInterfaceScanPlan struct {
|
||||||
codec Codec
|
codec Codec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
oid uint32
|
oid uint32
|
||||||
formatCode int16
|
formatCode int16
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *pointerEmptyInterfaceScanPlan) Scan(src []byte, dst interface{}) error {
|
func (plan *pointerEmptyInterfaceScanPlan) Scan(src []byte, dst interface{}) error {
|
||||||
value, err := plan.codec.DecodeValue(plan.ci, plan.oid, plan.formatCode, src)
|
value, err := plan.codec.DecodeValue(plan.m, plan.oid, plan.formatCode, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -991,7 +993,7 @@ func (plan *wrapPtrMultiDimSliceScanPlan) Scan(src []byte, target interface{}) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PlanScan prepares a plan to scan a value into target.
|
// PlanScan prepares a plan to scan a value into target.
|
||||||
func (ci *ConnInfo) PlanScan(oid uint32, formatCode int16, target interface{}) ScanPlan {
|
func (m *Map) PlanScan(oid uint32, formatCode int16, target interface{}) ScanPlan {
|
||||||
if _, ok := target.(*UndecodedBytes); ok {
|
if _, ok := target.(*UndecodedBytes); ok {
|
||||||
return scanPlanAnyToUndecodedBytes{}
|
return scanPlanAnyToUndecodedBytes{}
|
||||||
}
|
}
|
||||||
@@ -1020,22 +1022,22 @@ func (ci *ConnInfo) PlanScan(oid uint32, formatCode int16, target interface{}) S
|
|||||||
|
|
||||||
var dt *Type
|
var dt *Type
|
||||||
|
|
||||||
if dataType, ok := ci.TypeForOID(oid); ok {
|
if dataType, ok := m.TypeForOID(oid); ok {
|
||||||
dt = dataType
|
dt = dataType
|
||||||
} else if dataType, ok := ci.TypeForValue(target); ok {
|
} else if dataType, ok := m.TypeForValue(target); ok {
|
||||||
dt = dataType
|
dt = dataType
|
||||||
oid = dt.OID // Preserve assumed OID in case we are recursively called below.
|
oid = dt.OID // Preserve assumed OID in case we are recursively called below.
|
||||||
}
|
}
|
||||||
|
|
||||||
if dt != nil {
|
if dt != nil {
|
||||||
if plan := dt.Codec.PlanScan(ci, oid, formatCode, target, false); plan != nil {
|
if plan := dt.Codec.PlanScan(m, oid, formatCode, target, false); plan != nil {
|
||||||
return plan
|
return plan
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range ci.TryWrapScanPlanFuncs {
|
for _, f := range m.TryWrapScanPlanFuncs {
|
||||||
if wrapperPlan, nextDst, ok := f(target); ok {
|
if wrapperPlan, nextDst, ok := f(target); ok {
|
||||||
if nextPlan := ci.PlanScan(oid, formatCode, nextDst); nextPlan != nil {
|
if nextPlan := m.PlanScan(oid, formatCode, nextDst); nextPlan != nil {
|
||||||
if _, failed := nextPlan.(*scanPlanFail); !failed {
|
if _, failed := nextPlan.(*scanPlanFail); !failed {
|
||||||
wrapperPlan.SetNext(nextPlan)
|
wrapperPlan.SetNext(nextPlan)
|
||||||
return wrapperPlan
|
return wrapperPlan
|
||||||
@@ -1046,11 +1048,11 @@ func (ci *ConnInfo) PlanScan(oid uint32, formatCode int16, target interface{}) S
|
|||||||
|
|
||||||
if dt != nil {
|
if dt != nil {
|
||||||
if _, ok := target.(*interface{}); ok {
|
if _, ok := target.(*interface{}); ok {
|
||||||
return &pointerEmptyInterfaceScanPlan{codec: dt.Codec, ci: ci, oid: oid, formatCode: formatCode}
|
return &pointerEmptyInterfaceScanPlan{codec: dt.Codec, m: m, oid: oid, formatCode: formatCode}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := target.(sql.Scanner); ok {
|
if _, ok := target.(sql.Scanner); ok {
|
||||||
return &scanPlanCodecSQLScanner{c: dt.Codec, ci: ci, oid: oid, formatCode: formatCode}
|
return &scanPlanCodecSQLScanner{c: dt.Codec, m: m, oid: oid, formatCode: formatCode}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1061,12 +1063,12 @@ func (ci *ConnInfo) PlanScan(oid uint32, formatCode int16, target interface{}) S
|
|||||||
return &scanPlanFail{oid: oid, formatCode: formatCode}
|
return &scanPlanFail{oid: oid, formatCode: formatCode}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ci *ConnInfo) Scan(oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
func (m *Map) Scan(oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||||
if dst == nil {
|
if dst == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
plan := ci.PlanScan(oid, formatCode, dst)
|
plan := m.PlanScan(oid, formatCode, dst)
|
||||||
return plan.Scan(src, dst)
|
return plan.Scan(src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1091,15 +1093,15 @@ func scanUnknownType(oid uint32, formatCode int16, buf []byte, dest interface{})
|
|||||||
|
|
||||||
var ErrScanTargetTypeChanged = errors.New("scan target type changed")
|
var ErrScanTargetTypeChanged = errors.New("scan target type changed")
|
||||||
|
|
||||||
func codecScan(codec Codec, ci *ConnInfo, oid uint32, format int16, src []byte, dst interface{}) error {
|
func codecScan(codec Codec, m *Map, oid uint32, format int16, src []byte, dst interface{}) error {
|
||||||
scanPlan := codec.PlanScan(ci, oid, format, dst, true)
|
scanPlan := codec.PlanScan(m, oid, format, dst, true)
|
||||||
if scanPlan == nil {
|
if scanPlan == nil {
|
||||||
return fmt.Errorf("PlanScan did not find a plan")
|
return fmt.Errorf("PlanScan did not find a plan")
|
||||||
}
|
}
|
||||||
return scanPlan.Scan(src, dst)
|
return scanPlan.Scan(src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
func codecDecodeToTextFormat(codec Codec, ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func codecDecodeToTextFormat(codec Codec, m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -1107,11 +1109,11 @@ func codecDecodeToTextFormat(codec Codec, ci *ConnInfo, oid uint32, format int16
|
|||||||
if format == TextFormatCode {
|
if format == TextFormatCode {
|
||||||
return string(src), nil
|
return string(src), nil
|
||||||
} else {
|
} else {
|
||||||
value, err := codec.DecodeValue(ci, oid, format, src)
|
value, err := codec.DecodeValue(m, oid, format, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
buf, err := ci.Encode(oid, TextFormatCode, value, nil)
|
buf, err := m.Encode(oid, TextFormatCode, value, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1121,29 +1123,29 @@ func codecDecodeToTextFormat(codec Codec, ci *ConnInfo, oid uint32, format int16
|
|||||||
|
|
||||||
// PlanEncode returns an Encode plan for encoding value into PostgreSQL format for oid and format. If no plan can be
|
// PlanEncode returns an Encode plan for encoding value into PostgreSQL format for oid and format. If no plan can be
|
||||||
// found then nil is returned.
|
// found then nil is returned.
|
||||||
func (ci *ConnInfo) PlanEncode(oid uint32, format int16, value interface{}) EncodePlan {
|
func (m *Map) PlanEncode(oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
|
|
||||||
var dt *Type
|
var dt *Type
|
||||||
|
|
||||||
if oid == 0 {
|
if oid == 0 {
|
||||||
if dataType, ok := ci.TypeForValue(value); ok {
|
if dataType, ok := m.TypeForValue(value); ok {
|
||||||
dt = dataType
|
dt = dataType
|
||||||
oid = dt.OID // Preserve assumed OID in case we are recursively called below.
|
oid = dt.OID // Preserve assumed OID in case we are recursively called below.
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if dataType, ok := ci.TypeForOID(oid); ok {
|
if dataType, ok := m.TypeForOID(oid); ok {
|
||||||
dt = dataType
|
dt = dataType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if dt != nil {
|
if dt != nil {
|
||||||
if plan := dt.Codec.PlanEncode(ci, oid, format, value); plan != nil {
|
if plan := dt.Codec.PlanEncode(m, oid, format, value); plan != nil {
|
||||||
return plan
|
return plan
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range ci.TryWrapEncodePlanFuncs {
|
for _, f := range m.TryWrapEncodePlanFuncs {
|
||||||
if wrapperPlan, nextValue, ok := f(value); ok {
|
if wrapperPlan, nextValue, ok := f(value); ok {
|
||||||
if nextPlan := ci.PlanEncode(oid, format, nextValue); nextPlan != nil {
|
if nextPlan := m.PlanEncode(oid, format, nextValue); nextPlan != nil {
|
||||||
wrapperPlan.SetNext(nextPlan)
|
wrapperPlan.SetNext(nextPlan)
|
||||||
return wrapperPlan
|
return wrapperPlan
|
||||||
}
|
}
|
||||||
@@ -1615,12 +1617,12 @@ func (plan *wrapMultiDimSliceEncodePlan) Encode(value interface{}, buf []byte) (
|
|||||||
// Encode appends the encoded bytes of value to buf. If value is the SQL value NULL then append nothing and return
|
// Encode appends the encoded bytes of value to buf. If value is the SQL value NULL then append nothing and return
|
||||||
// (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data
|
// (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data
|
||||||
// written.
|
// written.
|
||||||
func (ci *ConnInfo) Encode(oid uint32, formatCode int16, value interface{}, buf []byte) (newBuf []byte, err error) {
|
func (m *Map) Encode(oid uint32, formatCode int16, value interface{}, buf []byte) (newBuf []byte, err error) {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
plan := ci.PlanEncode(oid, formatCode, value)
|
plan := m.PlanEncode(oid, formatCode, value)
|
||||||
if plan == nil {
|
if plan == nil {
|
||||||
return nil, fmt.Errorf("unable to encode %#v into OID %d", value, oid)
|
return nil, fmt.Errorf("unable to encode %#v into OID %d", value, oid)
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-40
@@ -67,59 +67,59 @@ func mustParseMacaddr(t testing.TB, s string) net.HardwareAddr {
|
|||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnInfoScanNilIsNoOp(t *testing.T) {
|
func TestTypeMapScanNilIsNoOp(t *testing.T) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
|
|
||||||
err := ci.Scan(pgtype.TextOID, pgx.TextFormatCode, []byte("foo"), nil)
|
err := m.Scan(pgtype.TextOID, pgx.TextFormatCode, []byte("foo"), nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnInfoScanTextFormatInterfacePtr(t *testing.T) {
|
func TestTypeMapScanTextFormatInterfacePtr(t *testing.T) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
var got interface{}
|
var got interface{}
|
||||||
err := ci.Scan(pgtype.TextOID, pgx.TextFormatCode, []byte("foo"), &got)
|
err := m.Scan(pgtype.TextOID, pgx.TextFormatCode, []byte("foo"), &got)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "foo", got)
|
assert.Equal(t, "foo", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnInfoScanTextFormatNonByteaIntoByteSlice(t *testing.T) {
|
func TestTypeMapScanTextFormatNonByteaIntoByteSlice(t *testing.T) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
var got []byte
|
var got []byte
|
||||||
err := ci.Scan(pgtype.JSONBOID, pgx.TextFormatCode, []byte("{}"), &got)
|
err := m.Scan(pgtype.JSONBOID, pgx.TextFormatCode, []byte("{}"), &got)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []byte("{}"), got)
|
assert.Equal(t, []byte("{}"), got)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnInfoScanBinaryFormatInterfacePtr(t *testing.T) {
|
func TestTypeMapScanBinaryFormatInterfacePtr(t *testing.T) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
var got interface{}
|
var got interface{}
|
||||||
err := ci.Scan(pgtype.TextOID, pgx.BinaryFormatCode, []byte("foo"), &got)
|
err := m.Scan(pgtype.TextOID, pgx.BinaryFormatCode, []byte("foo"), &got)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "foo", got)
|
assert.Equal(t, "foo", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnInfoScanUnknownOIDToStringsAndBytes(t *testing.T) {
|
func TestTypeMapScanUnknownOIDToStringsAndBytes(t *testing.T) {
|
||||||
unknownOID := uint32(999999)
|
unknownOID := uint32(999999)
|
||||||
srcBuf := []byte("foo")
|
srcBuf := []byte("foo")
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
|
|
||||||
var s string
|
var s string
|
||||||
err := ci.Scan(unknownOID, pgx.TextFormatCode, srcBuf, &s)
|
err := m.Scan(unknownOID, pgx.TextFormatCode, srcBuf, &s)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "foo", s)
|
assert.Equal(t, "foo", s)
|
||||||
|
|
||||||
var rs _string
|
var rs _string
|
||||||
err = ci.Scan(unknownOID, pgx.TextFormatCode, srcBuf, &rs)
|
err = m.Scan(unknownOID, pgx.TextFormatCode, srcBuf, &rs)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "foo", string(rs))
|
assert.Equal(t, "foo", string(rs))
|
||||||
|
|
||||||
var b []byte
|
var b []byte
|
||||||
err = ci.Scan(unknownOID, pgx.TextFormatCode, srcBuf, &b)
|
err = m.Scan(unknownOID, pgx.TextFormatCode, srcBuf, &b)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []byte("foo"), b)
|
assert.Equal(t, []byte("foo"), b)
|
||||||
|
|
||||||
var rb _byteSlice
|
var rb _byteSlice
|
||||||
err = ci.Scan(unknownOID, pgx.TextFormatCode, srcBuf, &rb)
|
err = m.Scan(unknownOID, pgx.TextFormatCode, srcBuf, &rb)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []byte("foo"), []byte(rb))
|
assert.Equal(t, []byte("foo"), []byte(rb))
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ type pgCustomType struct {
|
|||||||
b string
|
b string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *pgCustomType) DecodeText(ci *pgtype.ConnInfo, buf []byte) error {
|
func (ct *pgCustomType) DecodeText(m *pgtype.Map, buf []byte) error {
|
||||||
// This is not a complete parser for the text format of composite types. This is just for test purposes.
|
// This is not a complete parser for the text format of composite types. This is just for test purposes.
|
||||||
if buf == nil {
|
if buf == nil {
|
||||||
return errors.New("cannot parse null")
|
return errors.New("cannot parse null")
|
||||||
@@ -150,58 +150,58 @@ func (ct *pgCustomType) DecodeText(ci *pgtype.ConnInfo, buf []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnInfoScanUnregisteredOIDToCustomType(t *testing.T) {
|
func TestTypeMapScanUnregisteredOIDToCustomType(t *testing.T) {
|
||||||
t.Skip("TODO - unskip later in v5") // may no longer be relevent
|
t.Skip("TODO - unskip later in v5") // may no longer be relevent
|
||||||
unregisteredOID := uint32(999999)
|
unregisteredOID := uint32(999999)
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
|
|
||||||
var ct pgCustomType
|
var ct pgCustomType
|
||||||
err := ci.Scan(unregisteredOID, pgx.TextFormatCode, []byte("(foo,bar)"), &ct)
|
err := m.Scan(unregisteredOID, pgx.TextFormatCode, []byte("(foo,bar)"), &ct)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "foo", ct.a)
|
assert.Equal(t, "foo", ct.a)
|
||||||
assert.Equal(t, "bar", ct.b)
|
assert.Equal(t, "bar", ct.b)
|
||||||
|
|
||||||
// Scan value into pointer to custom type
|
// Scan value into pointer to custom type
|
||||||
var pCt *pgCustomType
|
var pCt *pgCustomType
|
||||||
err = ci.Scan(unregisteredOID, pgx.TextFormatCode, []byte("(foo,bar)"), &pCt)
|
err = m.Scan(unregisteredOID, pgx.TextFormatCode, []byte("(foo,bar)"), &pCt)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
require.NotNil(t, pCt)
|
require.NotNil(t, pCt)
|
||||||
assert.Equal(t, "foo", pCt.a)
|
assert.Equal(t, "foo", pCt.a)
|
||||||
assert.Equal(t, "bar", pCt.b)
|
assert.Equal(t, "bar", pCt.b)
|
||||||
|
|
||||||
// Scan null into pointer to custom type
|
// Scan null into pointer to custom type
|
||||||
err = ci.Scan(unregisteredOID, pgx.TextFormatCode, nil, &pCt)
|
err = m.Scan(unregisteredOID, pgx.TextFormatCode, nil, &pCt)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Nil(t, pCt)
|
assert.Nil(t, pCt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnInfoScanUnknownOIDTextFormat(t *testing.T) {
|
func TestTypeMapScanUnknownOIDTextFormat(t *testing.T) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
|
|
||||||
var n int32
|
var n int32
|
||||||
err := ci.Scan(0, pgx.TextFormatCode, []byte("123"), &n)
|
err := m.Scan(0, pgx.TextFormatCode, []byte("123"), &n)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 123, n)
|
assert.EqualValues(t, 123, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnInfoScanUnknownOIDIntoSQLScanner(t *testing.T) {
|
func TestTypeMapScanUnknownOIDIntoSQLScanner(t *testing.T) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
|
|
||||||
var s sql.NullString
|
var s sql.NullString
|
||||||
err := ci.Scan(0, pgx.TextFormatCode, []byte(nil), &s)
|
err := m.Scan(0, pgx.TextFormatCode, []byte(nil), &s)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "", s.String)
|
assert.Equal(t, "", s.String)
|
||||||
assert.False(t, s.Valid)
|
assert.False(t, s.Valid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkConnInfoScanInt4IntoBinaryDecoder(b *testing.B) {
|
func BenchmarkTypeMapScanInt4IntoBinaryDecoder(b *testing.B) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
src := []byte{0, 0, 0, 42}
|
src := []byte{0, 0, 0, 42}
|
||||||
var v pgtype.Int4
|
var v pgtype.Int4
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
v = pgtype.Int4{}
|
v = pgtype.Int4{}
|
||||||
err := ci.Scan(pgtype.Int4OID, pgtype.BinaryFormatCode, src, &v)
|
err := m.Scan(pgtype.Int4OID, pgtype.BinaryFormatCode, src, &v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -211,14 +211,14 @@ func BenchmarkConnInfoScanInt4IntoBinaryDecoder(b *testing.B) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkConnInfoScanInt4IntoGoInt32(b *testing.B) {
|
func BenchmarkTypeMapScanInt4IntoGoInt32(b *testing.B) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
src := []byte{0, 0, 0, 42}
|
src := []byte{0, 0, 0, 42}
|
||||||
var v int32
|
var v int32
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
v = 0
|
v = 0
|
||||||
err := ci.Scan(pgtype.Int4OID, pgtype.BinaryFormatCode, src, &v)
|
err := m.Scan(pgtype.Int4OID, pgtype.BinaryFormatCode, src, &v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -229,11 +229,11 @@ func BenchmarkConnInfoScanInt4IntoGoInt32(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkScanPlanScanInt4IntoBinaryDecoder(b *testing.B) {
|
func BenchmarkScanPlanScanInt4IntoBinaryDecoder(b *testing.B) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
src := []byte{0, 0, 0, 42}
|
src := []byte{0, 0, 0, 42}
|
||||||
var v pgtype.Int4
|
var v pgtype.Int4
|
||||||
|
|
||||||
plan := ci.PlanScan(pgtype.Int4OID, pgtype.BinaryFormatCode, &v)
|
plan := m.PlanScan(pgtype.Int4OID, pgtype.BinaryFormatCode, &v)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
v = pgtype.Int4{}
|
v = pgtype.Int4{}
|
||||||
@@ -248,11 +248,11 @@ func BenchmarkScanPlanScanInt4IntoBinaryDecoder(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkScanPlanScanInt4IntoGoInt32(b *testing.B) {
|
func BenchmarkScanPlanScanInt4IntoGoInt32(b *testing.B) {
|
||||||
ci := pgtype.NewConnInfo()
|
m := pgtype.NewMap()
|
||||||
src := []byte{0, 0, 0, 42}
|
src := []byte{0, 0, 0, 42}
|
||||||
var v int32
|
var v int32
|
||||||
|
|
||||||
plan := ci.PlanScan(pgtype.Int4OID, pgtype.BinaryFormatCode, &v)
|
plan := m.PlanScan(pgtype.Int4OID, pgtype.BinaryFormatCode, &v)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
v = 0
|
v = 0
|
||||||
|
|||||||
+6
-6
@@ -127,7 +127,7 @@ func (PointCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (PointCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (PointCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(PointValuer); !ok {
|
if _, ok := value.(PointValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ func (encodePlanPointCodecText) Encode(value interface{}, buf []byte) (newBuf []
|
|||||||
)...), nil
|
)...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (PointCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (PointCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -195,17 +195,17 @@ func (PointCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interf
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c PointCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c PointCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c PointCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c PointCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var point Point
|
var point Point
|
||||||
err := codecScan(c, ci, oid, format, src, &point)
|
err := codecScan(c, m, oid, format, src, &point)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -72,7 +72,7 @@ func (PolygonCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (PolygonCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (PolygonCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(PolygonValuer); !ok {
|
if _, ok := value.(PolygonValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ func (encodePlanPolygonCodecText) Encode(value interface{}, buf []byte) (newBuf
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (PolygonCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (PolygonCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -235,17 +235,17 @@ func (scanPlanTextAnyToPolygonScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanPolygon(Polygon{P: points, Valid: true})
|
return scanner.ScanPolygon(Polygon{P: points, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c PolygonCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c PolygonCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c PolygonCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c PolygonCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var polygon Polygon
|
var polygon Polygon
|
||||||
err := codecScan(c, ci, oid, format, src, &polygon)
|
err := codecScan(c, m, oid, format, src, &polygon)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -22,7 +22,7 @@ func (QCharCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (QCharCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (QCharCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case TextFormatCode, BinaryFormatCode:
|
case TextFormatCode, BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -56,7 +56,7 @@ func (encodePlanQcharCodecRune) Encode(value interface{}, buf []byte) (newBuf []
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (QCharCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (QCharCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
switch format {
|
switch format {
|
||||||
case TextFormatCode, BinaryFormatCode:
|
case TextFormatCode, BinaryFormatCode:
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
@@ -114,26 +114,26 @@ func (scanPlanQcharCodecRune) Scan(src []byte, dst interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c QCharCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c QCharCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var r rune
|
var r rune
|
||||||
err := codecScan(c, ci, oid, format, src, &r)
|
err := codecScan(c, m, oid, format, src, &r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return string(r), nil
|
return string(r), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c QCharCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c QCharCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var r rune
|
var r rune
|
||||||
err := codecScan(c, ci, oid, format, src, &r)
|
err := codecScan(c, m, oid, format, src, &r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-21
@@ -86,16 +86,16 @@ func (c *RangeCodec) PreferredFormat() int16 {
|
|||||||
return TextFormatCode
|
return TextFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RangeCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (c *RangeCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(RangeValuer); !ok {
|
if _, ok := value.(RangeValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
return &encodePlanRangeCodecRangeValuerToBinary{rc: c, ci: ci}
|
return &encodePlanRangeCodecRangeValuerToBinary{rc: c, m: m}
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
return &encodePlanRangeCodecRangeValuerToText{rc: c, ci: ci}
|
return &encodePlanRangeCodecRangeValuerToText{rc: c, m: m}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -103,7 +103,7 @@ func (c *RangeCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value in
|
|||||||
|
|
||||||
type encodePlanRangeCodecRangeValuerToBinary struct {
|
type encodePlanRangeCodecRangeValuerToBinary struct {
|
||||||
rc *RangeCodec
|
rc *RangeCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *encodePlanRangeCodecRangeValuerToBinary) Encode(value interface{}, buf []byte) (newBuf []byte, err error) {
|
func (plan *encodePlanRangeCodecRangeValuerToBinary) Encode(value interface{}, buf []byte) (newBuf []byte, err error) {
|
||||||
@@ -149,7 +149,7 @@ func (plan *encodePlanRangeCodecRangeValuerToBinary) Encode(value interface{}, b
|
|||||||
sp := len(buf)
|
sp := len(buf)
|
||||||
buf = pgio.AppendInt32(buf, -1)
|
buf = pgio.AppendInt32(buf, -1)
|
||||||
|
|
||||||
lowerPlan := plan.ci.PlanEncode(plan.rc.ElementType.OID, BinaryFormatCode, lower)
|
lowerPlan := plan.m.PlanEncode(plan.rc.ElementType.OID, BinaryFormatCode, lower)
|
||||||
if lowerPlan == nil {
|
if lowerPlan == nil {
|
||||||
return nil, fmt.Errorf("cannot encode %v as element of range", lower)
|
return nil, fmt.Errorf("cannot encode %v as element of range", lower)
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ func (plan *encodePlanRangeCodecRangeValuerToBinary) Encode(value interface{}, b
|
|||||||
sp := len(buf)
|
sp := len(buf)
|
||||||
buf = pgio.AppendInt32(buf, -1)
|
buf = pgio.AppendInt32(buf, -1)
|
||||||
|
|
||||||
upperPlan := plan.ci.PlanEncode(plan.rc.ElementType.OID, BinaryFormatCode, upper)
|
upperPlan := plan.m.PlanEncode(plan.rc.ElementType.OID, BinaryFormatCode, upper)
|
||||||
if upperPlan == nil {
|
if upperPlan == nil {
|
||||||
return nil, fmt.Errorf("cannot encode %v as element of range", upper)
|
return nil, fmt.Errorf("cannot encode %v as element of range", upper)
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ func (plan *encodePlanRangeCodecRangeValuerToBinary) Encode(value interface{}, b
|
|||||||
|
|
||||||
type encodePlanRangeCodecRangeValuerToText struct {
|
type encodePlanRangeCodecRangeValuerToText struct {
|
||||||
rc *RangeCodec
|
rc *RangeCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value interface{}, buf []byte) (newBuf []byte, err error) {
|
func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value interface{}, buf []byte) (newBuf []byte, err error) {
|
||||||
@@ -223,7 +223,7 @@ func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value interface{}, buf
|
|||||||
return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded")
|
return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded")
|
||||||
}
|
}
|
||||||
|
|
||||||
lowerPlan := plan.ci.PlanEncode(plan.rc.ElementType.OID, TextFormatCode, lower)
|
lowerPlan := plan.m.PlanEncode(plan.rc.ElementType.OID, TextFormatCode, lower)
|
||||||
if lowerPlan == nil {
|
if lowerPlan == nil {
|
||||||
return nil, fmt.Errorf("cannot encode %v as element of range", lower)
|
return nil, fmt.Errorf("cannot encode %v as element of range", lower)
|
||||||
}
|
}
|
||||||
@@ -244,7 +244,7 @@ func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value interface{}, buf
|
|||||||
return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded")
|
return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded")
|
||||||
}
|
}
|
||||||
|
|
||||||
upperPlan := plan.ci.PlanEncode(plan.rc.ElementType.OID, TextFormatCode, upper)
|
upperPlan := plan.m.PlanEncode(plan.rc.ElementType.OID, TextFormatCode, upper)
|
||||||
if upperPlan == nil {
|
if upperPlan == nil {
|
||||||
return nil, fmt.Errorf("cannot encode %v as element of range", upper)
|
return nil, fmt.Errorf("cannot encode %v as element of range", upper)
|
||||||
}
|
}
|
||||||
@@ -270,17 +270,17 @@ func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value interface{}, buf
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RangeCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (c *RangeCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
case RangeScanner:
|
case RangeScanner:
|
||||||
return &scanPlanBinaryRangeToRangeScanner{rc: c, ci: ci}
|
return &scanPlanBinaryRangeToRangeScanner{rc: c, m: m}
|
||||||
}
|
}
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
case RangeScanner:
|
case RangeScanner:
|
||||||
return &scanPlanTextRangeToRangeScanner{rc: c, ci: ci}
|
return &scanPlanTextRangeToRangeScanner{rc: c, m: m}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +289,7 @@ func (c *RangeCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target int
|
|||||||
|
|
||||||
type scanPlanBinaryRangeToRangeScanner struct {
|
type scanPlanBinaryRangeToRangeScanner struct {
|
||||||
rc *RangeCodec
|
rc *RangeCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target interface{}) error {
|
func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target interface{}) error {
|
||||||
@@ -311,7 +311,7 @@ func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target interface
|
|||||||
lowerTarget, upperTarget := rangeScanner.ScanBounds()
|
lowerTarget, upperTarget := rangeScanner.ScanBounds()
|
||||||
|
|
||||||
if ubr.LowerType == Inclusive || ubr.LowerType == Exclusive {
|
if ubr.LowerType == Inclusive || ubr.LowerType == Exclusive {
|
||||||
lowerPlan := plan.ci.PlanScan(plan.rc.ElementType.OID, BinaryFormatCode, lowerTarget)
|
lowerPlan := plan.m.PlanScan(plan.rc.ElementType.OID, BinaryFormatCode, lowerTarget)
|
||||||
if lowerPlan == nil {
|
if lowerPlan == nil {
|
||||||
return fmt.Errorf("cannot scan into %v from range element", lowerTarget)
|
return fmt.Errorf("cannot scan into %v from range element", lowerTarget)
|
||||||
}
|
}
|
||||||
@@ -323,7 +323,7 @@ func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ubr.UpperType == Inclusive || ubr.UpperType == Exclusive {
|
if ubr.UpperType == Inclusive || ubr.UpperType == Exclusive {
|
||||||
upperPlan := plan.ci.PlanScan(plan.rc.ElementType.OID, BinaryFormatCode, upperTarget)
|
upperPlan := plan.m.PlanScan(plan.rc.ElementType.OID, BinaryFormatCode, upperTarget)
|
||||||
if upperPlan == nil {
|
if upperPlan == nil {
|
||||||
return fmt.Errorf("cannot scan into %v from range element", upperTarget)
|
return fmt.Errorf("cannot scan into %v from range element", upperTarget)
|
||||||
}
|
}
|
||||||
@@ -339,7 +339,7 @@ func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target interface
|
|||||||
|
|
||||||
type scanPlanTextRangeToRangeScanner struct {
|
type scanPlanTextRangeToRangeScanner struct {
|
||||||
rc *RangeCodec
|
rc *RangeCodec
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target interface{}) error {
|
func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target interface{}) error {
|
||||||
@@ -361,7 +361,7 @@ func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target interface{}
|
|||||||
lowerTarget, upperTarget := rangeScanner.ScanBounds()
|
lowerTarget, upperTarget := rangeScanner.ScanBounds()
|
||||||
|
|
||||||
if utr.LowerType == Inclusive || utr.LowerType == Exclusive {
|
if utr.LowerType == Inclusive || utr.LowerType == Exclusive {
|
||||||
lowerPlan := plan.ci.PlanScan(plan.rc.ElementType.OID, TextFormatCode, lowerTarget)
|
lowerPlan := plan.m.PlanScan(plan.rc.ElementType.OID, TextFormatCode, lowerTarget)
|
||||||
if lowerPlan == nil {
|
if lowerPlan == nil {
|
||||||
return fmt.Errorf("cannot scan into %v from range element", lowerTarget)
|
return fmt.Errorf("cannot scan into %v from range element", lowerTarget)
|
||||||
}
|
}
|
||||||
@@ -373,7 +373,7 @@ func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target interface{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
if utr.UpperType == Inclusive || utr.UpperType == Exclusive {
|
if utr.UpperType == Inclusive || utr.UpperType == Exclusive {
|
||||||
upperPlan := plan.ci.PlanScan(plan.rc.ElementType.OID, TextFormatCode, upperTarget)
|
upperPlan := plan.m.PlanScan(plan.rc.ElementType.OID, TextFormatCode, upperTarget)
|
||||||
if upperPlan == nil {
|
if upperPlan == nil {
|
||||||
return fmt.Errorf("cannot scan into %v from range element", upperTarget)
|
return fmt.Errorf("cannot scan into %v from range element", upperTarget)
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@ func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target interface{}
|
|||||||
return rangeScanner.SetBoundTypes(utr.LowerType, utr.UpperType)
|
return rangeScanner.SetBoundTypes(utr.LowerType, utr.UpperType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RangeCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c *RangeCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -404,12 +404,12 @@ func (c *RangeCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RangeCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c *RangeCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var r GenericRange
|
var r GenericRange
|
||||||
err := c.PlanScan(ci, oid, format, &r, true).Scan(src, &r)
|
err := c.PlanScan(m, oid, format, &r, true).Scan(src, &r)
|
||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -21,15 +21,15 @@ func (RecordCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (RecordCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (RecordCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (RecordCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (RecordCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
if format == BinaryFormatCode {
|
if format == BinaryFormatCode {
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
case CompositeIndexScanner:
|
case CompositeIndexScanner:
|
||||||
return &scanPlanBinaryRecordToCompositeIndexScanner{ci: ci}
|
return &scanPlanBinaryRecordToCompositeIndexScanner{m: m}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ func (RecordCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
type scanPlanBinaryRecordToCompositeIndexScanner struct {
|
type scanPlanBinaryRecordToCompositeIndexScanner struct {
|
||||||
ci *ConnInfo
|
m *Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plan *scanPlanBinaryRecordToCompositeIndexScanner) Scan(src []byte, target interface{}) error {
|
func (plan *scanPlanBinaryRecordToCompositeIndexScanner) Scan(src []byte, target interface{}) error {
|
||||||
@@ -47,11 +47,11 @@ func (plan *scanPlanBinaryRecordToCompositeIndexScanner) Scan(src []byte, target
|
|||||||
return targetScanner.ScanNull()
|
return targetScanner.ScanNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner := NewCompositeBinaryScanner(plan.ci, src)
|
scanner := NewCompositeBinaryScanner(plan.m, src)
|
||||||
for i := 0; scanner.Next(); i++ {
|
for i := 0; scanner.Next(); i++ {
|
||||||
fieldTarget := targetScanner.ScanIndex(i)
|
fieldTarget := targetScanner.ScanIndex(i)
|
||||||
if fieldTarget != nil {
|
if fieldTarget != nil {
|
||||||
fieldPlan := plan.ci.PlanScan(scanner.OID(), BinaryFormatCode, fieldTarget)
|
fieldPlan := plan.m.PlanScan(scanner.OID(), BinaryFormatCode, fieldTarget)
|
||||||
if fieldPlan == nil {
|
if fieldPlan == nil {
|
||||||
return fmt.Errorf("unable to scan OID %d in binary format into %v", scanner.OID(), fieldTarget)
|
return fmt.Errorf("unable to scan OID %d in binary format into %v", scanner.OID(), fieldTarget)
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ func (plan *scanPlanBinaryRecordToCompositeIndexScanner) Scan(src []byte, target
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (RecordCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (RecordCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ func (RecordCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (RecordCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (RecordCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -96,11 +96,11 @@ func (RecordCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byt
|
|||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
return string(src), nil
|
return string(src), nil
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
scanner := NewCompositeBinaryScanner(ci, src)
|
scanner := NewCompositeBinaryScanner(m, src)
|
||||||
values := make([]interface{}, scanner.FieldCount())
|
values := make([]interface{}, scanner.FieldCount())
|
||||||
for i := 0; scanner.Next(); i++ {
|
for i := 0; scanner.Next(); i++ {
|
||||||
var v interface{}
|
var v interface{}
|
||||||
fieldPlan := ci.PlanScan(scanner.OID(), BinaryFormatCode, &v)
|
fieldPlan := m.PlanScan(scanner.OID(), BinaryFormatCode, &v)
|
||||||
if fieldPlan == nil {
|
if fieldPlan == nil {
|
||||||
return nil, fmt.Errorf("unable to scan OID %d in binary format into %v", scanner.OID(), v)
|
return nil, fmt.Errorf("unable to scan OID %d in binary format into %v", scanner.OID(), v)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -90,7 +90,7 @@ func (TextCodec) PreferredFormat() int16 {
|
|||||||
return TextFormatCode
|
return TextFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TextCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (TextCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case TextFormatCode, BinaryFormatCode:
|
case TextFormatCode, BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -156,7 +156,7 @@ func (encodePlanTextCodecTextValuer) Encode(value interface{}, buf []byte) (newB
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TextCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (TextCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case TextFormatCode, BinaryFormatCode:
|
case TextFormatCode, BinaryFormatCode:
|
||||||
@@ -175,11 +175,11 @@ func (TextCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interfa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TextCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c TextCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return c.DecodeValue(ci, oid, format, src)
|
return c.DecodeValue(m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TextCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c TextCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -82,7 +82,7 @@ func (TIDCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TIDCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (TIDCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(TIDValuer); !ok {
|
if _, ok := value.(TIDValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ func (encodePlanTIDCodecText) Encode(value interface{}, buf []byte) (newBuf []by
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TIDCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (TIDCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -223,17 +223,17 @@ func (scanPlanTextAnyToTIDScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanTID(TID{BlockNumber: uint32(blockNumber), OffsetNumber: uint16(offsetNumber), Valid: true})
|
return scanner.ScanTID(TID{BlockNumber: uint32(blockNumber), OffsetNumber: uint16(offsetNumber), Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TIDCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c TIDCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TIDCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c TIDCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var tid TID
|
var tid TID
|
||||||
err := codecScan(c, ci, oid, format, src, &tid)
|
err := codecScan(c, m, oid, format, src, &tid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -74,7 +74,7 @@ func (TimeCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TimeCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (TimeCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(TimeValuer); !ok {
|
if _, ok := value.(TimeValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ func (encodePlanTimeCodecText) Encode(value interface{}, buf []byte) (newBuf []b
|
|||||||
return append(buf, s...), nil
|
return append(buf, s...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TimeCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (TimeCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -215,17 +215,17 @@ func (scanPlanTextAnyToTimeScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanTime(Time{Microseconds: usec, Valid: true})
|
return scanner.ScanTime(Time{Microseconds: usec, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TimeCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c TimeCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
return codecDecodeToTextFormat(c, m, oid, format, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TimeCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c TimeCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var t Time
|
var t Time
|
||||||
err := codecScan(c, ci, oid, format, src, &t)
|
err := codecScan(c, m, oid, format, src, &t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -75,7 +75,7 @@ func (TimestampCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TimestampCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (TimestampCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(TimestampValuer); !ok {
|
if _, ok := value.(TimestampValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -152,7 +152,7 @@ func discardTimeZone(t time.Time) time.Time {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TimestampCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (TimestampCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -230,13 +230,13 @@ func (scanPlanTextTimestampToTimestampScanner) Scan(src []byte, dst interface{})
|
|||||||
return scanner.ScanTimestamp(ts)
|
return scanner.ScanTimestamp(ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TimestampCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c TimestampCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var ts Timestamp
|
var ts Timestamp
|
||||||
err := codecScan(c, ci, oid, format, src, &ts)
|
err := codecScan(c, m, oid, format, src, &ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -248,13 +248,13 @@ func (c TimestampCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format
|
|||||||
return ts.Time, nil
|
return ts.Time, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TimestampCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c TimestampCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var ts Timestamp
|
var ts Timestamp
|
||||||
err := codecScan(c, ci, oid, format, src, &ts)
|
err := codecScan(c, m, oid, format, src, &ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ func (TimestamptzCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TimestamptzCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (TimestamptzCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(TimestamptzValuer); !ok {
|
if _, ok := value.(TimestamptzValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -200,7 +200,7 @@ func (encodePlanTimestamptzCodecText) Encode(value interface{}, buf []byte) (new
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TimestamptzCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (TimestamptzCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -287,13 +287,13 @@ func (scanPlanTextTimestamptzToTimestamptzScanner) Scan(src []byte, dst interfac
|
|||||||
return scanner.ScanTimestamptz(tstz)
|
return scanner.ScanTimestamptz(tstz)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TimestamptzCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c TimestamptzCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var tstz Timestamptz
|
var tstz Timestamptz
|
||||||
err := codecScan(c, ci, oid, format, src, &tstz)
|
err := codecScan(c, m, oid, format, src, &tstz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -305,13 +305,13 @@ func (c TimestamptzCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, forma
|
|||||||
return tstz.Time, nil
|
return tstz.Time, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TimestamptzCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c TimestamptzCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var tstz Timestamptz
|
var tstz Timestamptz
|
||||||
err := codecScan(c, ci, oid, format, src, &tstz)
|
err := codecScan(c, m, oid, format, src, &tstz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -85,7 +85,7 @@ func (Uint32Codec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Uint32Codec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (Uint32Codec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@@ -196,7 +196,7 @@ func (encodePlanUint32CodecTextInt64Valuer) Encode(value interface{}, buf []byte
|
|||||||
return append(buf, strconv.FormatInt(v.Int, 10)...), nil
|
return append(buf, strconv.FormatInt(v.Int, 10)...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Uint32Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (Uint32Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
@@ -218,26 +218,26 @@ func (Uint32Codec) PlanScan(ci *ConnInfo, oid uint32, format int16, target inter
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Uint32Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c Uint32Codec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n uint32
|
var n uint32
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return int64(n), nil
|
return int64(n), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Uint32Codec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c Uint32Codec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var n uint32
|
var n uint32
|
||||||
err := codecScan(c, ci, oid, format, src, &n)
|
err := codecScan(c, m, oid, format, src, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -122,7 +122,7 @@ func (UUIDCodec) PreferredFormat() int16 {
|
|||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UUIDCodec) PlanEncode(ci *ConnInfo, oid uint32, format int16, value interface{}) EncodePlan {
|
func (UUIDCodec) PlanEncode(m *Map, oid uint32, format int16, value interface{}) EncodePlan {
|
||||||
if _, ok := value.(UUIDValuer); !ok {
|
if _, ok := value.(UUIDValuer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,7 @@ func (encodePlanUUIDCodecTextUUIDValuer) Encode(value interface{}, buf []byte) (
|
|||||||
return append(buf, encodeUUID(uuid.Bytes)...), nil
|
return append(buf, encodeUUID(uuid.Bytes)...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UUIDCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
func (UUIDCodec) PlanScan(m *Map, oid uint32, format int16, target interface{}, actualTarget bool) ScanPlan {
|
||||||
switch format {
|
switch format {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
switch target.(type) {
|
switch target.(type) {
|
||||||
@@ -220,13 +220,13 @@ func (scanPlanTextAnyToUUIDScanner) Scan(src []byte, dst interface{}) error {
|
|||||||
return scanner.ScanUUID(UUID{Bytes: buf, Valid: true})
|
return scanner.ScanUUID(UUID{Bytes: buf, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c UUIDCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c UUIDCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var uuid UUID
|
var uuid UUID
|
||||||
err := codecScan(c, ci, oid, format, src, &uuid)
|
err := codecScan(c, m, oid, format, src, &uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -234,13 +234,13 @@ func (c UUIDCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16
|
|||||||
return encodeUUID(uuid.Bytes), nil
|
return encodeUUID(uuid.Bytes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c UUIDCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c UUIDCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var uuid UUID
|
var uuid UUID
|
||||||
err := codecScan(c, ci, oid, format, src, &uuid)
|
err := codecScan(c, m, oid, format, src, &uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1358,7 +1358,7 @@ func TestScanRow(t *testing.T) {
|
|||||||
|
|
||||||
for resultReader.NextRow() {
|
for resultReader.NextRow() {
|
||||||
var n int32
|
var n int32
|
||||||
err := pgx.ScanRow(conn.ConnInfo(), resultReader.FieldDescriptions(), resultReader.Values(), &n)
|
err := pgx.ScanRow(conn.TypeMap(), resultReader.FieldDescriptions(), resultReader.Values(), &n)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
sum += n
|
sum += n
|
||||||
rowCount++
|
rowCount++
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ type rowLog interface {
|
|||||||
type connRows struct {
|
type connRows struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
logger rowLog
|
logger rowLog
|
||||||
connInfo *pgtype.ConnInfo
|
typeMap *pgtype.Map
|
||||||
values [][]byte
|
values [][]byte
|
||||||
rowCount int
|
rowCount int
|
||||||
err error
|
err error
|
||||||
@@ -196,7 +196,7 @@ func (rows *connRows) Next() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rows *connRows) Scan(dest ...interface{}) error {
|
func (rows *connRows) Scan(dest ...interface{}) error {
|
||||||
ci := rows.connInfo
|
m := rows.typeMap
|
||||||
fieldDescriptions := rows.FieldDescriptions()
|
fieldDescriptions := rows.FieldDescriptions()
|
||||||
values := rows.values
|
values := rows.values
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ func (rows *connRows) Scan(dest ...interface{}) error {
|
|||||||
rows.scanPlans = make([]pgtype.ScanPlan, len(values))
|
rows.scanPlans = make([]pgtype.ScanPlan, len(values))
|
||||||
rows.scanTypes = make([]reflect.Type, len(values))
|
rows.scanTypes = make([]reflect.Type, len(values))
|
||||||
for i := range dest {
|
for i := range dest {
|
||||||
rows.scanPlans[i] = ci.PlanScan(fieldDescriptions[i].DataTypeOID, fieldDescriptions[i].Format, dest[i])
|
rows.scanPlans[i] = m.PlanScan(fieldDescriptions[i].DataTypeOID, fieldDescriptions[i].Format, dest[i])
|
||||||
rows.scanTypes[i] = reflect.TypeOf(dest[i])
|
rows.scanTypes[i] = reflect.TypeOf(dest[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,7 +226,7 @@ func (rows *connRows) Scan(dest ...interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rows.scanTypes[i] != reflect.TypeOf(dst) {
|
if rows.scanTypes[i] != reflect.TypeOf(dst) {
|
||||||
rows.scanPlans[i] = ci.PlanScan(fieldDescriptions[i].DataTypeOID, fieldDescriptions[i].Format, dest[i])
|
rows.scanPlans[i] = m.PlanScan(fieldDescriptions[i].DataTypeOID, fieldDescriptions[i].Format, dest[i])
|
||||||
rows.scanTypes[i] = reflect.TypeOf(dest[i])
|
rows.scanTypes[i] = reflect.TypeOf(dest[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,8 +257,8 @@ func (rows *connRows) Values() ([]interface{}, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if dt, ok := rows.connInfo.TypeForOID(fd.DataTypeOID); ok {
|
if dt, ok := rows.typeMap.TypeForOID(fd.DataTypeOID); ok {
|
||||||
value, err := dt.Codec.DecodeValue(rows.connInfo, fd.DataTypeOID, fd.Format, buf)
|
value, err := dt.Codec.DecodeValue(rows.typeMap, fd.DataTypeOID, fd.Format, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.fatal(err)
|
rows.fatal(err)
|
||||||
}
|
}
|
||||||
@@ -303,11 +303,11 @@ func (e ScanArgError) Unwrap() error {
|
|||||||
|
|
||||||
// ScanRow decodes raw row data into dest. It can be used to scan rows read from the lower level pgconn interface.
|
// ScanRow decodes raw row data into dest. It can be used to scan rows read from the lower level pgconn interface.
|
||||||
//
|
//
|
||||||
// connInfo - OID to Go type mapping.
|
// typeMap - OID to Go type mapping.
|
||||||
// fieldDescriptions - OID and format of values
|
// fieldDescriptions - OID and format of values
|
||||||
// values - the raw data as returned from the PostgreSQL server
|
// values - the raw data as returned from the PostgreSQL server
|
||||||
// dest - the destination that values will be decoded into
|
// dest - the destination that values will be decoded into
|
||||||
func ScanRow(connInfo *pgtype.ConnInfo, fieldDescriptions []pgproto3.FieldDescription, values [][]byte, dest ...interface{}) error {
|
func ScanRow(typeMap *pgtype.Map, fieldDescriptions []pgproto3.FieldDescription, values [][]byte, dest ...interface{}) error {
|
||||||
if len(fieldDescriptions) != len(values) {
|
if len(fieldDescriptions) != len(values) {
|
||||||
return fmt.Errorf("number of field descriptions must equal number of values, got %d and %d", len(fieldDescriptions), len(values))
|
return fmt.Errorf("number of field descriptions must equal number of values, got %d and %d", len(fieldDescriptions), len(values))
|
||||||
}
|
}
|
||||||
@@ -320,7 +320,7 @@ func ScanRow(connInfo *pgtype.ConnInfo, fieldDescriptions []pgproto3.FieldDescri
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err := connInfo.Scan(fieldDescriptions[i].DataTypeOID, fieldDescriptions[i].Format, values[i], d)
|
err := typeMap.Scan(fieldDescriptions[i].DataTypeOID, fieldDescriptions[i].Format, values[i], d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ScanArgError{ColumnIndex: i, Err: err}
|
return ScanArgError{ColumnIndex: i, Err: err}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -519,7 +519,7 @@ func (r *Rows) Columns() []string {
|
|||||||
|
|
||||||
// ColumnTypeDatabaseTypeName returns the database system type name. If the name is unknown the OID is returned.
|
// ColumnTypeDatabaseTypeName returns the database system type name. If the name is unknown the OID is returned.
|
||||||
func (r *Rows) ColumnTypeDatabaseTypeName(index int) string {
|
func (r *Rows) ColumnTypeDatabaseTypeName(index int) string {
|
||||||
if dt, ok := r.conn.conn.ConnInfo().TypeForOID(r.rows.FieldDescriptions()[index].DataTypeOID); ok {
|
if dt, ok := r.conn.conn.TypeMap().TypeForOID(r.rows.FieldDescriptions()[index].DataTypeOID); ok {
|
||||||
return strings.ToUpper(dt.Name)
|
return strings.ToUpper(dt.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ func (r *Rows) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Rows) Next(dest []driver.Value) error {
|
func (r *Rows) Next(dest []driver.Value) error {
|
||||||
ci := r.conn.conn.ConnInfo()
|
m := r.conn.conn.TypeMap()
|
||||||
fieldDescriptions := r.rows.FieldDescriptions()
|
fieldDescriptions := r.rows.FieldDescriptions()
|
||||||
|
|
||||||
if r.valueFuncs == nil {
|
if r.valueFuncs == nil {
|
||||||
@@ -607,21 +607,21 @@ func (r *Rows) Next(dest []driver.Value) error {
|
|||||||
switch fd.DataTypeOID {
|
switch fd.DataTypeOID {
|
||||||
case pgtype.BoolOID:
|
case pgtype.BoolOID:
|
||||||
var d bool
|
var d bool
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
return d, err
|
return d, err
|
||||||
}
|
}
|
||||||
case pgtype.ByteaOID:
|
case pgtype.ByteaOID:
|
||||||
var d []byte
|
var d []byte
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
return d, err
|
return d, err
|
||||||
}
|
}
|
||||||
case pgtype.CIDOID, pgtype.OIDOID, pgtype.XIDOID:
|
case pgtype.CIDOID, pgtype.OIDOID, pgtype.XIDOID:
|
||||||
var d pgtype.Uint32
|
var d pgtype.Uint32
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -631,7 +631,7 @@ func (r *Rows) Next(dest []driver.Value) error {
|
|||||||
}
|
}
|
||||||
case pgtype.DateOID:
|
case pgtype.DateOID:
|
||||||
var d pgtype.Date
|
var d pgtype.Date
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -641,42 +641,42 @@ func (r *Rows) Next(dest []driver.Value) error {
|
|||||||
}
|
}
|
||||||
case pgtype.Float4OID:
|
case pgtype.Float4OID:
|
||||||
var d float32
|
var d float32
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
return float64(d), err
|
return float64(d), err
|
||||||
}
|
}
|
||||||
case pgtype.Float8OID:
|
case pgtype.Float8OID:
|
||||||
var d float64
|
var d float64
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
return d, err
|
return d, err
|
||||||
}
|
}
|
||||||
case pgtype.Int2OID:
|
case pgtype.Int2OID:
|
||||||
var d int16
|
var d int16
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
return int64(d), err
|
return int64(d), err
|
||||||
}
|
}
|
||||||
case pgtype.Int4OID:
|
case pgtype.Int4OID:
|
||||||
var d int32
|
var d int32
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
return int64(d), err
|
return int64(d), err
|
||||||
}
|
}
|
||||||
case pgtype.Int8OID:
|
case pgtype.Int8OID:
|
||||||
var d int64
|
var d int64
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
return d, err
|
return d, err
|
||||||
}
|
}
|
||||||
case pgtype.JSONOID, pgtype.JSONBOID:
|
case pgtype.JSONOID, pgtype.JSONBOID:
|
||||||
var d []byte
|
var d []byte
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -686,7 +686,7 @@ func (r *Rows) Next(dest []driver.Value) error {
|
|||||||
}
|
}
|
||||||
case pgtype.TimestampOID:
|
case pgtype.TimestampOID:
|
||||||
var d pgtype.Timestamp
|
var d pgtype.Timestamp
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -696,7 +696,7 @@ func (r *Rows) Next(dest []driver.Value) error {
|
|||||||
}
|
}
|
||||||
case pgtype.TimestamptzOID:
|
case pgtype.TimestamptzOID:
|
||||||
var d pgtype.Timestamptz
|
var d pgtype.Timestamptz
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -706,7 +706,7 @@ func (r *Rows) Next(dest []driver.Value) error {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
var d string
|
var d string
|
||||||
scanPlan := ci.PlanScan(dataTypeOID, format, &d)
|
scanPlan := m.PlanScan(dataTypeOID, format, &d)
|
||||||
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
r.valueFuncs[i] = func(src []byte) (driver.Value, error) {
|
||||||
err := scanPlan.Scan(src, &d)
|
err := scanPlan.Scan(src, &d)
|
||||||
return d, err
|
return d, err
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func (e SerializationError) Error() string {
|
|||||||
return string(e)
|
return string(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertSimpleArgument(ci *pgtype.ConnInfo, arg interface{}) (interface{}, error) {
|
func convertSimpleArgument(m *pgtype.Map, arg interface{}) (interface{}, error) {
|
||||||
if arg == nil {
|
if arg == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -79,8 +79,8 @@ func convertSimpleArgument(ci *pgtype.ConnInfo, arg interface{}) (interface{}, e
|
|||||||
return int64(arg), nil
|
return int64(arg), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, found := ci.TypeForValue(arg); found {
|
if _, found := m.TypeForValue(arg); found {
|
||||||
buf, err := ci.Encode(0, TextFormatCode, arg, nil)
|
buf, err := m.Encode(0, TextFormatCode, arg, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -92,16 +92,16 @@ func convertSimpleArgument(ci *pgtype.ConnInfo, arg interface{}) (interface{}, e
|
|||||||
|
|
||||||
if refVal.Kind() == reflect.Ptr {
|
if refVal.Kind() == reflect.Ptr {
|
||||||
arg = refVal.Elem().Interface()
|
arg = refVal.Elem().Interface()
|
||||||
return convertSimpleArgument(ci, arg)
|
return convertSimpleArgument(m, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strippedArg, ok := stripNamedType(&refVal); ok {
|
if strippedArg, ok := stripNamedType(&refVal); ok {
|
||||||
return convertSimpleArgument(ci, strippedArg)
|
return convertSimpleArgument(m, strippedArg)
|
||||||
}
|
}
|
||||||
return nil, SerializationError(fmt.Sprintf("Cannot encode %T in simple protocol - %T must implement driver.Valuer, pgtype.TextEncoder, or be a native type", arg, arg))
|
return nil, SerializationError(fmt.Sprintf("Cannot encode %T in simple protocol - %T must implement driver.Valuer, pgtype.TextEncoder, or be a native type", arg, arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodePreparedStatementArgument(ci *pgtype.ConnInfo, buf []byte, oid uint32, arg interface{}) ([]byte, error) {
|
func encodePreparedStatementArgument(m *pgtype.Map, buf []byte, oid uint32, arg interface{}) ([]byte, error) {
|
||||||
if arg == nil {
|
if arg == nil {
|
||||||
return pgio.AppendInt32(buf, -1), nil
|
return pgio.AppendInt32(buf, -1), nil
|
||||||
}
|
}
|
||||||
@@ -120,13 +120,13 @@ func encodePreparedStatementArgument(ci *pgtype.ConnInfo, buf []byte, oid uint32
|
|||||||
return pgio.AppendInt32(buf, -1), nil
|
return pgio.AppendInt32(buf, -1), nil
|
||||||
}
|
}
|
||||||
arg = refVal.Elem().Interface()
|
arg = refVal.Elem().Interface()
|
||||||
return encodePreparedStatementArgument(ci, buf, oid, arg)
|
return encodePreparedStatementArgument(m, buf, oid, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := ci.TypeForOID(oid); ok {
|
if _, ok := m.TypeForOID(oid); ok {
|
||||||
sp := len(buf)
|
sp := len(buf)
|
||||||
buf = pgio.AppendInt32(buf, -1)
|
buf = pgio.AppendInt32(buf, -1)
|
||||||
argBuf, err := ci.Encode(oid, BinaryFormatCode, arg, buf)
|
argBuf, err := m.Encode(oid, BinaryFormatCode, arg, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ func encodePreparedStatementArgument(ci *pgtype.ConnInfo, buf []byte, oid uint32
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strippedArg, ok := stripNamedType(&refVal); ok {
|
if strippedArg, ok := stripNamedType(&refVal); ok {
|
||||||
return encodePreparedStatementArgument(ci, buf, oid, strippedArg)
|
return encodePreparedStatementArgument(m, buf, oid, strippedArg)
|
||||||
}
|
}
|
||||||
return nil, SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
return nil, SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
||||||
}
|
}
|
||||||
@@ -146,13 +146,13 @@ func encodePreparedStatementArgument(ci *pgtype.ConnInfo, buf []byte, oid uint32
|
|||||||
// chooseParameterFormatCode determines the correct format code for an
|
// chooseParameterFormatCode determines the correct format code for an
|
||||||
// argument to a prepared statement. It defaults to TextFormatCode if no
|
// argument to a prepared statement. It defaults to TextFormatCode if no
|
||||||
// determination can be made.
|
// determination can be made.
|
||||||
func chooseParameterFormatCode(ci *pgtype.ConnInfo, oid uint32, arg interface{}) int16 {
|
func chooseParameterFormatCode(m *pgtype.Map, oid uint32, arg interface{}) int16 {
|
||||||
switch arg.(type) {
|
switch arg.(type) {
|
||||||
case string, *string:
|
case string, *string:
|
||||||
return TextFormatCode
|
return TextFormatCode
|
||||||
}
|
}
|
||||||
|
|
||||||
return ci.FormatCodeForOID(oid)
|
return m.FormatCodeForOID(oid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func stripNamedType(val *reflect.Value) (interface{}, bool) {
|
func stripNamedType(val *reflect.Value) (interface{}, bool) {
|
||||||
|
|||||||
+2
-2
@@ -79,7 +79,7 @@ func TestJSONAndJSONBTranscode(t *testing.T) {
|
|||||||
|
|
||||||
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
|
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
|
||||||
for _, typename := range []string{"json", "jsonb"} {
|
for _, typename := range []string{"json", "jsonb"} {
|
||||||
if _, ok := conn.ConnInfo().TypeForName(typename); !ok {
|
if _, ok := conn.TypeMap().TypeForName(typename); !ok {
|
||||||
continue // No JSON/JSONB type -- must be running against old PostgreSQL
|
continue // No JSON/JSONB type -- must be running against old PostgreSQL
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ func TestJSONAndJSONBTranscodeExtendedOnly(t *testing.T) {
|
|||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
for _, typename := range []string{"json", "jsonb"} {
|
for _, typename := range []string{"json", "jsonb"} {
|
||||||
if _, ok := conn.ConnInfo().TypeForName(typename); !ok {
|
if _, ok := conn.TypeMap().TypeForName(typename); !ok {
|
||||||
continue // No JSON/JSONB type -- must be running against old PostgreSQL
|
continue // No JSON/JSONB type -- must be running against old PostgreSQL
|
||||||
}
|
}
|
||||||
testJSONSingleLevelStringMap(t, conn, typename)
|
testJSONSingleLevelStringMap(t, conn, typename)
|
||||||
|
|||||||
Reference in New Issue
Block a user