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