2
0

Name PG types as words

Though this doesn't follow Go naming conventions exactly it makes names more
consistent with PostgreSQL and it is easier to read. For example, TIDOID becomes
TidOid. In addition this is one less breaking change in the move to V3.
This commit is contained in:
Jack Christensen
2017-03-11 17:03:23 -06:00
parent 3dc509df94
commit 743b98b298
51 changed files with 689 additions and 694 deletions
+63 -63
View File
@@ -77,7 +77,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
@@ -102,7 +102,7 @@ type Conn struct {
doneChan chan struct{}
closedChan chan error
oidPgtypeValues map[OID]pgtype.Value
oidPgtypeValues map[Oid]pgtype.Value
}
// PreparedStatement is a description of a prepared statement
@@ -110,12 +110,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
@@ -180,13 +180,13 @@ func Connect(config ConnConfig) (c *Conn, err error) {
return connect(config, nil)
}
func connect(config ConnConfig, pgTypes map[OID]PgType) (c *Conn, err error) {
func connect(config ConnConfig, pgTypes map[Oid]PgType) (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
}
@@ -267,43 +267,43 @@ func (c *Conn) connect(config ConnConfig, network, address string, tlsConfig *tl
c.doneChan = make(chan struct{})
c.closedChan = make(chan error)
c.oidPgtypeValues = map[OID]pgtype.Value{
ACLItemArrayOID: &pgtype.ACLItemArray{},
ACLItemOID: &pgtype.ACLItem{},
BoolArrayOID: &pgtype.BoolArray{},
BoolOID: &pgtype.Bool{},
ByteaArrayOID: &pgtype.ByteaArray{},
ByteaOID: &pgtype.Bytea{},
CharOID: &pgtype.QChar{},
CIDOID: &pgtype.CID{},
CidrArrayOID: &pgtype.CidrArray{},
CidrOID: &pgtype.Inet{},
DateArrayOID: &pgtype.DateArray{},
DateOID: &pgtype.Date{},
Float4ArrayOID: &pgtype.Float4Array{},
Float4OID: &pgtype.Float4{},
Float8ArrayOID: &pgtype.Float8Array{},
Float8OID: &pgtype.Float8{},
InetArrayOID: &pgtype.InetArray{},
InetOID: &pgtype.Inet{},
Int2ArrayOID: &pgtype.Int2Array{},
Int2OID: &pgtype.Int2{},
Int4ArrayOID: &pgtype.Int4Array{},
Int4OID: &pgtype.Int4{},
Int8ArrayOID: &pgtype.Int8Array{},
Int8OID: &pgtype.Int8{},
NameOID: &pgtype.Name{},
OIDOID: &pgtype.OID{},
TextArrayOID: &pgtype.TextArray{},
TextOID: &pgtype.Text{},
TIDOID: &pgtype.TID{},
TimestampArrayOID: &pgtype.TimestampArray{},
TimestampOID: &pgtype.Timestamp{},
TimestampTzArrayOID: &pgtype.TimestamptzArray{},
TimestampTzOID: &pgtype.Timestamptz{},
VarcharArrayOID: &pgtype.VarcharArray{},
VarcharOID: &pgtype.Text{},
XIDOID: &pgtype.XID{},
c.oidPgtypeValues = map[Oid]pgtype.Value{
AclitemArrayOid: &pgtype.AclitemArray{},
AclitemOid: &pgtype.Aclitem{},
BoolArrayOid: &pgtype.BoolArray{},
BoolOid: &pgtype.Bool{},
ByteaArrayOid: &pgtype.ByteaArray{},
ByteaOid: &pgtype.Bytea{},
CharOid: &pgtype.QChar{},
CidOid: &pgtype.Cid{},
CidrArrayOid: &pgtype.CidrArray{},
CidrOid: &pgtype.Inet{},
DateArrayOid: &pgtype.DateArray{},
DateOid: &pgtype.Date{},
Float4ArrayOid: &pgtype.Float4Array{},
Float4Oid: &pgtype.Float4{},
Float8ArrayOid: &pgtype.Float8Array{},
Float8Oid: &pgtype.Float8{},
InetArrayOid: &pgtype.InetArray{},
InetOid: &pgtype.Inet{},
Int2ArrayOid: &pgtype.Int2Array{},
Int2Oid: &pgtype.Int2{},
Int4ArrayOid: &pgtype.Int4Array{},
Int4Oid: &pgtype.Int4{},
Int8ArrayOid: &pgtype.Int8Array{},
Int8Oid: &pgtype.Int8{},
NameOid: &pgtype.Name{},
OidOid: &pgtype.Oid{},
TextArrayOid: &pgtype.TextArray{},
TextOid: &pgtype.Text{},
TidOid: &pgtype.Tid{},
TimestampArrayOid: &pgtype.TimestampArray{},
TimestampOid: &pgtype.Timestamp{},
TimestampTzArrayOid: &pgtype.TimestamptzArray{},
TimestampTzOid: &pgtype.Timestamptz{},
VarcharArrayOid: &pgtype.VarcharArray{},
VarcharOid: &pgtype.Text{},
XidOid: &pgtype.Xid{},
}
if tlsConfig != nil {
@@ -397,7 +397,7 @@ where (
return err
}
c.PgTypes = make(map[OID]PgType, 128)
c.PgTypes = make(map[Oid]PgType, 128)
for rows.Next() {
var oid uint32
@@ -408,7 +408,7 @@ where (
// The zero value is text format so we ignore any types without a default type format
t.DefaultFormat, _ = DefaultTypeFormats[t.Name]
c.PgTypes[OID(oid)] = t
c.PgTypes[Oid(oid)] = t
}
return rows.Err()
@@ -669,7 +669,7 @@ func (c *Conn) Prepare(name, sql string) (ps *PreparedStatement, err error) {
// PrepareEx creates a prepared statement with name and sql. sql can contain placeholders
// for bound parameters. These placeholders are referenced positional as $1, $2, etc.
// It defers from Prepare as it allows additional options (such as parameter OIDs) to be passed via struct
// It defers from Prepare as it allows additional options (such as parameter Oids) to be passed via struct
//
// PrepareEx is idempotent; i.e. it is safe to call PrepareEx multiple times with the same
// name and sql arguments. This allows a code path to PrepareEx and Query/Exec without
@@ -719,11 +719,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, fmt.Errorf("Number of PrepareExOptions ParameterOIDs must be between 0 and 65535, received %d", len(opts.ParameterOIDs))
if len(opts.ParameterOids) > 65535 {
return nil, fmt.Errorf("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 {
@@ -760,10 +760,10 @@ func (c *Conn) prepareEx(name, sql string, opts *PrepareExOptions) (ps *Prepared
switch t {
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)
@@ -970,8 +970,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))
}
if err := c.ensureConnectionReadyForQuery(); err != nil {
@@ -983,8 +983,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())
@@ -1000,7 +1000,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
}
@@ -1188,9 +1188,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 = OID(r.readUint32())
f.Table = Oid(r.readUint32())
f.AttributeNumber = r.readInt16()
f.DataType = OID(r.readUint32())
f.DataType = Oid(r.readUint32())
f.DataTypeSize = r.readInt16()
f.Modifier = r.readInt32()
f.FormatCode = r.readInt16()
@@ -1198,7 +1198,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
@@ -1207,10 +1207,10 @@ func (c *Conn) rxParameterDescription(r *msgReader) (parameters []OID) {
r.readInt16()
parameterCount := len(r.msgBody[r.rp:]) / 4
parameters = make([]OID, 0, parameterCount)
parameters = make([]Oid, 0, parameterCount)
for i := 0; i < parameterCount; i++ {
parameters = append(parameters, OID(r.readUint32()))
parameters = append(parameters, Oid(r.readUint32()))
}
return
}
+2 -2
View File
@@ -28,7 +28,7 @@ type ConnPool struct {
closed bool
preparedStatements map[string]*PreparedStatement
acquireTimeout time.Duration
pgTypes map[OID]PgType
pgTypes map[Oid]PgType
txAfterClose func(tx *Tx)
rowsAfterClose func(rows *Rows)
}
@@ -446,7 +446,7 @@ func (p *ConnPool) Prepare(name, sql string) (*PreparedStatement, error) {
//
// PrepareEx creates a prepared statement with name and sql. sql can contain placeholders
// for bound parameters. These placeholders are referenced positional as $1, $2, etc.
// It defers from Prepare as it allows additional options (such as parameter OIDs) to be passed via struct
// It defers from Prepare as it allows additional options (such as parameter Oids) to be passed via struct
//
// PrepareEx is idempotent; i.e. it is safe to call PrepareEx multiple times with the same
// name and sql arguments. This allows a code path to PrepareEx and Query/Exec/Prepare without
+1 -1
View File
@@ -1042,7 +1042,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
+1 -1
View File
@@ -125,7 +125,7 @@ func TestConnCopyToJSON(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
}
+3 -3
View File
@@ -169,10 +169,10 @@ there.
pgx.DefaultTypeFormats["point"] = pgx.BinaryFormatCode
Note that the type is referred to by name, not by OID. This is because custom
PostgreSQL types like hstore will have different OIDs on different servers. When
Note that the type is referred to by name, not by Oid. This is because custom
PostgreSQL types like hstore will have different Oids on different servers. When
pgx establishes a connection it queries the pg_type table for all types. It then
matches the names in DefaultTypeFormats with the returned OIDs and stores it in
matches the names in DefaultTypeFormats with the returned Oids and stores it in
Conn.PgTypes.
See example_custom_type_test.go for an example of a custom type for the
+4 -3
View File
@@ -3,9 +3,10 @@ package pgx_test
import (
"errors"
"fmt"
"github.com/jackc/pgx"
"regexp"
"strconv"
"github.com/jackc/pgx"
)
var pointRegexp *regexp.Regexp = regexp.MustCompile(`^\((.*),(.*)\)$`)
@@ -20,7 +21,7 @@ type NullPoint struct {
func (p *NullPoint) ScanPgx(vr *pgx.ValueReader) error {
if vr.Type().DataTypeName != "point" {
return pgx.SerializationError(fmt.Sprintf("NullPoint.Scan cannot decode %s (OID %d)", vr.Type().DataTypeName, vr.Type().DataType))
return pgx.SerializationError(fmt.Sprintf("NullPoint.Scan cannot decode %s (Oid %d)", vr.Type().DataTypeName, vr.Type().DataType))
}
if vr.Len() == -1 {
@@ -57,7 +58,7 @@ func (p *NullPoint) ScanPgx(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
+7 -7
View File
@@ -5,26 +5,26 @@ import (
)
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
}
@@ -47,7 +47,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) {
if err := f.cn.ensureConnectionReadyForQuery(); err != nil {
return nil, err
}
@@ -93,7 +93,7 @@ func (f *fastpath) Call(oid OID, args []fpArg) (res []byte, err error) {
}
func (f *fastpath) CallFn(fn string, args []fpArg) ([]byte, error) {
return f.Call(f.functionOID(fn), args)
return f.Call(f.functionOid(fn), args)
}
func fpInt32(data []byte, err error) (int32, error) {
+6 -6
View File
@@ -59,20 +59,20 @@ 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
// 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
}
// 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
}
+2 -2
View File
@@ -55,9 +55,9 @@ func (s *startupMessage) Bytes() (buf []byte) {
type FieldDescription struct {
Name string
Table OID
Table Oid
AttributeNumber int16
DataType OID
DataType Oid
DataTypeSize int16
DataTypeName string
Modifier int32
+13 -13
View File
@@ -6,7 +6,7 @@ import (
"reflect"
)
// ACLItem is used for PostgreSQL's aclitem data type. A sample aclitem
// Aclitem is used for PostgreSQL's aclitem data type. A sample aclitem
// might look like this:
//
// postgres=arwdDxt/postgres
@@ -18,34 +18,34 @@ import (
//
// postgres=arwdDxt/"role with spaces"
//
type ACLItem struct {
type Aclitem struct {
String string
Status Status
}
func (dst *ACLItem) ConvertFrom(src interface{}) error {
func (dst *Aclitem) ConvertFrom(src interface{}) error {
switch value := src.(type) {
case ACLItem:
case Aclitem:
*dst = value
case string:
*dst = ACLItem{String: value, Status: Present}
*dst = Aclitem{String: value, Status: Present}
case *string:
if value == nil {
*dst = ACLItem{Status: Null}
*dst = Aclitem{Status: Null}
} else {
*dst = ACLItem{String: *value, Status: Present}
*dst = Aclitem{String: *value, Status: Present}
}
default:
if originalSrc, ok := underlyingStringType(src); ok {
return dst.ConvertFrom(originalSrc)
}
return fmt.Errorf("cannot convert %v to ACLItem", value)
return fmt.Errorf("cannot convert %v to Aclitem", value)
}
return nil
}
func (src *ACLItem) AssignTo(dst interface{}) error {
func (src *Aclitem) AssignTo(dst interface{}) error {
switch v := dst.(type) {
case *string:
if src.Status != Present {
@@ -81,17 +81,17 @@ func (src *ACLItem) AssignTo(dst interface{}) error {
return nil
}
func (dst *ACLItem) DecodeText(src []byte) error {
func (dst *Aclitem) DecodeText(src []byte) error {
if src == nil {
*dst = ACLItem{Status: Null}
*dst = Aclitem{Status: Null}
return nil
}
*dst = ACLItem{String: string(src), Status: Present}
*dst = Aclitem{String: string(src), Status: Present}
return nil
}
func (src ACLItem) EncodeText(w io.Writer) (bool, error) {
func (src Aclitem) EncodeText(w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
+17 -17
View File
@@ -8,30 +8,30 @@ import (
"github.com/jackc/pgx/pgio"
)
type ACLItemArray struct {
Elements []ACLItem
type AclitemArray struct {
Elements []Aclitem
Dimensions []ArrayDimension
Status Status
}
func (dst *ACLItemArray) ConvertFrom(src interface{}) error {
func (dst *AclitemArray) ConvertFrom(src interface{}) error {
switch value := src.(type) {
case ACLItemArray:
case AclitemArray:
*dst = value
case []string:
if value == nil {
*dst = ACLItemArray{Status: Null}
*dst = AclitemArray{Status: Null}
} else if len(value) == 0 {
*dst = ACLItemArray{Status: Present}
*dst = AclitemArray{Status: Present}
} else {
elements := make([]ACLItem, len(value))
elements := make([]Aclitem, len(value))
for i := range value {
if err := elements[i].ConvertFrom(value[i]); err != nil {
return err
}
}
*dst = ACLItemArray{
*dst = AclitemArray{
Elements: elements,
Dimensions: []ArrayDimension{{Length: int32(len(elements)), LowerBound: 1}},
Status: Present,
@@ -42,13 +42,13 @@ func (dst *ACLItemArray) ConvertFrom(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.ConvertFrom(originalSrc)
}
return fmt.Errorf("cannot convert %v to ACLItem", value)
return fmt.Errorf("cannot convert %v to Aclitem", value)
}
return nil
}
func (src *ACLItemArray) AssignTo(dst interface{}) error {
func (src *AclitemArray) AssignTo(dst interface{}) error {
switch v := dst.(type) {
case *[]string:
@@ -73,9 +73,9 @@ func (src *ACLItemArray) AssignTo(dst interface{}) error {
return nil
}
func (dst *ACLItemArray) DecodeText(src []byte) error {
func (dst *AclitemArray) DecodeText(src []byte) error {
if src == nil {
*dst = ACLItemArray{Status: Null}
*dst = AclitemArray{Status: Null}
return nil
}
@@ -84,13 +84,13 @@ func (dst *ACLItemArray) DecodeText(src []byte) error {
return err
}
var elements []ACLItem
var elements []Aclitem
if len(uta.Elements) > 0 {
elements = make([]ACLItem, len(uta.Elements))
elements = make([]Aclitem, len(uta.Elements))
for i, s := range uta.Elements {
var elem ACLItem
var elem Aclitem
var elemSrc []byte
if s != "NULL" {
elemSrc = []byte(s)
@@ -104,12 +104,12 @@ func (dst *ACLItemArray) DecodeText(src []byte) error {
}
}
*dst = ACLItemArray{Elements: elements, Dimensions: uta.Dimensions, Status: Present}
*dst = AclitemArray{Elements: elements, Dimensions: uta.Dimensions, Status: Present}
return nil
}
func (src *ACLItemArray) EncodeText(w io.Writer) (bool, error) {
func (src *AclitemArray) EncodeText(w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
+37 -37
View File
@@ -7,40 +7,40 @@ import (
"github.com/jackc/pgx/pgtype"
)
func TestACLItemArrayTranscode(t *testing.T) {
func TestAclitemArrayTranscode(t *testing.T) {
testSuccessfulTranscode(t, "aclitem[]", []interface{}{
&pgtype.ACLItemArray{
&pgtype.AclitemArray{
Elements: nil,
Dimensions: nil,
Status: pgtype.Present,
},
&pgtype.ACLItemArray{
Elements: []pgtype.ACLItem{
pgtype.ACLItem{String: "=r/postgres", Status: pgtype.Present},
pgtype.ACLItem{Status: pgtype.Null},
&pgtype.AclitemArray{
Elements: []pgtype.Aclitem{
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
pgtype.Aclitem{Status: pgtype.Null},
},
Dimensions: []pgtype.ArrayDimension{{Length: 2, LowerBound: 1}},
Status: pgtype.Present,
},
&pgtype.ACLItemArray{Status: pgtype.Null},
&pgtype.ACLItemArray{
Elements: []pgtype.ACLItem{
pgtype.ACLItem{String: "=r/postgres", Status: pgtype.Present},
pgtype.ACLItem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
pgtype.ACLItem{String: `postgres=arwdDxt/" tricky, ' } "" \ test user "`, Status: pgtype.Present},
pgtype.ACLItem{String: "=r/postgres", Status: pgtype.Present},
pgtype.ACLItem{Status: pgtype.Null},
pgtype.ACLItem{String: "=r/postgres", Status: pgtype.Present},
&pgtype.AclitemArray{Status: pgtype.Null},
&pgtype.AclitemArray{
Elements: []pgtype.Aclitem{
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
pgtype.Aclitem{String: `postgres=arwdDxt/" tricky, ' } "" \ test user "`, Status: pgtype.Present},
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
pgtype.Aclitem{Status: pgtype.Null},
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
},
Dimensions: []pgtype.ArrayDimension{{Length: 3, LowerBound: 1}, {Length: 2, LowerBound: 1}},
Status: pgtype.Present,
},
&pgtype.ACLItemArray{
Elements: []pgtype.ACLItem{
pgtype.ACLItem{String: "=r/postgres", Status: pgtype.Present},
pgtype.ACLItem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
pgtype.ACLItem{String: "=r/postgres", Status: pgtype.Present},
pgtype.ACLItem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
&pgtype.AclitemArray{
Elements: []pgtype.Aclitem{
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
pgtype.Aclitem{String: "=r/postgres", Status: pgtype.Present},
pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
},
Dimensions: []pgtype.ArrayDimension{
{Length: 2, LowerBound: 4},
@@ -51,26 +51,26 @@ func TestACLItemArrayTranscode(t *testing.T) {
})
}
func TestACLItemArrayConvertFrom(t *testing.T) {
func TestAclitemArrayConvertFrom(t *testing.T) {
successfulTests := []struct {
source interface{}
result pgtype.ACLItemArray
result pgtype.AclitemArray
}{
{
source: []string{"=r/postgres"},
result: pgtype.ACLItemArray{
Elements: []pgtype.ACLItem{{String: "=r/postgres", Status: pgtype.Present}},
result: pgtype.AclitemArray{
Elements: []pgtype.Aclitem{{String: "=r/postgres", Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
Status: pgtype.Present},
},
{
source: (([]string)(nil)),
result: pgtype.ACLItemArray{Status: pgtype.Null},
result: pgtype.AclitemArray{Status: pgtype.Null},
},
}
for i, tt := range successfulTests {
var r pgtype.ACLItemArray
var r pgtype.AclitemArray
err := r.ConvertFrom(tt.source)
if err != nil {
t.Errorf("%d: %v", i, err)
@@ -82,19 +82,19 @@ func TestACLItemArrayConvertFrom(t *testing.T) {
}
}
func TestACLItemArrayAssignTo(t *testing.T) {
func TestAclitemArrayAssignTo(t *testing.T) {
var stringSlice []string
type _stringSlice []string
var namedStringSlice _stringSlice
simpleTests := []struct {
src pgtype.ACLItemArray
src pgtype.AclitemArray
dst interface{}
expected interface{}
}{
{
src: pgtype.ACLItemArray{
Elements: []pgtype.ACLItem{{String: "=r/postgres", Status: pgtype.Present}},
src: pgtype.AclitemArray{
Elements: []pgtype.Aclitem{{String: "=r/postgres", Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
Status: pgtype.Present,
},
@@ -102,8 +102,8 @@ func TestACLItemArrayAssignTo(t *testing.T) {
expected: []string{"=r/postgres"},
},
{
src: pgtype.ACLItemArray{
Elements: []pgtype.ACLItem{{String: "=r/postgres", Status: pgtype.Present}},
src: pgtype.AclitemArray{
Elements: []pgtype.Aclitem{{String: "=r/postgres", Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
Status: pgtype.Present,
},
@@ -111,7 +111,7 @@ func TestACLItemArrayAssignTo(t *testing.T) {
expected: _stringSlice{"=r/postgres"},
},
{
src: pgtype.ACLItemArray{Status: pgtype.Null},
src: pgtype.AclitemArray{Status: pgtype.Null},
dst: &stringSlice,
expected: (([]string)(nil)),
},
@@ -129,12 +129,12 @@ func TestACLItemArrayAssignTo(t *testing.T) {
}
errorTests := []struct {
src pgtype.ACLItemArray
src pgtype.AclitemArray
dst interface{}
}{
{
src: pgtype.ACLItemArray{
Elements: []pgtype.ACLItem{{Status: pgtype.Null}},
src: pgtype.AclitemArray{
Elements: []pgtype.Aclitem{{Status: pgtype.Null}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
Status: pgtype.Present,
},
+18 -18
View File
@@ -7,26 +7,26 @@ import (
"github.com/jackc/pgx/pgtype"
)
func TestACLItemTranscode(t *testing.T) {
func TestAclitemTranscode(t *testing.T) {
testSuccessfulTranscode(t, "aclitem", []interface{}{
pgtype.ACLItem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
pgtype.ACLItem{String: `postgres=arwdDxt/" tricky, ' } "" \ test user "`, Status: pgtype.Present},
pgtype.ACLItem{Status: pgtype.Null},
pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present},
pgtype.Aclitem{String: `postgres=arwdDxt/" tricky, ' } "" \ test user "`, Status: pgtype.Present},
pgtype.Aclitem{Status: pgtype.Null},
})
}
func TestACLItemConvertFrom(t *testing.T) {
func TestAclitemConvertFrom(t *testing.T) {
successfulTests := []struct {
source interface{}
result pgtype.ACLItem
result pgtype.Aclitem
}{
{source: pgtype.ACLItem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}, result: pgtype.ACLItem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}},
{source: "postgres=arwdDxt/postgres", result: pgtype.ACLItem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}},
{source: (*string)(nil), result: pgtype.ACLItem{Status: pgtype.Null}},
{source: pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}, result: pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}},
{source: "postgres=arwdDxt/postgres", result: pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}},
{source: (*string)(nil), result: pgtype.Aclitem{Status: pgtype.Null}},
}
for i, tt := range successfulTests {
var d pgtype.ACLItem
var d pgtype.Aclitem
err := d.ConvertFrom(tt.source)
if err != nil {
t.Errorf("%d: %v", i, err)
@@ -38,17 +38,17 @@ func TestACLItemConvertFrom(t *testing.T) {
}
}
func TestACLItemAssignTo(t *testing.T) {
func TestAclitemAssignTo(t *testing.T) {
var s string
var ps *string
simpleTests := []struct {
src pgtype.ACLItem
src pgtype.Aclitem
dst interface{}
expected interface{}
}{
{src: pgtype.ACLItem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}, dst: &s, expected: "postgres=arwdDxt/postgres"},
{src: pgtype.ACLItem{Status: pgtype.Null}, dst: &ps, expected: ((*string)(nil))},
{src: pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}, dst: &s, expected: "postgres=arwdDxt/postgres"},
{src: pgtype.Aclitem{Status: pgtype.Null}, dst: &ps, expected: ((*string)(nil))},
}
for i, tt := range simpleTests {
@@ -63,11 +63,11 @@ func TestACLItemAssignTo(t *testing.T) {
}
pointerAllocTests := []struct {
src pgtype.ACLItem
src pgtype.Aclitem
dst interface{}
expected interface{}
}{
{src: pgtype.ACLItem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}, dst: &ps, expected: "postgres=arwdDxt/postgres"},
{src: pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}, dst: &ps, expected: "postgres=arwdDxt/postgres"},
}
for i, tt := range pointerAllocTests {
@@ -82,10 +82,10 @@ func TestACLItemAssignTo(t *testing.T) {
}
errorTests := []struct {
src pgtype.ACLItem
src pgtype.Aclitem
dst interface{}
}{
{src: pgtype.ACLItem{Status: pgtype.Null}, dst: &s},
{src: pgtype.Aclitem{Status: pgtype.Null}, dst: &s},
}
for i, tt := range errorTests {
+3 -3
View File
@@ -18,7 +18,7 @@ import (
type ArrayHeader struct {
ContainsNull bool
ElementOID int32
ElementOid int32
Dimensions []ArrayDimension
}
@@ -40,7 +40,7 @@ func (dst *ArrayHeader) DecodeBinary(src []byte) (int, error) {
dst.ContainsNull = binary.BigEndian.Uint32(src[rp:]) == 1
rp += 4
dst.ElementOID = int32(binary.BigEndian.Uint32(src[rp:]))
dst.ElementOid = int32(binary.BigEndian.Uint32(src[rp:]))
rp += 4
if numDims > 0 {
@@ -75,7 +75,7 @@ func (src *ArrayHeader) EncodeBinary(w io.Writer) error {
return err
}
_, err = pgio.WriteInt32(w, src.ElementOID)
_, err = pgio.WriteInt32(w, src.ElementOid)
if err != nil {
return err
}
+3 -3
View File
@@ -229,10 +229,10 @@ func (src *BoolArray) EncodeText(w io.Writer) (bool, error) {
}
func (src *BoolArray) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, BoolOID)
return src.encodeBinary(w, BoolOid)
}
func (src *BoolArray) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *BoolArray) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -241,7 +241,7 @@ func (src *BoolArray) encodeBinary(w io.Writer, elementOID int32) (bool, error)
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+3 -3
View File
@@ -229,10 +229,10 @@ func (src *ByteaArray) EncodeText(w io.Writer) (bool, error) {
}
func (src *ByteaArray) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, ByteaOID)
return src.encodeBinary(w, ByteaOid)
}
func (src *ByteaArray) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *ByteaArray) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -241,7 +241,7 @@ func (src *ByteaArray) encodeBinary(w io.Writer, elementOID int32) (bool, error)
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+10 -10
View File
@@ -4,7 +4,7 @@ import (
"io"
)
// CID is PostgreSQL's Command Identifier type.
// Cid is PostgreSQL's Command Identifier type.
//
// When one does
//
@@ -15,33 +15,33 @@ import (
// It is currently implemented as an unsigned four byte integer.
// Its definition can be found in src/include/c.h as CommandId
// in the PostgreSQL sources.
type CID pguint32
type Cid pguint32
// ConvertFrom converts from src to dst. Note that as CID is not a general
// ConvertFrom converts from src to dst. Note that as Cid is not a general
// number type ConvertFrom does not do automatic type conversion as other number
// types do.
func (dst *CID) ConvertFrom(src interface{}) error {
func (dst *Cid) ConvertFrom(src interface{}) error {
return (*pguint32)(dst).ConvertFrom(src)
}
// AssignTo assigns from src to dst. Note that as CID is not a general number
// AssignTo assigns from src to dst. Note that as Cid is not a general number
// type AssignTo does not do automatic type conversion as other number types do.
func (src *CID) AssignTo(dst interface{}) error {
func (src *Cid) AssignTo(dst interface{}) error {
return (*pguint32)(src).AssignTo(dst)
}
func (dst *CID) DecodeText(src []byte) error {
func (dst *Cid) DecodeText(src []byte) error {
return (*pguint32)(dst).DecodeText(src)
}
func (dst *CID) DecodeBinary(src []byte) error {
func (dst *Cid) DecodeBinary(src []byte) error {
return (*pguint32)(dst).DecodeBinary(src)
}
func (src CID) EncodeText(w io.Writer) (bool, error) {
func (src Cid) EncodeText(w io.Writer) (bool, error) {
return (pguint32)(src).EncodeText(w)
}
func (src CID) EncodeBinary(w io.Writer) (bool, error) {
func (src Cid) EncodeBinary(w io.Writer) (bool, error) {
return (pguint32)(src).EncodeBinary(w)
}
+15 -15
View File
@@ -7,23 +7,23 @@ import (
"github.com/jackc/pgx/pgtype"
)
func TestCIDTranscode(t *testing.T) {
func TestCidTranscode(t *testing.T) {
testSuccessfulTranscode(t, "cid", []interface{}{
pgtype.CID{Uint: 42, Status: pgtype.Present},
pgtype.CID{Status: pgtype.Null},
pgtype.Cid{Uint: 42, Status: pgtype.Present},
pgtype.Cid{Status: pgtype.Null},
})
}
func TestCIDConvertFrom(t *testing.T) {
func TestCidConvertFrom(t *testing.T) {
successfulTests := []struct {
source interface{}
result pgtype.CID
result pgtype.Cid
}{
{source: uint32(1), result: pgtype.CID{Uint: 1, Status: pgtype.Present}},
{source: uint32(1), result: pgtype.Cid{Uint: 1, Status: pgtype.Present}},
}
for i, tt := range successfulTests {
var r pgtype.CID
var r pgtype.Cid
err := r.ConvertFrom(tt.source)
if err != nil {
t.Errorf("%d: %v", i, err)
@@ -35,17 +35,17 @@ func TestCIDConvertFrom(t *testing.T) {
}
}
func TestCIDAssignTo(t *testing.T) {
func TestCidAssignTo(t *testing.T) {
var ui32 uint32
var pui32 *uint32
simpleTests := []struct {
src pgtype.CID
src pgtype.Cid
dst interface{}
expected interface{}
}{
{src: pgtype.CID{Uint: 42, Status: pgtype.Present}, dst: &ui32, expected: uint32(42)},
{src: pgtype.CID{Status: pgtype.Null}, dst: &pui32, expected: ((*uint32)(nil))},
{src: pgtype.Cid{Uint: 42, Status: pgtype.Present}, dst: &ui32, expected: uint32(42)},
{src: pgtype.Cid{Status: pgtype.Null}, dst: &pui32, expected: ((*uint32)(nil))},
}
for i, tt := range simpleTests {
@@ -60,11 +60,11 @@ func TestCIDAssignTo(t *testing.T) {
}
pointerAllocTests := []struct {
src pgtype.CID
src pgtype.Cid
dst interface{}
expected interface{}
}{
{src: pgtype.CID{Uint: 42, Status: pgtype.Present}, dst: &pui32, expected: uint32(42)},
{src: pgtype.Cid{Uint: 42, Status: pgtype.Present}, dst: &pui32, expected: uint32(42)},
}
for i, tt := range pointerAllocTests {
@@ -79,10 +79,10 @@ func TestCIDAssignTo(t *testing.T) {
}
errorTests := []struct {
src pgtype.CID
src pgtype.Cid
dst interface{}
}{
{src: pgtype.CID{Status: pgtype.Null}, dst: &ui32},
{src: pgtype.Cid{Status: pgtype.Null}, dst: &ui32},
}
for i, tt := range errorTests {
+1 -1
View File
@@ -27,5 +27,5 @@ func (src *CidrArray) EncodeText(w io.Writer) (bool, error) {
}
func (src *CidrArray) EncodeBinary(w io.Writer) (bool, error) {
return (*InetArray)(src).encodeBinary(w, CidrOID)
return (*InetArray)(src).encodeBinary(w, CidrOid)
}
+3 -3
View File
@@ -230,10 +230,10 @@ func (src *DateArray) EncodeText(w io.Writer) (bool, error) {
}
func (src *DateArray) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, DateOID)
return src.encodeBinary(w, DateOid)
}
func (src *DateArray) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *DateArray) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -242,7 +242,7 @@ func (src *DateArray) encodeBinary(w io.Writer, elementOID int32) (bool, error)
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+1 -1
View File
@@ -1,3 +1,3 @@
Can pass function to get inet data and function to get oid/name mapping as optional interface with io.Reader or io.Writer
Could be useful for arrays of types without defined OIDs like hstore.
Could be useful for arrays of types without defined Oids like hstore.
+3 -3
View File
@@ -229,10 +229,10 @@ func (src *Float4Array) EncodeText(w io.Writer) (bool, error) {
}
func (src *Float4Array) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, Float4OID)
return src.encodeBinary(w, Float4Oid)
}
func (src *Float4Array) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *Float4Array) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -241,7 +241,7 @@ func (src *Float4Array) encodeBinary(w io.Writer, elementOID int32) (bool, error
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+3 -3
View File
@@ -229,10 +229,10 @@ func (src *Float8Array) EncodeText(w io.Writer) (bool, error) {
}
func (src *Float8Array) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, Float8OID)
return src.encodeBinary(w, Float8Oid)
}
func (src *Float8Array) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *Float8Array) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -241,7 +241,7 @@ func (src *Float8Array) encodeBinary(w io.Writer, elementOID int32) (bool, error
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+3 -3
View File
@@ -261,10 +261,10 @@ func (src *InetArray) EncodeText(w io.Writer) (bool, error) {
}
func (src *InetArray) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, InetOID)
return src.encodeBinary(w, InetOid)
}
func (src *InetArray) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *InetArray) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -273,7 +273,7 @@ func (src *InetArray) encodeBinary(w io.Writer, elementOID int32) (bool, error)
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+18 -18
View File
@@ -17,7 +17,7 @@ func TestInetArrayTranscode(t *testing.T) {
},
&pgtype.InetArray{
Elements: []pgtype.Inet{
pgtype.Inet{IPNet: mustParseCIDR(t, "12.34.56.0/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "12.34.56.0/32"), Status: pgtype.Present},
pgtype.Inet{Status: pgtype.Null},
},
Dimensions: []pgtype.ArrayDimension{{Length: 2, LowerBound: 1}},
@@ -26,22 +26,22 @@ func TestInetArrayTranscode(t *testing.T) {
&pgtype.InetArray{Status: pgtype.Null},
&pgtype.InetArray{
Elements: []pgtype.Inet{
pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "12.34.56.0/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "192.168.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "2607:f8b0:4009:80b::200e/128"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "12.34.56.0/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "192.168.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "2607:f8b0:4009:80b::200e/128"), Status: pgtype.Present},
pgtype.Inet{Status: pgtype.Null},
pgtype.Inet{IPNet: mustParseCIDR(t, "255.0.0.0/8"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "255.0.0.0/8"), Status: pgtype.Present},
},
Dimensions: []pgtype.ArrayDimension{{Length: 3, LowerBound: 1}, {Length: 2, LowerBound: 1}},
Status: pgtype.Present,
},
&pgtype.InetArray{
Elements: []pgtype.Inet{
pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "12.34.56.0/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "192.168.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "2607:f8b0:4009:80b::200e/128"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "12.34.56.0/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "192.168.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "2607:f8b0:4009:80b::200e/128"), Status: pgtype.Present},
},
Dimensions: []pgtype.ArrayDimension{
{Length: 2, LowerBound: 4},
@@ -58,9 +58,9 @@ func TestInetArrayConvertFrom(t *testing.T) {
result pgtype.InetArray
}{
{
source: []*net.IPNet{mustParseCIDR(t, "127.0.0.1/32")},
source: []*net.IPNet{mustParseCidr(t, "127.0.0.1/32")},
result: pgtype.InetArray{
Elements: []pgtype.Inet{{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}},
Elements: []pgtype.Inet{{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
Status: pgtype.Present},
},
@@ -69,9 +69,9 @@ func TestInetArrayConvertFrom(t *testing.T) {
result: pgtype.InetArray{Status: pgtype.Null},
},
{
source: []net.IP{mustParseCIDR(t, "127.0.0.1/32").IP},
source: []net.IP{mustParseCidr(t, "127.0.0.1/32").IP},
result: pgtype.InetArray{
Elements: []pgtype.Inet{{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}},
Elements: []pgtype.Inet{{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
Status: pgtype.Present},
},
@@ -105,12 +105,12 @@ func TestInetArrayAssignTo(t *testing.T) {
}{
{
src: pgtype.InetArray{
Elements: []pgtype.Inet{{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}},
Elements: []pgtype.Inet{{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
Status: pgtype.Present,
},
dst: &ipnetSlice,
expected: []*net.IPNet{mustParseCIDR(t, "127.0.0.1/32")},
expected: []*net.IPNet{mustParseCidr(t, "127.0.0.1/32")},
},
{
src: pgtype.InetArray{
@@ -123,12 +123,12 @@ func TestInetArrayAssignTo(t *testing.T) {
},
{
src: pgtype.InetArray{
Elements: []pgtype.Inet{{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}},
Elements: []pgtype.Inet{{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
Status: pgtype.Present,
},
dst: &ipSlice,
expected: []net.IP{mustParseCIDR(t, "127.0.0.1/32").IP},
expected: []net.IP{mustParseCidr(t, "127.0.0.1/32").IP},
},
{
src: pgtype.InetArray{
+19 -19
View File
@@ -11,16 +11,16 @@ import (
func TestInetTranscode(t *testing.T) {
for _, pgTypeName := range []string{"inet", "cidr"} {
testSuccessfulTranscode(t, pgTypeName, []interface{}{
pgtype.Inet{IPNet: mustParseCIDR(t, "0.0.0.0/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "12.34.56.0/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "192.168.1.0/24"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "255.0.0.0/8"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "255.255.255.255/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "::/128"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "::/0"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "::1/128"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCIDR(t, "2607:f8b0:4009:80b::200e/128"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "0.0.0.0/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "12.34.56.0/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "192.168.1.0/24"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "255.0.0.0/8"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "255.255.255.255/32"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "::/128"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "::/0"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "::1/128"), Status: pgtype.Present},
pgtype.Inet{IPNet: mustParseCidr(t, "2607:f8b0:4009:80b::200e/128"), Status: pgtype.Present},
pgtype.Inet{Status: pgtype.Null},
})
}
@@ -31,10 +31,10 @@ func TestInetConvertFrom(t *testing.T) {
source interface{}
result pgtype.Inet
}{
{source: pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Null}, result: pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Null}},
{source: mustParseCIDR(t, "127.0.0.1/32"), result: pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}},
{source: mustParseCIDR(t, "127.0.0.1/32").IP, result: pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}},
{source: "127.0.0.1/32", result: pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}},
{source: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Null}, result: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Null}},
{source: mustParseCidr(t, "127.0.0.1/32"), result: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},
{source: mustParseCidr(t, "127.0.0.1/32").IP, result: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},
{source: "127.0.0.1/32", result: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},
}
for i, tt := range successfulTests {
@@ -61,8 +61,8 @@ func TestInetAssignTo(t *testing.T) {
dst interface{}
expected interface{}
}{
{src: pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}, dst: &ipnet, expected: *mustParseCIDR(t, "127.0.0.1/32")},
{src: pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}, dst: &ip, expected: mustParseCIDR(t, "127.0.0.1/32").IP},
{src: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}, dst: &ipnet, expected: *mustParseCidr(t, "127.0.0.1/32")},
{src: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}, dst: &ip, expected: mustParseCidr(t, "127.0.0.1/32").IP},
{src: pgtype.Inet{Status: pgtype.Null}, dst: &pipnet, expected: ((*net.IPNet)(nil))},
{src: pgtype.Inet{Status: pgtype.Null}, dst: &pip, expected: ((*net.IP)(nil))},
}
@@ -83,8 +83,8 @@ func TestInetAssignTo(t *testing.T) {
dst interface{}
expected interface{}
}{
{src: pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}, dst: &pipnet, expected: *mustParseCIDR(t, "127.0.0.1/32")},
{src: pgtype.Inet{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present}, dst: &pip, expected: mustParseCIDR(t, "127.0.0.1/32").IP},
{src: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}, dst: &pipnet, expected: *mustParseCidr(t, "127.0.0.1/32")},
{src: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}, dst: &pip, expected: mustParseCidr(t, "127.0.0.1/32").IP},
}
for i, tt := range pointerAllocTests {
@@ -102,7 +102,7 @@ func TestInetAssignTo(t *testing.T) {
src pgtype.Inet
dst interface{}
}{
{src: pgtype.Inet{IPNet: mustParseCIDR(t, "192.168.0.0/16"), Status: pgtype.Present}, dst: &ip},
{src: pgtype.Inet{IPNet: mustParseCidr(t, "192.168.0.0/16"), Status: pgtype.Present}, dst: &ip},
{src: pgtype.Inet{Status: pgtype.Null}, dst: &ipnet},
}
+3 -3
View File
@@ -260,10 +260,10 @@ func (src *Int2Array) EncodeText(w io.Writer) (bool, error) {
}
func (src *Int2Array) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, Int2OID)
return src.encodeBinary(w, Int2Oid)
}
func (src *Int2Array) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *Int2Array) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -272,7 +272,7 @@ func (src *Int2Array) encodeBinary(w io.Writer, elementOID int32) (bool, error)
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+3 -3
View File
@@ -260,10 +260,10 @@ func (src *Int4Array) EncodeText(w io.Writer) (bool, error) {
}
func (src *Int4Array) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, Int4OID)
return src.encodeBinary(w, Int4Oid)
}
func (src *Int4Array) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *Int4Array) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -272,7 +272,7 @@ func (src *Int4Array) encodeBinary(w io.Writer, elementOID int32) (bool, error)
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+3 -3
View File
@@ -260,10 +260,10 @@ func (src *Int8Array) EncodeText(w io.Writer) (bool, error) {
}
func (src *Int8Array) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, Int8OID)
return src.encodeBinary(w, Int8Oid)
}
func (src *Int8Array) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *Int8Array) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -272,7 +272,7 @@ func (src *Int8Array) encodeBinary(w io.Writer, elementOID int32) (bool, error)
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+10 -10
View File
@@ -4,38 +4,38 @@ import (
"io"
)
// OID (Object Identifier Type) is, according to
// Oid (Object Identifier Type) is, according to
// https://www.postgresql.org/docs/current/static/datatype-oid.html, used
// internally by PostgreSQL as a primary key for various system tables. It is
// currently implemented as an unsigned four-byte integer. Its definition can be
// found in src/include/postgres_ext.h in the PostgreSQL sources.
type OID pguint32
type Oid pguint32
// ConvertFrom converts from src to dst. Note that as OID is not a general
// ConvertFrom converts from src to dst. Note that as Oid is not a general
// number type ConvertFrom does not do automatic type conversion as other number
// types do.
func (dst *OID) ConvertFrom(src interface{}) error {
func (dst *Oid) ConvertFrom(src interface{}) error {
return (*pguint32)(dst).ConvertFrom(src)
}
// AssignTo assigns from src to dst. Note that as OID is not a general number
// AssignTo assigns from src to dst. Note that as Oid is not a general number
// type AssignTo does not do automatic type conversion as other number types do.
func (src *OID) AssignTo(dst interface{}) error {
func (src *Oid) AssignTo(dst interface{}) error {
return (*pguint32)(src).AssignTo(dst)
}
func (dst *OID) DecodeText(src []byte) error {
func (dst *Oid) DecodeText(src []byte) error {
return (*pguint32)(dst).DecodeText(src)
}
func (dst *OID) DecodeBinary(src []byte) error {
func (dst *Oid) DecodeBinary(src []byte) error {
return (*pguint32)(dst).DecodeBinary(src)
}
func (src OID) EncodeText(w io.Writer) (bool, error) {
func (src Oid) EncodeText(w io.Writer) (bool, error) {
return (pguint32)(src).EncodeText(w)
}
func (src OID) EncodeBinary(w io.Writer) (bool, error) {
func (src Oid) EncodeBinary(w io.Writer) (bool, error) {
return (pguint32)(src).EncodeBinary(w)
}
+15 -15
View File
@@ -7,23 +7,23 @@ import (
"github.com/jackc/pgx/pgtype"
)
func TestOIDTranscode(t *testing.T) {
func TestOidTranscode(t *testing.T) {
testSuccessfulTranscode(t, "oid", []interface{}{
pgtype.OID{Uint: 42, Status: pgtype.Present},
pgtype.OID{Status: pgtype.Null},
pgtype.Oid{Uint: 42, Status: pgtype.Present},
pgtype.Oid{Status: pgtype.Null},
})
}
func TestOIDConvertFrom(t *testing.T) {
func TestOidConvertFrom(t *testing.T) {
successfulTests := []struct {
source interface{}
result pgtype.OID
result pgtype.Oid
}{
{source: uint32(1), result: pgtype.OID{Uint: 1, Status: pgtype.Present}},
{source: uint32(1), result: pgtype.Oid{Uint: 1, Status: pgtype.Present}},
}
for i, tt := range successfulTests {
var r pgtype.OID
var r pgtype.Oid
err := r.ConvertFrom(tt.source)
if err != nil {
t.Errorf("%d: %v", i, err)
@@ -35,17 +35,17 @@ func TestOIDConvertFrom(t *testing.T) {
}
}
func TestOIDAssignTo(t *testing.T) {
func TestOidAssignTo(t *testing.T) {
var ui32 uint32
var pui32 *uint32
simpleTests := []struct {
src pgtype.OID
src pgtype.Oid
dst interface{}
expected interface{}
}{
{src: pgtype.OID{Uint: 42, Status: pgtype.Present}, dst: &ui32, expected: uint32(42)},
{src: pgtype.OID{Status: pgtype.Null}, dst: &pui32, expected: ((*uint32)(nil))},
{src: pgtype.Oid{Uint: 42, Status: pgtype.Present}, dst: &ui32, expected: uint32(42)},
{src: pgtype.Oid{Status: pgtype.Null}, dst: &pui32, expected: ((*uint32)(nil))},
}
for i, tt := range simpleTests {
@@ -60,11 +60,11 @@ func TestOIDAssignTo(t *testing.T) {
}
pointerAllocTests := []struct {
src pgtype.OID
src pgtype.Oid
dst interface{}
expected interface{}
}{
{src: pgtype.OID{Uint: 42, Status: pgtype.Present}, dst: &pui32, expected: uint32(42)},
{src: pgtype.Oid{Uint: 42, Status: pgtype.Present}, dst: &pui32, expected: uint32(42)},
}
for i, tt := range pointerAllocTests {
@@ -79,10 +79,10 @@ func TestOIDAssignTo(t *testing.T) {
}
errorTests := []struct {
src pgtype.OID
src pgtype.Oid
dst interface{}
}{
{src: pgtype.OID{Status: pgtype.Null}, dst: &ui32},
{src: pgtype.Oid{Status: pgtype.Null}, dst: &ui32},
}
for i, tt := range errorTests {
+41 -41
View File
@@ -7,47 +7,47 @@ import (
// PostgreSQL oids for common types
const (
BoolOID = 16
ByteaOID = 17
CharOID = 18
NameOID = 19
Int8OID = 20
Int2OID = 21
Int4OID = 23
TextOID = 25
OIDOID = 26
TIDOID = 27
XIDOID = 28
CIDOID = 29
JSONOID = 114
CidrOID = 650
CidrArrayOID = 651
Float4OID = 700
Float8OID = 701
UnknownOID = 705
InetOID = 869
BoolArrayOID = 1000
Int2ArrayOID = 1005
Int4ArrayOID = 1007
TextArrayOID = 1009
ByteaArrayOID = 1001
VarcharArrayOID = 1015
Int8ArrayOID = 1016
Float4ArrayOID = 1021
Float8ArrayOID = 1022
ACLItemOID = 1033
ACLItemArrayOID = 1034
InetArrayOID = 1041
VarcharOID = 1043
DateOID = 1082
TimestampOID = 1114
TimestampArrayOID = 1115
DateArrayOID = 1182
TimestamptzOID = 1184
TimestamptzArrayOID = 1185
RecordOID = 2249
UUIDOID = 2950
JSONBOID = 3802
BoolOid = 16
ByteaOid = 17
CharOid = 18
NameOid = 19
Int8Oid = 20
Int2Oid = 21
Int4Oid = 23
TextOid = 25
OidOid = 26
TidOid = 27
XidOid = 28
CidOid = 29
JsonOid = 114
CidrOid = 650
CidrArrayOid = 651
Float4Oid = 700
Float8Oid = 701
UnknownOid = 705
InetOid = 869
BoolArrayOid = 1000
Int2ArrayOid = 1005
Int4ArrayOid = 1007
TextArrayOid = 1009
ByteaArrayOid = 1001
VarcharArrayOid = 1015
Int8ArrayOid = 1016
Float4ArrayOid = 1021
Float8ArrayOid = 1022
AclitemOid = 1033
AclitemArrayOid = 1034
InetArrayOid = 1041
VarcharOid = 1043
DateOid = 1082
TimestampOid = 1114
TimestampArrayOid = 1115
DateArrayOid = 1182
TimestamptzOid = 1184
TimestamptzArrayOid = 1185
RecordOid = 2249
UuidOid = 2950
JsonbOid = 3802
)
type Status byte
+1 -1
View File
@@ -47,7 +47,7 @@ func mustClose(t testing.TB, conn interface {
}
}
func mustParseCIDR(t testing.TB, s string) *net.IPNet {
func mustParseCidr(t testing.TB, s string) *net.IPNet {
_, ipnet, err := net.ParseCIDR(s)
if err != nil {
t.Fatal(err)
+1 -1
View File
@@ -10,7 +10,7 @@ import (
)
// pguint32 is the core type that is used to implement PostgreSQL types such as
// CID and XID.
// Cid and Xid.
type pguint32 struct {
Uint uint32
Status Status
+3 -3
View File
@@ -229,10 +229,10 @@ func (src *TextArray) EncodeText(w io.Writer) (bool, error) {
}
func (src *TextArray) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, TextOID)
return src.encodeBinary(w, TextOid)
}
func (src *TextArray) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *TextArray) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -241,7 +241,7 @@ func (src *TextArray) encodeBinary(w io.Writer, elementOID int32) (bool, error)
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+10 -10
View File
@@ -10,7 +10,7 @@ import (
"github.com/jackc/pgx/pgio"
)
// TID is PostgreSQL's Tuple Identifier type.
// Tid is PostgreSQL's Tuple Identifier type.
//
// When one does
//
@@ -21,15 +21,15 @@ import (
// It is currently implemented as a pair unsigned two byte integers.
// Its conversion functions can be found in src/backend/utils/adt/tid.c
// in the PostgreSQL sources.
type TID struct {
type Tid struct {
BlockNumber uint32
OffsetNumber uint16
Status Status
}
func (dst *TID) DecodeText(src []byte) error {
func (dst *Tid) DecodeText(src []byte) error {
if src == nil {
*dst = TID{Status: Null}
*dst = Tid{Status: Null}
return nil
}
@@ -52,13 +52,13 @@ func (dst *TID) DecodeText(src []byte) error {
return err
}
*dst = TID{BlockNumber: uint32(blockNumber), OffsetNumber: uint16(offsetNumber), Status: Present}
*dst = Tid{BlockNumber: uint32(blockNumber), OffsetNumber: uint16(offsetNumber), Status: Present}
return nil
}
func (dst *TID) DecodeBinary(src []byte) error {
func (dst *Tid) DecodeBinary(src []byte) error {
if src == nil {
*dst = TID{Status: Null}
*dst = Tid{Status: Null}
return nil
}
@@ -66,7 +66,7 @@ func (dst *TID) DecodeBinary(src []byte) error {
return fmt.Errorf("invalid length for tid: %v", len(src))
}
*dst = TID{
*dst = Tid{
BlockNumber: binary.BigEndian.Uint32(src),
OffsetNumber: binary.BigEndian.Uint16(src[4:]),
Status: Present,
@@ -74,7 +74,7 @@ func (dst *TID) DecodeBinary(src []byte) error {
return nil
}
func (src TID) EncodeText(w io.Writer) (bool, error) {
func (src Tid) EncodeText(w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -86,7 +86,7 @@ func (src TID) EncodeText(w io.Writer) (bool, error) {
return false, err
}
func (src TID) EncodeBinary(w io.Writer) (bool, error) {
func (src Tid) EncodeBinary(w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
+4 -4
View File
@@ -6,10 +6,10 @@ import (
"github.com/jackc/pgx/pgtype"
)
func TestTIDTranscode(t *testing.T) {
func TestTidTranscode(t *testing.T) {
testSuccessfulTranscode(t, "tid", []interface{}{
pgtype.TID{BlockNumber: 42, OffsetNumber: 43, Status: pgtype.Present},
pgtype.TID{BlockNumber: 4294967295, OffsetNumber: 65535, Status: pgtype.Present},
pgtype.TID{Status: pgtype.Null},
pgtype.Tid{BlockNumber: 42, OffsetNumber: 43, Status: pgtype.Present},
pgtype.Tid{BlockNumber: 4294967295, OffsetNumber: 65535, Status: pgtype.Present},
pgtype.Tid{Status: pgtype.Null},
})
}
+3 -3
View File
@@ -230,10 +230,10 @@ func (src *TimestampArray) EncodeText(w io.Writer) (bool, error) {
}
func (src *TimestampArray) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, TimestampOID)
return src.encodeBinary(w, TimestampOid)
}
func (src *TimestampArray) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *TimestampArray) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -242,7 +242,7 @@ func (src *TimestampArray) encodeBinary(w io.Writer, elementOID int32) (bool, er
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+3 -3
View File
@@ -230,10 +230,10 @@ func (src *TimestamptzArray) EncodeText(w io.Writer) (bool, error) {
}
func (src *TimestamptzArray) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, TimestamptzOID)
return src.encodeBinary(w, TimestamptzOid)
}
func (src *TimestamptzArray) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *TimestamptzArray) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -242,7 +242,7 @@ func (src *TimestamptzArray) encodeBinary(w io.Writer, elementOID int32) (bool,
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+2 -2
View File
@@ -231,7 +231,7 @@ func (src *<%= pgtype_array_type %>) EncodeBinary(w io.Writer) (bool, error) {
return src.encodeBinary(w, <%= element_oid %>)
}
func (src *<%= pgtype_array_type %>) encodeBinary(w io.Writer, elementOID int32) (bool, error) {
func (src *<%= pgtype_array_type %>) encodeBinary(w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -240,7 +240,7 @@ func (src *<%= pgtype_array_type %>) encodeBinary(w io.Writer, elementOID int32)
}
arrayHeader := ArrayHeader{
ElementOID: elementOID,
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
+13 -13
View File
@@ -1,13 +1,13 @@
erb pgtype_array_type=Int2Array pgtype_element_type=Int2 go_array_types=[]int16,[]uint16 element_oid=Int2OID text_null=NULL typed_array.go.erb > int2_array.go
erb pgtype_array_type=Int4Array pgtype_element_type=Int4 go_array_types=[]int32,[]uint32 element_oid=Int4OID text_null=NULL typed_array.go.erb > int4_array.go
erb pgtype_array_type=Int8Array pgtype_element_type=Int8 go_array_types=[]int64,[]uint64 element_oid=Int8OID text_null=NULL typed_array.go.erb > int8_array.go
erb pgtype_array_type=BoolArray pgtype_element_type=Bool go_array_types=[]bool element_oid=BoolOID text_null=NULL typed_array.go.erb > bool_array.go
erb pgtype_array_type=DateArray pgtype_element_type=Date go_array_types=[]time.Time element_oid=DateOID text_null=NULL typed_array.go.erb > date_array.go
erb pgtype_array_type=TimestamptzArray pgtype_element_type=Timestamptz go_array_types=[]time.Time element_oid=TimestamptzOID text_null=NULL typed_array.go.erb > timestamptz_array.go
erb pgtype_array_type=TimestampArray pgtype_element_type=Timestamp go_array_types=[]time.Time element_oid=TimestampOID text_null=NULL typed_array.go.erb > timestamp_array.go
erb pgtype_array_type=Float4Array pgtype_element_type=Float4 go_array_types=[]float32 element_oid=Float4OID text_null=NULL typed_array.go.erb > float4_array.go
erb pgtype_array_type=Float8Array pgtype_element_type=Float8 go_array_types=[]float64 element_oid=Float8OID text_null=NULL typed_array.go.erb > float8_array.go
erb pgtype_array_type=InetArray pgtype_element_type=Inet go_array_types=[]*net.IPNet,[]net.IP element_oid=InetOID text_null=NULL typed_array.go.erb > inet_array.go
erb pgtype_array_type=TextArray pgtype_element_type=Text go_array_types=[]string element_oid=TextOID text_null='"NULL"' typed_array.go.erb > text_array.go
erb pgtype_array_type=ByteaArray pgtype_element_type=Bytea go_array_types=[][]byte element_oid=ByteaOID text_null=NULL typed_array.go.erb > bytea_array.go
erb pgtype_array_type=ACLItemArray pgtype_element_type=ACLItem go_array_types=[]string element_oid=ACLItemOID text_null=NULL typed_array.go.erb > aclitem_array.go
erb pgtype_array_type=Int2Array pgtype_element_type=Int2 go_array_types=[]int16,[]uint16 element_oid=Int2Oid text_null=NULL typed_array.go.erb > int2_array.go
erb pgtype_array_type=Int4Array pgtype_element_type=Int4 go_array_types=[]int32,[]uint32 element_oid=Int4Oid text_null=NULL typed_array.go.erb > int4_array.go
erb pgtype_array_type=Int8Array pgtype_element_type=Int8 go_array_types=[]int64,[]uint64 element_oid=Int8Oid text_null=NULL typed_array.go.erb > int8_array.go
erb pgtype_array_type=BoolArray pgtype_element_type=Bool go_array_types=[]bool element_oid=BoolOid text_null=NULL typed_array.go.erb > bool_array.go
erb pgtype_array_type=DateArray pgtype_element_type=Date go_array_types=[]time.Time element_oid=DateOid text_null=NULL typed_array.go.erb > date_array.go
erb pgtype_array_type=TimestamptzArray pgtype_element_type=Timestamptz go_array_types=[]time.Time element_oid=TimestamptzOid text_null=NULL typed_array.go.erb > timestamptz_array.go
erb pgtype_array_type=TimestampArray pgtype_element_type=Timestamp go_array_types=[]time.Time element_oid=TimestampOid text_null=NULL typed_array.go.erb > timestamp_array.go
erb pgtype_array_type=Float4Array pgtype_element_type=Float4 go_array_types=[]float32 element_oid=Float4Oid text_null=NULL typed_array.go.erb > float4_array.go
erb pgtype_array_type=Float8Array pgtype_element_type=Float8 go_array_types=[]float64 element_oid=Float8Oid text_null=NULL typed_array.go.erb > float8_array.go
erb pgtype_array_type=InetArray pgtype_element_type=Inet go_array_types=[]*net.IPNet,[]net.IP element_oid=InetOid text_null=NULL typed_array.go.erb > inet_array.go
erb pgtype_array_type=TextArray pgtype_element_type=Text go_array_types=[]string element_oid=TextOid text_null='"NULL"' typed_array.go.erb > text_array.go
erb pgtype_array_type=ByteaArray pgtype_element_type=Bytea go_array_types=[][]byte element_oid=ByteaOid text_null=NULL typed_array.go.erb > bytea_array.go
erb pgtype_array_type=AclitemArray pgtype_element_type=Aclitem go_array_types=[]string element_oid=AclitemOid text_null=NULL typed_array.go.erb > aclitem_array.go
+1 -1
View File
@@ -27,5 +27,5 @@ func (src *VarcharArray) EncodeText(w io.Writer) (bool, error) {
}
func (src *VarcharArray) EncodeBinary(w io.Writer) (bool, error) {
return (*TextArray)(src).encodeBinary(w, VarcharOID)
return (*TextArray)(src).encodeBinary(w, VarcharOid)
}
+10 -10
View File
@@ -4,7 +4,7 @@ import (
"io"
)
// XID is PostgreSQL's Transaction ID type.
// Xid is PostgreSQL's Transaction ID type.
//
// In later versions of PostgreSQL, it is the type used for the backend_xid
// and backend_xmin columns of the pg_stat_activity system view.
@@ -18,33 +18,33 @@ import (
// It is currently implemented as an unsigned four byte integer.
// Its definition can be found in src/include/postgres_ext.h as TransactionId
// in the PostgreSQL sources.
type XID pguint32
type Xid pguint32
// ConvertFrom converts from src to dst. Note that as XID is not a general
// ConvertFrom converts from src to dst. Note that as Xid is not a general
// number type ConvertFrom does not do automatic type conversion as other number
// types do.
func (dst *XID) ConvertFrom(src interface{}) error {
func (dst *Xid) ConvertFrom(src interface{}) error {
return (*pguint32)(dst).ConvertFrom(src)
}
// AssignTo assigns from src to dst. Note that as XID is not a general number
// AssignTo assigns from src to dst. Note that as Xid is not a general number
// type AssignTo does not do automatic type conversion as other number types do.
func (src *XID) AssignTo(dst interface{}) error {
func (src *Xid) AssignTo(dst interface{}) error {
return (*pguint32)(src).AssignTo(dst)
}
func (dst *XID) DecodeText(src []byte) error {
func (dst *Xid) DecodeText(src []byte) error {
return (*pguint32)(dst).DecodeText(src)
}
func (dst *XID) DecodeBinary(src []byte) error {
func (dst *Xid) DecodeBinary(src []byte) error {
return (*pguint32)(dst).DecodeBinary(src)
}
func (src XID) EncodeText(w io.Writer) (bool, error) {
func (src Xid) EncodeText(w io.Writer) (bool, error) {
return (pguint32)(src).EncodeText(w)
}
func (src XID) EncodeBinary(w io.Writer) (bool, error) {
func (src Xid) EncodeBinary(w io.Writer) (bool, error) {
return (pguint32)(src).EncodeBinary(w)
}
+15 -15
View File
@@ -7,23 +7,23 @@ import (
"github.com/jackc/pgx/pgtype"
)
func TestXIDTranscode(t *testing.T) {
func TestXidTranscode(t *testing.T) {
testSuccessfulTranscode(t, "xid", []interface{}{
pgtype.XID{Uint: 42, Status: pgtype.Present},
pgtype.XID{Status: pgtype.Null},
pgtype.Xid{Uint: 42, Status: pgtype.Present},
pgtype.Xid{Status: pgtype.Null},
})
}
func TestXIDConvertFrom(t *testing.T) {
func TestXidConvertFrom(t *testing.T) {
successfulTests := []struct {
source interface{}
result pgtype.XID
result pgtype.Xid
}{
{source: uint32(1), result: pgtype.XID{Uint: 1, Status: pgtype.Present}},
{source: uint32(1), result: pgtype.Xid{Uint: 1, Status: pgtype.Present}},
}
for i, tt := range successfulTests {
var r pgtype.XID
var r pgtype.Xid
err := r.ConvertFrom(tt.source)
if err != nil {
t.Errorf("%d: %v", i, err)
@@ -35,17 +35,17 @@ func TestXIDConvertFrom(t *testing.T) {
}
}
func TestXIDAssignTo(t *testing.T) {
func TestXidAssignTo(t *testing.T) {
var ui32 uint32
var pui32 *uint32
simpleTests := []struct {
src pgtype.XID
src pgtype.Xid
dst interface{}
expected interface{}
}{
{src: pgtype.XID{Uint: 42, Status: pgtype.Present}, dst: &ui32, expected: uint32(42)},
{src: pgtype.XID{Status: pgtype.Null}, dst: &pui32, expected: ((*uint32)(nil))},
{src: pgtype.Xid{Uint: 42, Status: pgtype.Present}, dst: &ui32, expected: uint32(42)},
{src: pgtype.Xid{Status: pgtype.Null}, dst: &pui32, expected: ((*uint32)(nil))},
}
for i, tt := range simpleTests {
@@ -60,11 +60,11 @@ func TestXIDAssignTo(t *testing.T) {
}
pointerAllocTests := []struct {
src pgtype.XID
src pgtype.Xid
dst interface{}
expected interface{}
}{
{src: pgtype.XID{Uint: 42, Status: pgtype.Present}, dst: &pui32, expected: uint32(42)},
{src: pgtype.Xid{Uint: 42, Status: pgtype.Present}, dst: &pui32, expected: uint32(42)},
}
for i, tt := range pointerAllocTests {
@@ -79,10 +79,10 @@ func TestXIDAssignTo(t *testing.T) {
}
errorTests := []struct {
src pgtype.XID
src pgtype.Xid
dst interface{}
}{
{src: pgtype.XID{Status: pgtype.Null}, dst: &ui32},
{src: pgtype.Xid{Status: pgtype.Null}, dst: &ui32},
}
for i, tt := range errorTests {
+41 -41
View File
@@ -202,7 +202,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 {
@@ -235,25 +235,25 @@ 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 Float4OID:
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())
@@ -263,14 +263,14 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
if err != nil {
rows.Fatal(scanArgError{col: i, err: err})
}
} else if vr.Type().DataType == JSONOID {
} else if vr.Type().DataType == JsonOid {
// 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
// row.
d2 := d
decodeJSON(vr, &d2)
} else if vr.Type().DataType == JSONBOID {
} else if vr.Type().DataType == JsonbOid {
// Same trick as above for getting stack allocation
d2 := d
decodeJSONB(vr, &d2)
@@ -345,11 +345,11 @@ func (rows *Rows) Values() ([]interface{}, error) {
// encoding so anything else should be treated as a string
case TextFormatCode:
switch vr.Type().DataType {
case JSONOID:
case JsonOid:
var d interface{}
decodeJSON(vr, &d)
values = append(values, d)
case JSONBOID:
case JsonbOid:
var d interface{}
decodeJSONB(vr, &d)
values = append(values, d)
@@ -359,33 +359,33 @@ func (rows *Rows) Values() ([]interface{}, error) {
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 Float4OID:
case Float4Oid:
values = append(values, decodeFloat4(vr))
case Float8OID:
case Float8Oid:
values = append(values, decodeFloat8(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 JSONOID:
case JsonOid:
var d interface{}
decodeJSON(vr, &d)
values = append(values, d)
case JSONBOID:
case JsonbOid:
var d interface{}
decodeJSONB(vr, &d)
values = append(values, d)
@@ -432,33 +432,33 @@ func (rows *Rows) ValuesForStdlib() ([]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 Float4OID:
case Float4Oid:
values = append(values, decodeFloat4(vr))
case Float8OID:
case Float8Oid:
values = append(values, decodeFloat8(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 JSONOID:
case JsonOid:
var d interface{}
decodeJSON(vr, &d)
values = append(values, d)
case JSONBOID:
case JsonbOid:
var d interface{}
decodeJSONB(vr, &d)
values = append(values, d)
+4 -4
View File
@@ -197,7 +197,7 @@ func TestConnQueryReadWrongTypeError(t *testing.T) {
t.Fatal("Expected Rows to have an error after an improper read but it didn't")
}
if rows.Err().Error() != "can't scan into dest[0]: Can't convert OID 23 to time.Time" && !strings.Contains(rows.Err().Error(), "cannot assign") {
if rows.Err().Error() != "can't scan into dest[0]: Can't convert Oid 23 to time.Time" && !strings.Contains(rows.Err().Error(), "cannot assign") {
t.Fatalf("Expected different Rows.Err(): %v", rows.Err())
}
@@ -403,7 +403,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
@@ -438,7 +438,7 @@ func TestQueryRowCoreTypes(t *testing.T) {
f64 float64
b bool
t time.Time
oid pgx.OID
oid pgx.Oid
}
var actual, zero allTypes
@@ -456,7 +456,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.UTC)}, []interface{}{&actual.t}, allTypes{t: time.Date(2010, 1, 2, 3, 4, 5, 0, time.UTC)}},
{"select $1::date", []interface{}{time.Date(1987, 1, 2, 0, 0, 0, 0, time.UTC)}, []interface{}{&actual.t}, allTypes{t: time.Date(1987, 1, 2, 0, 0, 0, 0, time.UTC)}},
{"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 {
+14 -14
View File
@@ -58,23 +58,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 {
@@ -263,7 +263,7 @@ func (c *Conn) queryPreparedContext(ctx context.Context, name string, argsV []dr
// (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
}
@@ -280,7 +280,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) {
-6
View File
@@ -2,14 +2,8 @@
## Changes
Rename Oid to OID in accordance with Go naming conventions.
Rename Json(b) to JSON(B) in accordance with Go naming conventions.
Rename Pid to PID in accordance with Go naming conventions.
Rename Uuid to UUID in accordance with Go naming conventions.
Logger interface reduced to single Log method.
Replace BeginIso with BeginEx. BeginEx adds support for read/write mode and deferrable mode.
+2 -2
View File
@@ -116,8 +116,8 @@ func (r *ValueReader) ReadInt64() int64 {
return r.mr.readInt64()
}
func (r *ValueReader) ReadOID() OID {
return OID(r.ReadUint32())
func (r *ValueReader) ReadOid() Oid {
return Oid(r.ReadUint32())
}
// ReadString reads count bytes and returns as string
+172 -172
View File
@@ -19,47 +19,47 @@ import (
// PostgreSQL oids for common types
const (
BoolOID = 16
ByteaOID = 17
CharOID = 18
NameOID = 19
Int8OID = 20
Int2OID = 21
Int4OID = 23
TextOID = 25
OIDOID = 26
TIDOID = 27
XIDOID = 28
CIDOID = 29
JSONOID = 114
CidrOID = 650
CidrArrayOID = 651
Float4OID = 700
Float8OID = 701
UnknownOID = 705
InetOID = 869
BoolArrayOID = 1000
Int2ArrayOID = 1005
Int4ArrayOID = 1007
TextArrayOID = 1009
ByteaArrayOID = 1001
VarcharArrayOID = 1015
Int8ArrayOID = 1016
Float4ArrayOID = 1021
Float8ArrayOID = 1022
ACLItemOID = 1033
ACLItemArrayOID = 1034
InetArrayOID = 1041
VarcharOID = 1043
DateOID = 1082
TimestampOID = 1114
TimestampArrayOID = 1115
DateArrayOID = 1182
TimestampTzOID = 1184
TimestampTzArrayOID = 1185
RecordOID = 2249
UUIDOID = 2950
JSONBOID = 3802
BoolOid = 16
ByteaOid = 17
CharOid = 18
NameOid = 19
Int8Oid = 20
Int2Oid = 21
Int4Oid = 23
TextOid = 25
OidOid = 26
TidOid = 27
XidOid = 28
CidOid = 29
JsonOid = 114
CidrOid = 650
CidrArrayOid = 651
Float4Oid = 700
Float8Oid = 701
UnknownOid = 705
InetOid = 869
BoolArrayOid = 1000
Int2ArrayOid = 1005
Int4ArrayOid = 1007
TextArrayOid = 1009
ByteaArrayOid = 1001
VarcharArrayOid = 1015
Int8ArrayOid = 1016
Float4ArrayOid = 1021
Float8ArrayOid = 1022
AclitemOid = 1033
AclitemArrayOid = 1034
InetArrayOid = 1041
VarcharOid = 1043
DateOid = 1082
TimestampOid = 1114
TimestampArrayOid = 1115
DateArrayOid = 1182
TimestampTzOid = 1184
TimestampTzArrayOid = 1185
RecordOid = 2249
UuidOid = 2950
JsonbOid = 3802
)
// PostgreSQL format codes
@@ -81,7 +81,7 @@ const minInt = -maxInt - 1
var DefaultTypeFormats map[string]int16
// internalNativeGoTypeFormats lists the encoding type for native Go types (not handled with Encoder interface)
var internalNativeGoTypeFormats map[OID]int16
var internalNativeGoTypeFormats map[Oid]int16
func init() {
DefaultTypeFormats = map[string]int16{
@@ -120,36 +120,36 @@ func init() {
"xid": BinaryFormatCode,
}
internalNativeGoTypeFormats = map[OID]int16{
BoolArrayOID: BinaryFormatCode,
BoolOID: BinaryFormatCode,
ByteaArrayOID: BinaryFormatCode,
ByteaOID: BinaryFormatCode,
CidrArrayOID: BinaryFormatCode,
CidrOID: BinaryFormatCode,
DateOID: BinaryFormatCode,
Float4ArrayOID: BinaryFormatCode,
Float4OID: BinaryFormatCode,
Float8ArrayOID: BinaryFormatCode,
Float8OID: BinaryFormatCode,
InetArrayOID: BinaryFormatCode,
InetOID: BinaryFormatCode,
Int2ArrayOID: BinaryFormatCode,
Int2OID: BinaryFormatCode,
Int4ArrayOID: BinaryFormatCode,
Int4OID: BinaryFormatCode,
Int8ArrayOID: BinaryFormatCode,
Int8OID: BinaryFormatCode,
JSONBOID: BinaryFormatCode,
JSONOID: BinaryFormatCode,
OIDOID: BinaryFormatCode,
RecordOID: BinaryFormatCode,
TextArrayOID: BinaryFormatCode,
TimestampArrayOID: BinaryFormatCode,
TimestampOID: BinaryFormatCode,
TimestampTzArrayOID: BinaryFormatCode,
TimestampTzOID: BinaryFormatCode,
VarcharArrayOID: BinaryFormatCode,
internalNativeGoTypeFormats = map[Oid]int16{
BoolArrayOid: BinaryFormatCode,
BoolOid: BinaryFormatCode,
ByteaArrayOid: BinaryFormatCode,
ByteaOid: BinaryFormatCode,
CidrArrayOid: BinaryFormatCode,
CidrOid: BinaryFormatCode,
DateOid: BinaryFormatCode,
Float4ArrayOid: BinaryFormatCode,
Float4Oid: BinaryFormatCode,
Float8ArrayOid: BinaryFormatCode,
Float8Oid: BinaryFormatCode,
InetArrayOid: BinaryFormatCode,
InetOid: BinaryFormatCode,
Int2ArrayOid: BinaryFormatCode,
Int2Oid: BinaryFormatCode,
Int4ArrayOid: BinaryFormatCode,
Int4Oid: BinaryFormatCode,
Int8ArrayOid: BinaryFormatCode,
Int8Oid: BinaryFormatCode,
JsonbOid: BinaryFormatCode,
JsonOid: BinaryFormatCode,
OidOid: BinaryFormatCode,
RecordOid: BinaryFormatCode,
TextArrayOid: BinaryFormatCode,
TimestampArrayOid: BinaryFormatCode,
TimestampOid: BinaryFormatCode,
TimestampTzArrayOid: BinaryFormatCode,
TimestampTzOid: BinaryFormatCode,
VarcharArrayOid: BinaryFormatCode,
}
}
@@ -164,7 +164,7 @@ func (e SerializationError) Error() string {
// server. To allow types to support pgx and database/sql.Scan this interface
// has been deprecated in favor of PgxScanner.
type Scanner interface {
// Scan MUST check r.Type().DataType (to check by OID) or
// Scan MUST check r.Type().DataType (to check by Oid) or
// r.Type().DataTypeName (to check by name) to ensure that it is scanning an
// expected column type. It also MUST check r.Type().FormatCode before
// decoding. It should not assume that it was called on a data type or format
@@ -176,7 +176,7 @@ type Scanner interface {
// It is used exactly the same as the Scanner interface. It simply has renamed
// the method.
type PgxScanner interface {
// ScanPgx MUST check r.Type().DataType (to check by OID) or
// ScanPgx MUST check r.Type().DataType (to check by Oid) or
// r.Type().DataTypeName (to check by name) to ensure that it is scanning an
// expected column type. It also MUST check r.Type().FormatCode before
// decoding. It should not assume that it was called on a data type or format
@@ -196,7 +196,7 @@ type Encoder interface {
// expected data size or format of the encoded data does not match. But if
// the encoded data is a valid representation of the data type PostgreSQL
// expects such as date and int4, incorrect data may be stored.
Encode(w *WriteBuf, oid OID) error
Encode(w *WriteBuf, oid Oid) error
// FormatCode returns the format that the encoder writes the value. It must be
// either pgx.TextFormatCode or pgx.BinaryFormatCode.
@@ -214,8 +214,8 @@ type NullFloat32 struct {
}
func (n *NullFloat32) Scan(vr *ValueReader) error {
if vr.Type().DataType != Float4OID {
return SerializationError(fmt.Sprintf("NullFloat32.Scan cannot decode OID %d", vr.Type().DataType))
if vr.Type().DataType != Float4Oid {
return SerializationError(fmt.Sprintf("NullFloat32.Scan cannot decode Oid %d", vr.Type().DataType))
}
if vr.Len() == -1 {
@@ -229,9 +229,9 @@ func (n *NullFloat32) Scan(vr *ValueReader) error {
func (n NullFloat32) FormatCode() int16 { return BinaryFormatCode }
func (n NullFloat32) Encode(w *WriteBuf, oid OID) error {
if oid != Float4OID {
return SerializationError(fmt.Sprintf("NullFloat32.Encode cannot encode into OID %d", oid))
func (n NullFloat32) Encode(w *WriteBuf, oid Oid) error {
if oid != Float4Oid {
return SerializationError(fmt.Sprintf("NullFloat32.Encode cannot encode into Oid %d", oid))
}
if !n.Valid {
@@ -253,8 +253,8 @@ type NullFloat64 struct {
}
func (n *NullFloat64) Scan(vr *ValueReader) error {
if vr.Type().DataType != Float8OID {
return SerializationError(fmt.Sprintf("NullFloat64.Scan cannot decode OID %d", vr.Type().DataType))
if vr.Type().DataType != Float8Oid {
return SerializationError(fmt.Sprintf("NullFloat64.Scan cannot decode Oid %d", vr.Type().DataType))
}
if vr.Len() == -1 {
@@ -268,9 +268,9 @@ func (n *NullFloat64) Scan(vr *ValueReader) error {
func (n NullFloat64) FormatCode() int16 { return BinaryFormatCode }
func (n NullFloat64) Encode(w *WriteBuf, oid OID) error {
if oid != Float8OID {
return SerializationError(fmt.Sprintf("NullFloat64.Encode cannot encode into OID %d", oid))
func (n NullFloat64) Encode(w *WriteBuf, oid Oid) error {
if oid != Float8Oid {
return SerializationError(fmt.Sprintf("NullFloat64.Encode cannot encode into Oid %d", oid))
}
if !n.Valid {
@@ -306,7 +306,7 @@ func (n *NullString) Scan(vr *ValueReader) error {
func (n NullString) FormatCode() int16 { return TextFormatCode }
func (s NullString) Encode(w *WriteBuf, oid OID) error {
func (s NullString) Encode(w *WriteBuf, oid Oid) error {
if !s.Valid {
w.WriteInt32(-1)
return nil
@@ -326,8 +326,8 @@ type NullInt16 struct {
}
func (n *NullInt16) Scan(vr *ValueReader) error {
if vr.Type().DataType != Int2OID {
return SerializationError(fmt.Sprintf("NullInt16.Scan cannot decode OID %d", vr.Type().DataType))
if vr.Type().DataType != Int2Oid {
return SerializationError(fmt.Sprintf("NullInt16.Scan cannot decode Oid %d", vr.Type().DataType))
}
if vr.Len() == -1 {
@@ -341,9 +341,9 @@ func (n *NullInt16) Scan(vr *ValueReader) error {
func (n NullInt16) FormatCode() int16 { return BinaryFormatCode }
func (n NullInt16) Encode(w *WriteBuf, oid OID) error {
if oid != Int2OID {
return SerializationError(fmt.Sprintf("NullInt16.Encode cannot encode into OID %d", oid))
func (n NullInt16) Encode(w *WriteBuf, oid Oid) error {
if oid != Int2Oid {
return SerializationError(fmt.Sprintf("NullInt16.Encode cannot encode into Oid %d", oid))
}
if !n.Valid {
@@ -368,8 +368,8 @@ type NullInt32 struct {
}
func (n *NullInt32) Scan(vr *ValueReader) error {
if vr.Type().DataType != Int4OID {
return SerializationError(fmt.Sprintf("NullInt32.Scan cannot decode OID %d", vr.Type().DataType))
if vr.Type().DataType != Int4Oid {
return SerializationError(fmt.Sprintf("NullInt32.Scan cannot decode Oid %d", vr.Type().DataType))
}
if vr.Len() == -1 {
@@ -383,9 +383,9 @@ func (n *NullInt32) Scan(vr *ValueReader) error {
func (n NullInt32) FormatCode() int16 { return BinaryFormatCode }
func (n NullInt32) Encode(w *WriteBuf, oid OID) error {
if oid != Int4OID {
return SerializationError(fmt.Sprintf("NullInt32.Encode cannot encode into OID %d", oid))
func (n NullInt32) Encode(w *WriteBuf, oid Oid) error {
if oid != Int4Oid {
return SerializationError(fmt.Sprintf("NullInt32.Encode cannot encode into Oid %d", oid))
}
if !n.Valid {
@@ -399,15 +399,15 @@ func (n NullInt32) Encode(w *WriteBuf, oid OID) error {
return err
}
// OID (Object Identifier Type) is, according to https://www.postgresql.org/docs/current/static/datatype-oid.html,
// Oid (Object Identifier Type) is, according to https://www.postgresql.org/docs/current/static/datatype-oid.html,
// used internally by PostgreSQL as a primary key for various system tables. It is currently implemented
// as an unsigned four-byte integer. Its definition can be found in src/include/postgres_ext.h
// in the PostgreSQL sources. OID cannot be NULL. To allow for NULL OIDs use pgtype.OID.
type OID uint32
// in the PostgreSQL sources. Oid cannot be NULL. To allow for NULL Oids use pgtype.Oid.
type Oid uint32
func (dst *OID) DecodeText(src []byte) error {
func (dst *Oid) DecodeText(src []byte) error {
if src == nil {
return fmt.Errorf("cannot decode nil into OID")
return fmt.Errorf("cannot decode nil into Oid")
}
n, err := strconv.ParseUint(string(src), 10, 32)
@@ -415,13 +415,13 @@ func (dst *OID) DecodeText(src []byte) error {
return err
}
*dst = OID(n)
*dst = Oid(n)
return nil
}
func (dst *OID) DecodeBinary(src []byte) error {
func (dst *Oid) DecodeBinary(src []byte) error {
if src == nil {
return fmt.Errorf("cannot decode nil into OID")
return fmt.Errorf("cannot decode nil into Oid")
}
if len(src) != 4 {
@@ -429,16 +429,16 @@ func (dst *OID) DecodeBinary(src []byte) error {
}
n := binary.BigEndian.Uint32(src)
*dst = OID(n)
*dst = Oid(n)
return nil
}
func (src OID) EncodeText(w io.Writer) (bool, error) {
func (src Oid) EncodeText(w io.Writer) (bool, error) {
_, err := io.WriteString(w, strconv.FormatUint(uint64(src), 10))
return false, err
}
func (src OID) EncodeBinary(w io.Writer) (bool, error) {
func (src Oid) EncodeBinary(w io.Writer) (bool, error) {
_, err := pgio.WriteUint32(w, uint32(src))
return false, err
}
@@ -454,8 +454,8 @@ type NullInt64 struct {
}
func (n *NullInt64) Scan(vr *ValueReader) error {
if vr.Type().DataType != Int8OID {
return SerializationError(fmt.Sprintf("NullInt64.Scan cannot decode OID %d", vr.Type().DataType))
if vr.Type().DataType != Int8Oid {
return SerializationError(fmt.Sprintf("NullInt64.Scan cannot decode Oid %d", vr.Type().DataType))
}
if vr.Len() == -1 {
@@ -469,9 +469,9 @@ func (n *NullInt64) Scan(vr *ValueReader) error {
func (n NullInt64) FormatCode() int16 { return BinaryFormatCode }
func (n NullInt64) Encode(w *WriteBuf, oid OID) error {
if oid != Int8OID {
return SerializationError(fmt.Sprintf("NullInt64.Encode cannot encode into OID %d", oid))
func (n NullInt64) Encode(w *WriteBuf, oid Oid) error {
if oid != Int8Oid {
return SerializationError(fmt.Sprintf("NullInt64.Encode cannot encode into Oid %d", oid))
}
if !n.Valid {
@@ -496,8 +496,8 @@ type NullBool struct {
}
func (n *NullBool) Scan(vr *ValueReader) error {
if vr.Type().DataType != BoolOID {
return SerializationError(fmt.Sprintf("NullBool.Scan cannot decode OID %d", vr.Type().DataType))
if vr.Type().DataType != BoolOid {
return SerializationError(fmt.Sprintf("NullBool.Scan cannot decode Oid %d", vr.Type().DataType))
}
if vr.Len() == -1 {
@@ -511,9 +511,9 @@ func (n *NullBool) Scan(vr *ValueReader) error {
func (n NullBool) FormatCode() int16 { return BinaryFormatCode }
func (n NullBool) Encode(w *WriteBuf, oid OID) error {
if oid != BoolOID {
return SerializationError(fmt.Sprintf("NullBool.Encode cannot encode into OID %d", oid))
func (n NullBool) Encode(w *WriteBuf, oid Oid) error {
if oid != BoolOid {
return SerializationError(fmt.Sprintf("NullBool.Encode cannot encode into Oid %d", oid))
}
if !n.Valid {
@@ -540,8 +540,8 @@ type NullTime struct {
func (n *NullTime) Scan(vr *ValueReader) error {
oid := vr.Type().DataType
if oid != TimestampTzOID && oid != TimestampOID && oid != DateOID {
return SerializationError(fmt.Sprintf("NullTime.Scan cannot decode OID %d", vr.Type().DataType))
if oid != TimestampTzOid && oid != TimestampOid && oid != DateOid {
return SerializationError(fmt.Sprintf("NullTime.Scan cannot decode Oid %d", vr.Type().DataType))
}
if vr.Len() == -1 {
@@ -551,11 +551,11 @@ func (n *NullTime) Scan(vr *ValueReader) error {
n.Valid = true
switch oid {
case TimestampTzOID:
case TimestampTzOid:
n.Time = decodeTimestampTz(vr)
case TimestampOID:
case TimestampOid:
n.Time = decodeTimestamp(vr)
case DateOID:
case DateOid:
n.Time = decodeDate(vr)
}
@@ -564,9 +564,9 @@ func (n *NullTime) Scan(vr *ValueReader) error {
func (n NullTime) FormatCode() int16 { return BinaryFormatCode }
func (n NullTime) Encode(w *WriteBuf, oid OID) error {
if oid != TimestampTzOID && oid != TimestampOID && oid != DateOID {
return SerializationError(fmt.Sprintf("NullTime.Encode cannot encode into OID %d", oid))
func (n NullTime) Encode(w *WriteBuf, oid Oid) error {
if oid != TimestampTzOid && oid != TimestampOid && oid != DateOid {
return SerializationError(fmt.Sprintf("NullTime.Encode cannot encode into Oid %d", oid))
}
if !n.Valid {
@@ -616,7 +616,7 @@ func (h *Hstore) Scan(vr *ValueReader) error {
func (h Hstore) FormatCode() int16 { return TextFormatCode }
func (h Hstore) Encode(w *WriteBuf, oid OID) error {
func (h Hstore) Encode(w *WriteBuf, oid Oid) error {
var buf bytes.Buffer
i := 0
@@ -682,7 +682,7 @@ func (h *NullHstore) Scan(vr *ValueReader) error {
func (h NullHstore) FormatCode() int16 { return TextFormatCode }
func (h NullHstore) Encode(w *WriteBuf, oid OID) error {
func (h NullHstore) Encode(w *WriteBuf, oid Oid) error {
var buf bytes.Buffer
if !h.Valid {
@@ -714,7 +714,7 @@ func (h NullHstore) Encode(w *WriteBuf, oid OID) error {
// Encode encodes arg into wbuf as the type oid. This allows implementations
// of the Encoder interface to delegate the actual work of encoding to the
// built-in functionality.
func Encode(wbuf *WriteBuf, oid OID, arg interface{}) error {
func Encode(wbuf *WriteBuf, oid Oid, arg interface{}) error {
if arg == nil {
wbuf.WriteInt32(-1)
return nil
@@ -772,10 +772,10 @@ func Encode(wbuf *WriteBuf, oid OID, arg interface{}) error {
return Encode(wbuf, oid, arg)
}
if oid == JSONOID {
if oid == JsonOid {
return encodeJSON(wbuf, oid, arg)
}
if oid == JSONBOID {
if oid == JsonbOid {
return encodeJSONB(wbuf, oid, arg)
}
@@ -890,7 +890,7 @@ func Decode(vr *ValueReader, d interface{}) error {
}
func decodeBool(vr *ValueReader) bool {
if vr.Type().DataType != BoolOID {
if vr.Type().DataType != BoolOid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into bool", vr.Type().DataType)))
return false
}
@@ -922,11 +922,11 @@ func decodeBool(vr *ValueReader) bool {
func decodeInt(vr *ValueReader) int64 {
switch vr.Type().DataType {
case Int2OID:
case Int2Oid:
return int64(decodeInt2(vr))
case Int4OID:
case Int4Oid:
return int64(decodeInt4(vr))
case Int8OID:
case Int8Oid:
return int64(decodeInt8(vr))
}
@@ -940,7 +940,7 @@ func decodeInt8(vr *ValueReader) int64 {
return 0
}
if vr.Type().DataType != Int8OID {
if vr.Type().DataType != Int8Oid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into int8", vr.Type().DataType)))
return 0
}
@@ -972,7 +972,7 @@ func decodeInt8(vr *ValueReader) int64 {
func decodeInt2(vr *ValueReader) int16 {
if vr.Type().DataType != Int2OID {
if vr.Type().DataType != Int2Oid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into int16", vr.Type().DataType)))
return 0
}
@@ -1008,7 +1008,7 @@ func decodeInt4(vr *ValueReader) int32 {
return 0
}
if vr.Type().DataType != Int4OID {
if vr.Type().DataType != Int4Oid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into int32", vr.Type().DataType)))
return 0
}
@@ -1044,7 +1044,7 @@ func decodeFloat4(vr *ValueReader) float32 {
return 0
}
if vr.Type().DataType != Float4OID {
if vr.Type().DataType != Float4Oid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into float32", vr.Type().DataType)))
return 0
}
@@ -1063,12 +1063,12 @@ func decodeFloat4(vr *ValueReader) float32 {
return math.Float32frombits(uint32(i))
}
func encodeFloat32(w *WriteBuf, oid OID, value float32) error {
func encodeFloat32(w *WriteBuf, oid Oid, value float32) error {
switch oid {
case Float4OID:
case Float4Oid:
w.WriteInt32(4)
w.WriteInt32(int32(math.Float32bits(value)))
case Float8OID:
case Float8Oid:
w.WriteInt32(8)
w.WriteInt64(int64(math.Float64bits(float64(value))))
default:
@@ -1084,7 +1084,7 @@ func decodeFloat8(vr *ValueReader) float64 {
return 0
}
if vr.Type().DataType != Float8OID {
if vr.Type().DataType != Float8Oid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into float64", vr.Type().DataType)))
return 0
}
@@ -1103,9 +1103,9 @@ func decodeFloat8(vr *ValueReader) float64 {
return math.Float64frombits(uint64(i))
}
func encodeFloat64(w *WriteBuf, oid OID, value float64) error {
func encodeFloat64(w *WriteBuf, oid Oid, value float64) error {
switch oid {
case Float8OID:
case Float8Oid:
w.WriteInt32(8)
w.WriteInt64(int64(math.Float64bits(value)))
default:
@@ -1138,7 +1138,7 @@ func decodeTextAllowBinary(vr *ValueReader) string {
return vr.ReadString(vr.Len())
}
func encodeString(w *WriteBuf, oid OID, value string) error {
func encodeString(w *WriteBuf, oid Oid, value string) error {
w.WriteInt32(int32(len(value)))
w.WriteBytes([]byte(value))
return nil
@@ -1149,7 +1149,7 @@ func decodeBytea(vr *ValueReader) []byte {
return nil
}
if vr.Type().DataType != ByteaOID {
if vr.Type().DataType != ByteaOid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []byte", vr.Type().DataType)))
return nil
}
@@ -1162,7 +1162,7 @@ func decodeBytea(vr *ValueReader) []byte {
return vr.ReadBytes(vr.Len())
}
func encodeByteSlice(w *WriteBuf, oid OID, value []byte) error {
func encodeByteSlice(w *WriteBuf, oid Oid, value []byte) error {
w.WriteInt32(int32(len(value)))
w.WriteBytes(value)
@@ -1174,7 +1174,7 @@ func decodeJSON(vr *ValueReader, d interface{}) error {
return nil
}
if vr.Type().DataType != JSONOID {
if vr.Type().DataType != JsonOid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into json", vr.Type().DataType)))
}
@@ -1186,8 +1186,8 @@ func decodeJSON(vr *ValueReader, d interface{}) error {
return err
}
func encodeJSON(w *WriteBuf, oid OID, value interface{}) error {
if oid != JSONOID {
func encodeJSON(w *WriteBuf, oid Oid, value interface{}) error {
if oid != JsonOid {
return fmt.Errorf("cannot encode JSON into oid %v", oid)
}
@@ -1207,7 +1207,7 @@ func decodeJSONB(vr *ValueReader, d interface{}) error {
return nil
}
if vr.Type().DataType != JSONBOID {
if vr.Type().DataType != JsonbOid {
err := ProtocolError(fmt.Sprintf("Cannot decode oid %v into jsonb", vr.Type().DataType))
vr.Fatal(err)
return err
@@ -1230,8 +1230,8 @@ func decodeJSONB(vr *ValueReader, d interface{}) error {
return err
}
func encodeJSONB(w *WriteBuf, oid OID, value interface{}) error {
if oid != JSONBOID {
func encodeJSONB(w *WriteBuf, oid Oid, value interface{}) error {
if oid != JsonbOid {
return fmt.Errorf("cannot encode JSON into oid %v", oid)
}
@@ -1248,7 +1248,7 @@ func encodeJSONB(w *WriteBuf, oid OID, value interface{}) error {
}
func decodeDate(vr *ValueReader) time.Time {
if vr.Type().DataType != DateOID {
if vr.Type().DataType != DateOid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into time.Time", vr.Type().DataType)))
return time.Time{}
}
@@ -1278,9 +1278,9 @@ func decodeDate(vr *ValueReader) time.Time {
return d.Time
}
func encodeTime(w *WriteBuf, oid OID, value time.Time) error {
func encodeTime(w *WriteBuf, oid Oid, value time.Time) error {
switch oid {
case DateOID:
case DateOid:
var d pgtype.Date
err := d.ConvertFrom(value)
if err != nil {
@@ -1300,7 +1300,7 @@ func encodeTime(w *WriteBuf, oid OID, value time.Time) error {
}
return nil
case TimestampTzOID, TimestampOID:
case TimestampTzOid, TimestampOid:
var t pgtype.Timestamptz
err := t.ConvertFrom(value)
if err != nil {
@@ -1334,7 +1334,7 @@ func decodeTimestampTz(vr *ValueReader) time.Time {
return zeroTime
}
if vr.Type().DataType != TimestampTzOID {
if vr.Type().DataType != TimestampTzOid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into time.Time", vr.Type().DataType)))
return zeroTime
}
@@ -1372,7 +1372,7 @@ func decodeTimestamp(vr *ValueReader) time.Time {
return zeroTime
}
if vr.Type().DataType != TimestampOID {
if vr.Type().DataType != TimestampOid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into time.Time", vr.Type().DataType)))
return zeroTime
}
@@ -1402,7 +1402,7 @@ func decodeRecord(vr *ValueReader) []interface{} {
return nil
}
if vr.Type().DataType != RecordOID {
if vr.Type().DataType != RecordOid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []interface{}", vr.Type().DataType)))
return nil
}
@@ -1413,32 +1413,32 @@ func decodeRecord(vr *ValueReader) []interface{} {
for i := int32(0); i < valueCount; i++ {
fd := FieldDescription{FormatCode: BinaryFormatCode}
fieldVR := ValueReader{mr: vr.mr, fd: &fd}
fd.DataType = vr.ReadOID()
fd.DataType = vr.ReadOid()
fieldVR.valueBytesRemaining = vr.ReadInt32()
vr.valueBytesRemaining -= fieldVR.valueBytesRemaining
switch fd.DataType {
case BoolOID:
case BoolOid:
record = append(record, decodeBool(&fieldVR))
case ByteaOID:
case ByteaOid:
record = append(record, decodeBytea(&fieldVR))
case Int8OID:
case Int8Oid:
record = append(record, decodeInt8(&fieldVR))
case Int2OID:
case Int2Oid:
record = append(record, decodeInt2(&fieldVR))
case Int4OID:
case Int4Oid:
record = append(record, decodeInt4(&fieldVR))
case Float4OID:
case Float4Oid:
record = append(record, decodeFloat4(&fieldVR))
case Float8OID:
case Float8Oid:
record = append(record, decodeFloat8(&fieldVR))
case DateOID:
case DateOid:
record = append(record, decodeDate(&fieldVR))
case TimestampTzOID:
case TimestampTzOid:
record = append(record, decodeTimestampTz(&fieldVR))
case TimestampOID:
case TimestampOid:
record = append(record, decodeTimestamp(&fieldVR))
case TextOID, VarcharOID, UnknownOID:
case TextOid, VarcharOid, UnknownOid:
record = append(record, decodeTextAllowBinary(&fieldVR))
default:
vr.Fatal(fmt.Errorf("decodeRecord cannot decode oid %d", fd.DataType))
+56 -56
View File
@@ -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
}
@@ -232,7 +232,7 @@ func testJSONStruct(t *testing.T, conn *pgx.Conn, typename string, format int16)
}
}
func mustParseCIDR(t *testing.T, s string) *net.IPNet {
func mustParseCidr(t *testing.T, s string) *net.IPNet {
_, ipnet, err := net.ParseCIDR(s)
if err != nil {
t.Fatal(err)
@@ -277,26 +277,26 @@ func TestInetCidrTranscodeIPNet(t *testing.T) {
sql string
value *net.IPNet
}{
{"select $1::inet", mustParseCIDR(t, "0.0.0.0/32")},
{"select $1::inet", mustParseCIDR(t, "127.0.0.1/32")},
{"select $1::inet", mustParseCIDR(t, "12.34.56.0/32")},
{"select $1::inet", mustParseCIDR(t, "192.168.1.0/24")},
{"select $1::inet", mustParseCIDR(t, "255.0.0.0/8")},
{"select $1::inet", mustParseCIDR(t, "255.255.255.255/32")},
{"select $1::inet", mustParseCIDR(t, "::/128")},
{"select $1::inet", mustParseCIDR(t, "::/0")},
{"select $1::inet", mustParseCIDR(t, "::1/128")},
{"select $1::inet", mustParseCIDR(t, "2607:f8b0:4009:80b::200e/128")},
{"select $1::cidr", mustParseCIDR(t, "0.0.0.0/32")},
{"select $1::cidr", mustParseCIDR(t, "127.0.0.1/32")},
{"select $1::cidr", mustParseCIDR(t, "12.34.56.0/32")},
{"select $1::cidr", mustParseCIDR(t, "192.168.1.0/24")},
{"select $1::cidr", mustParseCIDR(t, "255.0.0.0/8")},
{"select $1::cidr", mustParseCIDR(t, "255.255.255.255/32")},
{"select $1::cidr", mustParseCIDR(t, "::/128")},
{"select $1::cidr", mustParseCIDR(t, "::/0")},
{"select $1::cidr", mustParseCIDR(t, "::1/128")},
{"select $1::cidr", mustParseCIDR(t, "2607:f8b0:4009:80b::200e/128")},
{"select $1::inet", mustParseCidr(t, "0.0.0.0/32")},
{"select $1::inet", mustParseCidr(t, "127.0.0.1/32")},
{"select $1::inet", mustParseCidr(t, "12.34.56.0/32")},
{"select $1::inet", mustParseCidr(t, "192.168.1.0/24")},
{"select $1::inet", mustParseCidr(t, "255.0.0.0/8")},
{"select $1::inet", mustParseCidr(t, "255.255.255.255/32")},
{"select $1::inet", mustParseCidr(t, "::/128")},
{"select $1::inet", mustParseCidr(t, "::/0")},
{"select $1::inet", mustParseCidr(t, "::1/128")},
{"select $1::inet", mustParseCidr(t, "2607:f8b0:4009:80b::200e/128")},
{"select $1::cidr", mustParseCidr(t, "0.0.0.0/32")},
{"select $1::cidr", mustParseCidr(t, "127.0.0.1/32")},
{"select $1::cidr", mustParseCidr(t, "12.34.56.0/32")},
{"select $1::cidr", mustParseCidr(t, "192.168.1.0/24")},
{"select $1::cidr", mustParseCidr(t, "255.0.0.0/8")},
{"select $1::cidr", mustParseCidr(t, "255.255.255.255/32")},
{"select $1::cidr", mustParseCidr(t, "::/128")},
{"select $1::cidr", mustParseCidr(t, "::/0")},
{"select $1::cidr", mustParseCidr(t, "::1/128")},
{"select $1::cidr", mustParseCidr(t, "2607:f8b0:4009:80b::200e/128")},
}
for i, tt := range tests {
@@ -360,8 +360,8 @@ func TestInetCidrTranscodeIP(t *testing.T) {
sql string
value *net.IPNet
}{
{"select $1::inet", mustParseCIDR(t, "192.168.1.0/24")},
{"select $1::cidr", mustParseCIDR(t, "192.168.1.0/24")},
{"select $1::inet", mustParseCidr(t, "192.168.1.0/24")},
{"select $1::cidr", mustParseCidr(t, "192.168.1.0/24")},
}
for i, tt := range failTests {
var actual net.IP
@@ -389,31 +389,31 @@ func TestInetCidrArrayTranscodeIPNet(t *testing.T) {
{
"select $1::inet[]",
[]*net.IPNet{
mustParseCIDR(t, "0.0.0.0/32"),
mustParseCIDR(t, "127.0.0.1/32"),
mustParseCIDR(t, "12.34.56.0/32"),
mustParseCIDR(t, "192.168.1.0/24"),
mustParseCIDR(t, "255.0.0.0/8"),
mustParseCIDR(t, "255.255.255.255/32"),
mustParseCIDR(t, "::/128"),
mustParseCIDR(t, "::/0"),
mustParseCIDR(t, "::1/128"),
mustParseCIDR(t, "2607:f8b0:4009:80b::200e/128"),
mustParseCidr(t, "0.0.0.0/32"),
mustParseCidr(t, "127.0.0.1/32"),
mustParseCidr(t, "12.34.56.0/32"),
mustParseCidr(t, "192.168.1.0/24"),
mustParseCidr(t, "255.0.0.0/8"),
mustParseCidr(t, "255.255.255.255/32"),
mustParseCidr(t, "::/128"),
mustParseCidr(t, "::/0"),
mustParseCidr(t, "::1/128"),
mustParseCidr(t, "2607:f8b0:4009:80b::200e/128"),
},
},
{
"select $1::cidr[]",
[]*net.IPNet{
mustParseCIDR(t, "0.0.0.0/32"),
mustParseCIDR(t, "127.0.0.1/32"),
mustParseCIDR(t, "12.34.56.0/32"),
mustParseCIDR(t, "192.168.1.0/24"),
mustParseCIDR(t, "255.0.0.0/8"),
mustParseCIDR(t, "255.255.255.255/32"),
mustParseCIDR(t, "::/128"),
mustParseCIDR(t, "::/0"),
mustParseCIDR(t, "::1/128"),
mustParseCIDR(t, "2607:f8b0:4009:80b::200e/128"),
mustParseCidr(t, "0.0.0.0/32"),
mustParseCidr(t, "127.0.0.1/32"),
mustParseCidr(t, "12.34.56.0/32"),
mustParseCidr(t, "192.168.1.0/24"),
mustParseCidr(t, "255.0.0.0/8"),
mustParseCidr(t, "255.255.255.255/32"),
mustParseCidr(t, "::/128"),
mustParseCidr(t, "::/0"),
mustParseCidr(t, "::1/128"),
mustParseCidr(t, "2607:f8b0:4009:80b::200e/128"),
},
},
}
@@ -490,15 +490,15 @@ func TestInetCidrArrayTranscodeIP(t *testing.T) {
{
"select $1::inet[]",
[]*net.IPNet{
mustParseCIDR(t, "12.34.56.0/32"),
mustParseCIDR(t, "192.168.1.0/24"),
mustParseCidr(t, "12.34.56.0/32"),
mustParseCidr(t, "192.168.1.0/24"),
},
},
{
"select $1::cidr[]",
[]*net.IPNet{
mustParseCIDR(t, "12.34.56.0/32"),
mustParseCIDR(t, "192.168.1.0/24"),
mustParseCidr(t, "12.34.56.0/32"),
mustParseCidr(t, "192.168.1.0/24"),
},
},
}
@@ -541,7 +541,7 @@ func TestInetCidrTranscodeWithJustIP(t *testing.T) {
}
for i, tt := range tests {
expected := mustParseCIDR(t, tt.value)
expected := mustParseCidr(t, tt.value)
var actual net.IPNet
err := conn.QueryRow(tt.sql, expected.IP).Scan(&actual)
@@ -840,13 +840,13 @@ func TestNullXMismatch(t *testing.T) {
err string
}{
{"select $1::date", []interface{}{pgx.NullString{String: "foo", Valid: true}}, []interface{}{&actual.s}, "invalid input syntax for type date"},
{"select $1::date", []interface{}{pgx.NullInt16{Int16: 1, Valid: true}}, []interface{}{&actual.i16}, "cannot encode into OID 1082"},
{"select $1::date", []interface{}{pgx.NullInt32{Int32: 1, Valid: true}}, []interface{}{&actual.i32}, "cannot encode into OID 1082"},
{"select $1::date", []interface{}{pgx.NullInt64{Int64: 1, Valid: true}}, []interface{}{&actual.i64}, "cannot encode into OID 1082"},
{"select $1::date", []interface{}{pgx.NullFloat32{Float32: 1.23, Valid: true}}, []interface{}{&actual.f32}, "cannot encode into OID 1082"},
{"select $1::date", []interface{}{pgx.NullFloat64{Float64: 1.23, Valid: true}}, []interface{}{&actual.f64}, "cannot encode into OID 1082"},
{"select $1::date", []interface{}{pgx.NullBool{Bool: true, Valid: true}}, []interface{}{&actual.b}, "cannot encode into OID 1082"},
{"select $1::int4", []interface{}{pgx.NullTime{Time: time.Unix(123, 5000), Valid: true}}, []interface{}{&actual.t}, "cannot encode into OID 23"},
{"select $1::date", []interface{}{pgx.NullInt16{Int16: 1, Valid: true}}, []interface{}{&actual.i16}, "cannot encode into Oid 1082"},
{"select $1::date", []interface{}{pgx.NullInt32{Int32: 1, Valid: true}}, []interface{}{&actual.i32}, "cannot encode into Oid 1082"},
{"select $1::date", []interface{}{pgx.NullInt64{Int64: 1, Valid: true}}, []interface{}{&actual.i64}, "cannot encode into Oid 1082"},
{"select $1::date", []interface{}{pgx.NullFloat32{Float32: 1.23, Valid: true}}, []interface{}{&actual.f32}, "cannot encode into Oid 1082"},
{"select $1::date", []interface{}{pgx.NullFloat64{Float64: 1.23, Valid: true}}, []interface{}{&actual.f64}, "cannot encode into Oid 1082"},
{"select $1::date", []interface{}{pgx.NullBool{Bool: true, Valid: true}}, []interface{}{&actual.b}, "cannot encode into Oid 1082"},
{"select $1::int4", []interface{}{pgx.NullTime{Time: time.Unix(123, 5000), Valid: true}}, []interface{}{&actual.t}, "cannot encode into Oid 23"},
}
for i, tt := range tests {