mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Rename Oid to OID
This commit is contained in:
parent
2bf3fac594
commit
214443deb7
50
conn.go
50
conn.go
@ -51,7 +51,7 @@ type Conn struct {
|
||||
Pid int32 // backend pid
|
||||
SecretKey int32 // key to use to send a cancel query message to the server
|
||||
RuntimeParams map[string]string // parameters that have been reported by the server
|
||||
PgTypes map[Oid]PgType // oids to PgTypes
|
||||
PgTypes map[OID]PgType // oids to PgTypes
|
||||
config ConnConfig // config used when establishing this connection
|
||||
TxStatus byte
|
||||
preparedStatements map[string]*PreparedStatement
|
||||
@ -75,12 +75,12 @@ type PreparedStatement struct {
|
||||
Name string
|
||||
SQL string
|
||||
FieldDescriptions []FieldDescription
|
||||
ParameterOids []Oid
|
||||
ParameterOIDs []OID
|
||||
}
|
||||
|
||||
// PrepareExOptions is an option struct that can be passed to PrepareEx
|
||||
type PrepareExOptions struct {
|
||||
ParameterOids []Oid
|
||||
ParameterOIDs []OID
|
||||
}
|
||||
|
||||
// Notification is a message received from the PostgreSQL LISTEN/NOTIFY system
|
||||
@ -145,13 +145,13 @@ func Connect(config ConnConfig) (c *Conn, err error) {
|
||||
return connect(config, nil, nil, nil)
|
||||
}
|
||||
|
||||
func connect(config ConnConfig, pgTypes map[Oid]PgType, pgsql_af_inet *byte, pgsql_af_inet6 *byte) (c *Conn, err error) {
|
||||
func connect(config ConnConfig, pgTypes map[OID]PgType, pgsql_af_inet *byte, pgsql_af_inet6 *byte) (c *Conn, err error) {
|
||||
c = new(Conn)
|
||||
|
||||
c.config = config
|
||||
|
||||
if pgTypes != nil {
|
||||
c.PgTypes = make(map[Oid]PgType, len(pgTypes))
|
||||
c.PgTypes = make(map[OID]PgType, len(pgTypes))
|
||||
for k, v := range pgTypes {
|
||||
c.PgTypes[k] = v
|
||||
}
|
||||
@ -344,10 +344,10 @@ where (
|
||||
return err
|
||||
}
|
||||
|
||||
c.PgTypes = make(map[Oid]PgType, 128)
|
||||
c.PgTypes = make(map[OID]PgType, 128)
|
||||
|
||||
for rows.Next() {
|
||||
var oid Oid
|
||||
var oid OID
|
||||
var t PgType
|
||||
|
||||
rows.Scan(&oid, &t.Name)
|
||||
@ -626,11 +626,11 @@ func (c *Conn) PrepareEx(name, sql string, opts *PrepareExOptions) (ps *Prepared
|
||||
wbuf.WriteCString(sql)
|
||||
|
||||
if opts != nil {
|
||||
if len(opts.ParameterOids) > 65535 {
|
||||
return nil, errors.New(fmt.Sprintf("Number of PrepareExOptions ParameterOids must be between 0 and 65535, received %d", len(opts.ParameterOids)))
|
||||
if len(opts.ParameterOIDs) > 65535 {
|
||||
return nil, errors.New(fmt.Sprintf("Number of PrepareExOptions ParameterOIDs must be between 0 and 65535, received %d", len(opts.ParameterOIDs)))
|
||||
}
|
||||
wbuf.WriteInt16(int16(len(opts.ParameterOids)))
|
||||
for _, oid := range opts.ParameterOids {
|
||||
wbuf.WriteInt16(int16(len(opts.ParameterOIDs)))
|
||||
for _, oid := range opts.ParameterOIDs {
|
||||
wbuf.WriteInt32(int32(oid))
|
||||
}
|
||||
} else {
|
||||
@ -667,10 +667,10 @@ func (c *Conn) PrepareEx(name, sql string, opts *PrepareExOptions) (ps *Prepared
|
||||
switch t {
|
||||
case parseComplete:
|
||||
case parameterDescription:
|
||||
ps.ParameterOids = c.rxParameterDescription(r)
|
||||
ps.ParameterOIDs = c.rxParameterDescription(r)
|
||||
|
||||
if len(ps.ParameterOids) > 65535 && softErr == nil {
|
||||
softErr = fmt.Errorf("PostgreSQL supports maximum of 65535 parameters, received %d", len(ps.ParameterOids))
|
||||
if len(ps.ParameterOIDs) > 65535 && softErr == nil {
|
||||
softErr = fmt.Errorf("PostgreSQL supports maximum of 65535 parameters, received %d", len(ps.ParameterOIDs))
|
||||
}
|
||||
case rowDescription:
|
||||
ps.FieldDescriptions = c.rxRowDescription(r)
|
||||
@ -899,8 +899,8 @@ func (c *Conn) sendSimpleQuery(sql string, args ...interface{}) error {
|
||||
}
|
||||
|
||||
func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}) (err error) {
|
||||
if len(ps.ParameterOids) != len(arguments) {
|
||||
return fmt.Errorf("Prepared statement \"%v\" requires %d parameters, but %d were provided", ps.Name, len(ps.ParameterOids), len(arguments))
|
||||
if len(ps.ParameterOIDs) != len(arguments) {
|
||||
return fmt.Errorf("Prepared statement \"%v\" requires %d parameters, but %d were provided", ps.Name, len(ps.ParameterOIDs), len(arguments))
|
||||
}
|
||||
|
||||
// bind
|
||||
@ -908,8 +908,8 @@ func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}
|
||||
wbuf.WriteByte(0)
|
||||
wbuf.WriteCString(ps.Name)
|
||||
|
||||
wbuf.WriteInt16(int16(len(ps.ParameterOids)))
|
||||
for i, oid := range ps.ParameterOids {
|
||||
wbuf.WriteInt16(int16(len(ps.ParameterOIDs)))
|
||||
for i, oid := range ps.ParameterOIDs {
|
||||
switch arg := arguments[i].(type) {
|
||||
case Encoder:
|
||||
wbuf.WriteInt16(arg.FormatCode())
|
||||
@ -917,7 +917,7 @@ func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}
|
||||
wbuf.WriteInt16(TextFormatCode)
|
||||
default:
|
||||
switch oid {
|
||||
case BoolOid, ByteaOid, Int2Oid, Int4Oid, Int8Oid, Float4Oid, Float8Oid, TimestampTzOid, TimestampTzArrayOid, TimestampOid, TimestampArrayOid, DateOid, BoolArrayOid, ByteaArrayOid, Int2ArrayOid, Int4ArrayOid, Int8ArrayOid, Float4ArrayOid, Float8ArrayOid, TextArrayOid, VarcharArrayOid, OidOid, InetOid, CidrOid, InetArrayOid, CidrArrayOid, RecordOid:
|
||||
case BoolOID, ByteaOID, Int2OID, Int4OID, Int8OID, Float4OID, Float8OID, TimestampTzOID, TimestampTzArrayOID, TimestampOID, TimestampArrayOID, DateOID, BoolArrayOID, ByteaArrayOID, Int2ArrayOID, Int4ArrayOID, Int8ArrayOID, Float4ArrayOID, Float8ArrayOID, TextArrayOID, VarcharArrayOID, OIDOID, InetOID, CidrOID, InetArrayOID, CidrArrayOID, RecordOID:
|
||||
wbuf.WriteInt16(BinaryFormatCode)
|
||||
default:
|
||||
wbuf.WriteInt16(TextFormatCode)
|
||||
@ -926,7 +926,7 @@ func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}
|
||||
}
|
||||
|
||||
wbuf.WriteInt16(int16(len(arguments)))
|
||||
for i, oid := range ps.ParameterOids {
|
||||
for i, oid := range ps.ParameterOIDs {
|
||||
if err := Encode(wbuf, oid, arguments[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1151,9 +1151,9 @@ func (c *Conn) rxRowDescription(r *msgReader) (fields []FieldDescription) {
|
||||
for i := int16(0); i < fieldCount; i++ {
|
||||
f := &fields[i]
|
||||
f.Name = r.readCString()
|
||||
f.Table = r.readOid()
|
||||
f.Table = r.readOID()
|
||||
f.AttributeNumber = r.readInt16()
|
||||
f.DataType = r.readOid()
|
||||
f.DataType = r.readOID()
|
||||
f.DataTypeSize = r.readInt16()
|
||||
f.Modifier = r.readInt32()
|
||||
f.FormatCode = r.readInt16()
|
||||
@ -1161,7 +1161,7 @@ func (c *Conn) rxRowDescription(r *msgReader) (fields []FieldDescription) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Conn) rxParameterDescription(r *msgReader) (parameters []Oid) {
|
||||
func (c *Conn) rxParameterDescription(r *msgReader) (parameters []OID) {
|
||||
// Internally, PostgreSQL supports greater than 64k parameters to a prepared
|
||||
// statement. But the parameter description uses a 16-bit integer for the
|
||||
// count of parameters. If there are more than 64K parameters, this count is
|
||||
@ -1170,10 +1170,10 @@ func (c *Conn) rxParameterDescription(r *msgReader) (parameters []Oid) {
|
||||
r.readInt16()
|
||||
parameterCount := r.msgBytesRemaining / 4
|
||||
|
||||
parameters = make([]Oid, 0, parameterCount)
|
||||
parameters = make([]OID, 0, parameterCount)
|
||||
|
||||
for i := int32(0); i < parameterCount; i++ {
|
||||
parameters = append(parameters, r.readOid())
|
||||
parameters = append(parameters, r.readOID())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ type ConnPool struct {
|
||||
closed bool
|
||||
preparedStatements map[string]*PreparedStatement
|
||||
acquireTimeout time.Duration
|
||||
pgTypes map[Oid]PgType
|
||||
pgTypes map[OID]PgType
|
||||
pgsql_af_inet *byte
|
||||
pgsql_af_inet6 *byte
|
||||
}
|
||||
|
@ -987,7 +987,7 @@ func TestPrepareEx(t *testing.T) {
|
||||
conn := mustConnect(t, *defaultConnConfig)
|
||||
defer closeConn(t, conn)
|
||||
|
||||
_, err := conn.PrepareEx("test", "select $1", &pgx.PrepareExOptions{ParameterOids: []pgx.Oid{pgx.TextOid}})
|
||||
_, err := conn.PrepareEx("test", "select $1", &pgx.PrepareExOptions{ParameterOIDs: []pgx.OID{pgx.TextOID}})
|
||||
if err != nil {
|
||||
t.Errorf("Unable to prepare statement: %v", err)
|
||||
return
|
||||
|
@ -57,7 +57,7 @@ func (p *NullPoint) Scan(vr *pgx.ValueReader) error {
|
||||
|
||||
func (p NullPoint) FormatCode() int16 { return pgx.BinaryFormatCode }
|
||||
|
||||
func (p NullPoint) Encode(w *pgx.WriteBuf, oid pgx.Oid) error {
|
||||
func (p NullPoint) Encode(w *pgx.WriteBuf, oid pgx.OID) error {
|
||||
if !p.Valid {
|
||||
w.WriteInt32(-1)
|
||||
return nil
|
||||
|
@ -12,7 +12,7 @@ func Example_JSON() {
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := conn.PgTypes[pgx.JsonOid]; !ok {
|
||||
if _, ok := conn.PgTypes[pgx.JsonOID]; !ok {
|
||||
// No JSON type -- must be running against very old PostgreSQL
|
||||
// Pretend it works
|
||||
fmt.Println("John", 42)
|
||||
|
12
fastpath.go
12
fastpath.go
@ -7,26 +7,26 @@ import (
|
||||
type fastpathArg []byte
|
||||
|
||||
func newFastpath(cn *Conn) *fastpath {
|
||||
return &fastpath{cn: cn, fns: make(map[string]Oid)}
|
||||
return &fastpath{cn: cn, fns: make(map[string]OID)}
|
||||
}
|
||||
|
||||
type fastpath struct {
|
||||
cn *Conn
|
||||
fns map[string]Oid
|
||||
fns map[string]OID
|
||||
}
|
||||
|
||||
func (f *fastpath) functionOID(name string) Oid {
|
||||
func (f *fastpath) functionOID(name string) OID {
|
||||
return f.fns[name]
|
||||
}
|
||||
|
||||
func (f *fastpath) addFunction(name string, oid Oid) {
|
||||
func (f *fastpath) addFunction(name string, oid OID) {
|
||||
f.fns[name] = oid
|
||||
}
|
||||
|
||||
func (f *fastpath) addFunctions(rows *Rows) error {
|
||||
for rows.Next() {
|
||||
var name string
|
||||
var oid Oid
|
||||
var oid OID
|
||||
if err := rows.Scan(&name, &oid); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -49,7 +49,7 @@ func fpInt64Arg(n int64) fpArg {
|
||||
return res
|
||||
}
|
||||
|
||||
func (f *fastpath) Call(oid Oid, args []fpArg) (res []byte, err error) {
|
||||
func (f *fastpath) Call(oid OID, args []fpArg) (res []byte, err error) {
|
||||
wbuf := newWriteBuf(f.cn, 'F') // function call
|
||||
wbuf.WriteInt32(int32(oid)) // function object id
|
||||
wbuf.WriteInt16(1) // # of argument format codes
|
||||
|
@ -14,20 +14,20 @@ type LargeObjects struct {
|
||||
fp *fastpath
|
||||
}
|
||||
|
||||
const largeObjectFns = `select proname, oid from pg_catalog.pg_proc
|
||||
const largeObjectFns = `select proname, oid from pg_catalog.pg_proc
|
||||
where proname in (
|
||||
'lo_open',
|
||||
'lo_close',
|
||||
'lo_create',
|
||||
'lo_unlink',
|
||||
'lo_lseek',
|
||||
'lo_lseek64',
|
||||
'lo_tell',
|
||||
'lo_tell64',
|
||||
'lo_truncate',
|
||||
'lo_truncate64',
|
||||
'loread',
|
||||
'lowrite')
|
||||
'lo_open',
|
||||
'lo_close',
|
||||
'lo_create',
|
||||
'lo_unlink',
|
||||
'lo_lseek',
|
||||
'lo_lseek64',
|
||||
'lo_tell',
|
||||
'lo_tell64',
|
||||
'lo_truncate',
|
||||
'lo_truncate64',
|
||||
'loread',
|
||||
'lowrite')
|
||||
and pronamespace = (select oid from pg_catalog.pg_namespace where nspname = 'pg_catalog')`
|
||||
|
||||
// LargeObjects returns a LargeObjects instance for the transaction.
|
||||
@ -60,19 +60,19 @@ const (
|
||||
|
||||
// Create creates a new large object. If id is zero, the server assigns an
|
||||
// unused OID.
|
||||
func (o *LargeObjects) Create(id Oid) (Oid, error) {
|
||||
newOid, err := fpInt32(o.fp.CallFn("lo_create", []fpArg{fpIntArg(int32(id))}))
|
||||
return Oid(newOid), err
|
||||
func (o *LargeObjects) Create(id OID) (OID, error) {
|
||||
newOID, err := fpInt32(o.fp.CallFn("lo_create", []fpArg{fpIntArg(int32(id))}))
|
||||
return OID(newOID), err
|
||||
}
|
||||
|
||||
// Open opens an existing large object with the given mode.
|
||||
func (o *LargeObjects) Open(oid Oid, mode LargeObjectMode) (*LargeObject, error) {
|
||||
func (o *LargeObjects) Open(oid OID, mode LargeObjectMode) (*LargeObject, error) {
|
||||
fd, err := fpInt32(o.fp.CallFn("lo_open", []fpArg{fpIntArg(int32(oid)), fpIntArg(int32(mode))}))
|
||||
return &LargeObject{fd: fd, lo: o}, err
|
||||
}
|
||||
|
||||
// Unlink removes a large object from the database.
|
||||
func (o *LargeObjects) Unlink(oid Oid) error {
|
||||
func (o *LargeObjects) Unlink(oid OID) error {
|
||||
_, err := o.fp.CallFn("lo_unlink", []fpArg{fpIntArg(int32(oid))})
|
||||
return err
|
||||
}
|
||||
|
@ -49,13 +49,13 @@ func (self *startupMessage) Bytes() (buf []byte) {
|
||||
return buf
|
||||
}
|
||||
|
||||
type Oid int32
|
||||
type OID int32
|
||||
|
||||
type FieldDescription struct {
|
||||
Name string
|
||||
Table Oid
|
||||
Table OID
|
||||
AttributeNumber int16
|
||||
DataType Oid
|
||||
DataType OID
|
||||
DataTypeSize int16
|
||||
DataTypeName string
|
||||
Modifier int32
|
||||
|
@ -158,8 +158,8 @@ func (r *msgReader) readInt64() int64 {
|
||||
return n
|
||||
}
|
||||
|
||||
func (r *msgReader) readOid() Oid {
|
||||
return Oid(r.readInt32())
|
||||
func (r *msgReader) readOID() OID {
|
||||
return OID(r.readInt32())
|
||||
}
|
||||
|
||||
// readCString reads a null terminated string
|
||||
|
76
query.go
76
query.go
@ -250,7 +250,7 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
|
||||
if b, ok := d.(*[]byte); ok {
|
||||
// If it actually is a bytea then pass it through decodeBytea (so it can be decoded if it is in text format)
|
||||
// Otherwise read the bytes directly regardless of what the actual type is.
|
||||
if vr.Type().DataType == ByteaOid {
|
||||
if vr.Type().DataType == ByteaOID {
|
||||
*b = decodeBytea(vr)
|
||||
} else {
|
||||
if vr.Len() != -1 {
|
||||
@ -268,27 +268,27 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
|
||||
var val interface{}
|
||||
if 0 <= vr.Len() {
|
||||
switch vr.Type().DataType {
|
||||
case BoolOid:
|
||||
case BoolOID:
|
||||
val = decodeBool(vr)
|
||||
case Int8Oid:
|
||||
case Int8OID:
|
||||
val = int64(decodeInt8(vr))
|
||||
case Int2Oid:
|
||||
case Int2OID:
|
||||
val = int64(decodeInt2(vr))
|
||||
case Int4Oid:
|
||||
case Int4OID:
|
||||
val = int64(decodeInt4(vr))
|
||||
case TextOid, VarcharOid:
|
||||
case TextOID, VarcharOID:
|
||||
val = decodeText(vr)
|
||||
case OidOid:
|
||||
val = int64(decodeOid(vr))
|
||||
case Float4Oid:
|
||||
case OIDOID:
|
||||
val = int64(decodeOID(vr))
|
||||
case Float4OID:
|
||||
val = float64(decodeFloat4(vr))
|
||||
case Float8Oid:
|
||||
case Float8OID:
|
||||
val = decodeFloat8(vr)
|
||||
case DateOid:
|
||||
case DateOID:
|
||||
val = decodeDate(vr)
|
||||
case TimestampOid:
|
||||
case TimestampOID:
|
||||
val = decodeTimestamp(vr)
|
||||
case TimestampTzOid:
|
||||
case TimestampTzOID:
|
||||
val = decodeTimestampTz(vr)
|
||||
default:
|
||||
val = vr.ReadBytes(vr.Len())
|
||||
@ -298,7 +298,7 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
|
||||
if err != nil {
|
||||
rows.Fatal(scanArgError{col: i, err: err})
|
||||
}
|
||||
} else if vr.Type().DataType == JsonOid || vr.Type().DataType == JsonbOid {
|
||||
} else if vr.Type().DataType == JsonOID || vr.Type().DataType == JsonbOID {
|
||||
// Because the argument passed to decodeJSON will escape the heap.
|
||||
// This allows d to be stack allocated and only copied to the heap when
|
||||
// we actually are decoding JSON. This saves one memory allocation per
|
||||
@ -345,53 +345,53 @@ func (rows *Rows) Values() ([]interface{}, error) {
|
||||
values = append(values, vr.ReadString(vr.Len()))
|
||||
case BinaryFormatCode:
|
||||
switch vr.Type().DataType {
|
||||
case TextOid, VarcharOid:
|
||||
case TextOID, VarcharOID:
|
||||
values = append(values, decodeText(vr))
|
||||
case BoolOid:
|
||||
case BoolOID:
|
||||
values = append(values, decodeBool(vr))
|
||||
case ByteaOid:
|
||||
case ByteaOID:
|
||||
values = append(values, decodeBytea(vr))
|
||||
case Int8Oid:
|
||||
case Int8OID:
|
||||
values = append(values, decodeInt8(vr))
|
||||
case Int2Oid:
|
||||
case Int2OID:
|
||||
values = append(values, decodeInt2(vr))
|
||||
case Int4Oid:
|
||||
case Int4OID:
|
||||
values = append(values, decodeInt4(vr))
|
||||
case OidOid:
|
||||
values = append(values, decodeOid(vr))
|
||||
case Float4Oid:
|
||||
case OIDOID:
|
||||
values = append(values, decodeOID(vr))
|
||||
case Float4OID:
|
||||
values = append(values, decodeFloat4(vr))
|
||||
case Float8Oid:
|
||||
case Float8OID:
|
||||
values = append(values, decodeFloat8(vr))
|
||||
case BoolArrayOid:
|
||||
case BoolArrayOID:
|
||||
values = append(values, decodeBoolArray(vr))
|
||||
case Int2ArrayOid:
|
||||
case Int2ArrayOID:
|
||||
values = append(values, decodeInt2Array(vr))
|
||||
case Int4ArrayOid:
|
||||
case Int4ArrayOID:
|
||||
values = append(values, decodeInt4Array(vr))
|
||||
case Int8ArrayOid:
|
||||
case Int8ArrayOID:
|
||||
values = append(values, decodeInt8Array(vr))
|
||||
case Float4ArrayOid:
|
||||
case Float4ArrayOID:
|
||||
values = append(values, decodeFloat4Array(vr))
|
||||
case Float8ArrayOid:
|
||||
case Float8ArrayOID:
|
||||
values = append(values, decodeFloat8Array(vr))
|
||||
case TextArrayOid, VarcharArrayOid:
|
||||
case TextArrayOID, VarcharArrayOID:
|
||||
values = append(values, decodeTextArray(vr))
|
||||
case TimestampArrayOid, TimestampTzArrayOid:
|
||||
case TimestampArrayOID, TimestampTzArrayOID:
|
||||
values = append(values, decodeTimestampArray(vr))
|
||||
case DateOid:
|
||||
case DateOID:
|
||||
values = append(values, decodeDate(vr))
|
||||
case TimestampTzOid:
|
||||
case TimestampTzOID:
|
||||
values = append(values, decodeTimestampTz(vr))
|
||||
case TimestampOid:
|
||||
case TimestampOID:
|
||||
values = append(values, decodeTimestamp(vr))
|
||||
case InetOid, CidrOid:
|
||||
case InetOID, CidrOID:
|
||||
values = append(values, decodeInet(vr))
|
||||
case JsonOid:
|
||||
case JsonOID:
|
||||
var d interface{}
|
||||
decodeJSON(vr, &d)
|
||||
values = append(values, d)
|
||||
case JsonbOid:
|
||||
case JsonbOID:
|
||||
var d interface{}
|
||||
decodeJSON(vr, &d)
|
||||
values = append(values, d)
|
||||
|
@ -83,7 +83,7 @@ func TestConnQueryValues(t *testing.T) {
|
||||
t.Errorf(`Expected values[3] to be %v, but it was %d`, nil, values[3])
|
||||
}
|
||||
|
||||
if values[4] != pgx.Oid(rowCount) {
|
||||
if values[4] != pgx.OID(rowCount) {
|
||||
t.Errorf(`Expected values[4] to be %d, but it was %d`, rowCount, values[4])
|
||||
}
|
||||
}
|
||||
@ -385,7 +385,7 @@ type coreEncoder struct{}
|
||||
|
||||
func (n coreEncoder) FormatCode() int16 { return pgx.TextFormatCode }
|
||||
|
||||
func (n *coreEncoder) Encode(w *pgx.WriteBuf, oid pgx.Oid) error {
|
||||
func (n *coreEncoder) Encode(w *pgx.WriteBuf, oid pgx.OID) error {
|
||||
w.WriteInt32(int32(2))
|
||||
w.WriteBytes([]byte("42"))
|
||||
return nil
|
||||
@ -420,7 +420,7 @@ func TestQueryRowCoreTypes(t *testing.T) {
|
||||
f64 float64
|
||||
b bool
|
||||
t time.Time
|
||||
oid pgx.Oid
|
||||
oid pgx.OID
|
||||
}
|
||||
|
||||
var actual, zero allTypes
|
||||
@ -438,7 +438,7 @@ func TestQueryRowCoreTypes(t *testing.T) {
|
||||
{"select $1::timestamptz", []interface{}{time.Unix(123, 5000)}, []interface{}{&actual.t}, allTypes{t: time.Unix(123, 5000)}},
|
||||
{"select $1::timestamp", []interface{}{time.Date(2010, 1, 2, 3, 4, 5, 0, time.Local)}, []interface{}{&actual.t}, allTypes{t: time.Date(2010, 1, 2, 3, 4, 5, 0, time.Local)}},
|
||||
{"select $1::date", []interface{}{time.Date(1987, 1, 2, 0, 0, 0, 0, time.Local)}, []interface{}{&actual.t}, allTypes{t: time.Date(1987, 1, 2, 0, 0, 0, 0, time.Local)}},
|
||||
{"select $1::oid", []interface{}{pgx.Oid(42)}, []interface{}{&actual.oid}, allTypes{oid: 42}},
|
||||
{"select $1::oid", []interface{}{pgx.OID(42)}, []interface{}{&actual.oid}, allTypes{oid: 42}},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
|
@ -57,23 +57,23 @@ var openFromConnPoolCount int
|
||||
|
||||
// oids that map to intrinsic database/sql types. These will be allowed to be
|
||||
// binary, anything else will be forced to text format
|
||||
var databaseSqlOids map[pgx.Oid]bool
|
||||
var databaseSqlOIDs map[pgx.OID]bool
|
||||
|
||||
func init() {
|
||||
d := &Driver{}
|
||||
sql.Register("pgx", d)
|
||||
|
||||
databaseSqlOids = make(map[pgx.Oid]bool)
|
||||
databaseSqlOids[pgx.BoolOid] = true
|
||||
databaseSqlOids[pgx.ByteaOid] = true
|
||||
databaseSqlOids[pgx.Int2Oid] = true
|
||||
databaseSqlOids[pgx.Int4Oid] = true
|
||||
databaseSqlOids[pgx.Int8Oid] = true
|
||||
databaseSqlOids[pgx.Float4Oid] = true
|
||||
databaseSqlOids[pgx.Float8Oid] = true
|
||||
databaseSqlOids[pgx.DateOid] = true
|
||||
databaseSqlOids[pgx.TimestampTzOid] = true
|
||||
databaseSqlOids[pgx.TimestampOid] = true
|
||||
databaseSqlOIDs = make(map[pgx.OID]bool)
|
||||
databaseSqlOIDs[pgx.BoolOID] = true
|
||||
databaseSqlOIDs[pgx.ByteaOID] = true
|
||||
databaseSqlOIDs[pgx.Int2OID] = true
|
||||
databaseSqlOIDs[pgx.Int4OID] = true
|
||||
databaseSqlOIDs[pgx.Int8OID] = true
|
||||
databaseSqlOIDs[pgx.Float4OID] = true
|
||||
databaseSqlOIDs[pgx.Float8OID] = true
|
||||
databaseSqlOIDs[pgx.DateOID] = true
|
||||
databaseSqlOIDs[pgx.TimestampTzOID] = true
|
||||
databaseSqlOIDs[pgx.TimestampOID] = true
|
||||
}
|
||||
|
||||
type Driver struct {
|
||||
@ -231,7 +231,7 @@ func (c *Conn) queryPrepared(name string, argsV []driver.Value) (driver.Rows, er
|
||||
// (e.g. []int32)
|
||||
func restrictBinaryToDatabaseSqlTypes(ps *pgx.PreparedStatement) {
|
||||
for i, _ := range ps.FieldDescriptions {
|
||||
intrinsic, _ := databaseSqlOids[ps.FieldDescriptions[i].DataType]
|
||||
intrinsic, _ := databaseSqlOIDs[ps.FieldDescriptions[i].DataType]
|
||||
if !intrinsic {
|
||||
ps.FieldDescriptions[i].FormatCode = pgx.TextFormatCode
|
||||
}
|
||||
@ -248,7 +248,7 @@ func (s *Stmt) Close() error {
|
||||
}
|
||||
|
||||
func (s *Stmt) NumInput() int {
|
||||
return len(s.ps.ParameterOids)
|
||||
return len(s.ps.ParameterOIDs)
|
||||
}
|
||||
|
||||
func (s *Stmt) Exec(argsV []driver.Value) (driver.Result, error) {
|
||||
|
3
v3.md
Normal file
3
v3.md
Normal file
@ -0,0 +1,3 @@
|
||||
# V3 Changes
|
||||
|
||||
Rename Oid to OID in accordance with Go conventions.
|
@ -88,8 +88,8 @@ func (r *ValueReader) ReadInt64() int64 {
|
||||
return r.mr.readInt64()
|
||||
}
|
||||
|
||||
func (r *ValueReader) ReadOid() Oid {
|
||||
return Oid(r.ReadInt32())
|
||||
func (r *ValueReader) ReadOID() OID {
|
||||
return OID(r.ReadInt32())
|
||||
}
|
||||
|
||||
// ReadString reads count bytes and returns as string
|
||||
|
@ -84,7 +84,7 @@ func TestJsonAndJsonbTranscode(t *testing.T) {
|
||||
conn := mustConnect(t, *defaultConnConfig)
|
||||
defer closeConn(t, conn)
|
||||
|
||||
for _, oid := range []pgx.Oid{pgx.JsonOid, pgx.JsonbOid} {
|
||||
for _, oid := range []pgx.OID{pgx.JsonOID, pgx.JsonbOID} {
|
||||
if _, ok := conn.PgTypes[oid]; !ok {
|
||||
return // No JSON/JSONB type -- must be running against old PostgreSQL
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user