Skip to content

Commit

Permalink
Use Go casing convention for OID
Browse files Browse the repository at this point in the history
  • Loading branch information
jackc committed Jun 3, 2017
1 parent 071de0b commit 2140814
Show file tree
Hide file tree
Showing 23 changed files with 119 additions and 119 deletions.
6 changes: 3 additions & 3 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

type ArrayHeader struct {
ContainsNull bool
ElementOid int32
ElementOID int32
Dimensions []ArrayDimension
}

Expand All @@ -40,7 +40,7 @@ func (dst *ArrayHeader) DecodeBinary(ci *ConnInfo, 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 {
Expand Down Expand Up @@ -69,7 +69,7 @@ func (src *ArrayHeader) EncodeBinary(ci *ConnInfo, buf []byte) []byte {
}
buf = pgio.AppendInt32(buf, containsNull)

buf = pgio.AppendInt32(buf, src.ElementOid)
buf = pgio.AppendInt32(buf, src.ElementOID)

for i := range src.Dimensions {
buf = pgio.AppendInt32(buf, src.Dimensions[i].Length)
Expand Down
2 changes: 1 addition & 1 deletion bool_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (src *BoolArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("bool"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "bool")
}
Expand Down
2 changes: 1 addition & 1 deletion bytea_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (src *ByteaArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("bytea"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "bytea")
}
Expand Down
2 changes: 1 addition & 1 deletion cidr_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (src *CidrArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("cidr"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "cidr")
}
Expand Down
2 changes: 1 addition & 1 deletion date_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (src *DateArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("date"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "date")
}
Expand Down
2 changes: 1 addition & 1 deletion float4_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (src *Float4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("float4"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "float4")
}
Expand Down
2 changes: 1 addition & 1 deletion float8_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (src *Float8Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("float8"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "float8")
}
Expand Down
2 changes: 1 addition & 1 deletion hstore_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (src *HstoreArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("hstore"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "hstore")
}
Expand Down
2 changes: 1 addition & 1 deletion inet_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (src *InetArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("inet"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "inet")
}
Expand Down
2 changes: 1 addition & 1 deletion int2_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (src *Int2Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("int2"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "int2")
}
Expand Down
2 changes: 1 addition & 1 deletion int4_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (src *Int4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("int4"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "int4")
}
Expand Down
2 changes: 1 addition & 1 deletion int8_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (src *Int8Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
}

if dt, ok := ci.DataTypeForName("int8"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "int8")
}
Expand Down
2 changes: 1 addition & 1 deletion numeric_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (src *NumericArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error)
}

if dt, ok := ci.DataTypeForName("numeric"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
arrayHeader.ElementOID = int32(dt.OID)
} else {
return nil, fmt.Errorf("unable to find oid for type name %v", "numeric")
}
Expand Down
30 changes: 15 additions & 15 deletions oid.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,60 @@ import (
"github.com/jackc/pgx/pgio"
)

// 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. Because it is
// so frequently required to be in a NOT NULL condition Oid cannot be NULL. To
// allow for NULL Oids use OidValue.
type Oid uint32
// so frequently required to be in a NOT NULL condition OID cannot be NULL. To
// allow for NULL OIDs use OIDValue.
type OID uint32

func (dst *Oid) DecodeText(ci *ConnInfo, src []byte) error {
func (dst *OID) DecodeText(ci *ConnInfo, 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)
if err != nil {
return err
}

*dst = Oid(n)
*dst = OID(n)
return nil
}

func (dst *Oid) DecodeBinary(ci *ConnInfo, src []byte) error {
func (dst *OID) DecodeBinary(ci *ConnInfo, 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 {
return fmt.Errorf("invalid length: %v", len(src))
}

n := binary.BigEndian.Uint32(src)
*dst = Oid(n)
*dst = OID(n)
return nil
}

func (src Oid) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
func (src OID) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
return append(buf, strconv.FormatUint(uint64(src), 10)...), nil
}

func (src Oid) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
func (src OID) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
return pgio.AppendUint32(buf, uint32(src)), nil
}

// Scan implements the database/sql Scanner interface.
func (dst *Oid) Scan(src interface{}) error {
func (dst *OID) Scan(src interface{}) error {
if src == nil {
return fmt.Errorf("cannot scan NULL into %T", src)
}

switch src := src.(type) {
case int64:
*dst = Oid(src)
*dst = OID(src)
return nil
case string:
return dst.DecodeText(nil, []byte(src))
Expand All @@ -76,6 +76,6 @@ func (dst *Oid) Scan(src interface{}) error {
}

// Value implements the database/sql/driver Valuer interface.
func (src Oid) Value() (driver.Value, error) {
func (src OID) Value() (driver.Value, error) {
return int64(src), nil
}
28 changes: 14 additions & 14 deletions oid_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,52 @@ import (
"database/sql/driver"
)

// OidValue (Object Identifier Type) is, according to
// https://www.postgresql.org/docs/current/static/datatype-OidValue.html, used
// OIDValue (Object Identifier Type) is, according to
// https://www.postgresql.org/docs/current/static/datatype-OIDValue.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 OidValue pguint32
type OIDValue pguint32

// Set converts from src to dst. Note that as OidValue is not a general
// Set converts from src to dst. Note that as OIDValue is not a general
// number type Set does not do automatic type conversion as other number
// types do.
func (dst *OidValue) Set(src interface{}) error {
func (dst *OIDValue) Set(src interface{}) error {
return (*pguint32)(dst).Set(src)
}

func (dst *OidValue) Get() interface{} {
func (dst *OIDValue) Get() interface{} {
return (*pguint32)(dst).Get()
}

// AssignTo assigns from src to dst. Note that as OidValue is not a general number
// AssignTo assigns from src to dst. Note that as OIDValue is not a general number
// type AssignTo does not do automatic type conversion as other number types do.
func (src *OidValue) AssignTo(dst interface{}) error {
func (src *OIDValue) AssignTo(dst interface{}) error {
return (*pguint32)(src).AssignTo(dst)
}

func (dst *OidValue) DecodeText(ci *ConnInfo, src []byte) error {
func (dst *OIDValue) DecodeText(ci *ConnInfo, src []byte) error {
return (*pguint32)(dst).DecodeText(ci, src)
}

func (dst *OidValue) DecodeBinary(ci *ConnInfo, src []byte) error {
func (dst *OIDValue) DecodeBinary(ci *ConnInfo, src []byte) error {
return (*pguint32)(dst).DecodeBinary(ci, src)
}

func (src *OidValue) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
func (src *OIDValue) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
return (*pguint32)(src).EncodeText(ci, buf)
}

func (src *OidValue) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
func (src *OIDValue) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
return (*pguint32)(src).EncodeBinary(ci, buf)
}

// Scan implements the database/sql Scanner interface.
func (dst *OidValue) Scan(src interface{}) error {
func (dst *OIDValue) Scan(src interface{}) error {
return (*pguint32)(dst).Scan(src)
}

// Value implements the database/sql/driver Valuer interface.
func (src *OidValue) Value() (driver.Value, error) {
func (src *OIDValue) Value() (driver.Value, error) {
return (*pguint32)(src).Value()
}
30 changes: 15 additions & 15 deletions oid_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import (
"github.com/jackc/pgx/pgtype/testutil"
)

func TestOidValueTranscode(t *testing.T) {
func TestOIDValueTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "oid", []interface{}{
&pgtype.OidValue{Uint: 42, Status: pgtype.Present},
&pgtype.OidValue{Status: pgtype.Null},
&pgtype.OIDValue{Uint: 42, Status: pgtype.Present},
&pgtype.OIDValue{Status: pgtype.Null},
})
}

func TestOidValueSet(t *testing.T) {
func TestOIDValueSet(t *testing.T) {
successfulTests := []struct {
source interface{}
result pgtype.OidValue
result pgtype.OIDValue
}{
{source: uint32(1), result: pgtype.OidValue{Uint: 1, Status: pgtype.Present}},
{source: uint32(1), result: pgtype.OIDValue{Uint: 1, Status: pgtype.Present}},
}

for i, tt := range successfulTests {
var r pgtype.OidValue
var r pgtype.OIDValue
err := r.Set(tt.source)
if err != nil {
t.Errorf("%d: %v", i, err)
Expand All @@ -36,17 +36,17 @@ func TestOidValueSet(t *testing.T) {
}
}

func TestOidValueAssignTo(t *testing.T) {
func TestOIDValueAssignTo(t *testing.T) {
var ui32 uint32
var pui32 *uint32

simpleTests := []struct {
src pgtype.OidValue
src pgtype.OIDValue
dst interface{}
expected interface{}
}{
{src: pgtype.OidValue{Uint: 42, Status: pgtype.Present}, dst: &ui32, expected: uint32(42)},
{src: pgtype.OidValue{Status: pgtype.Null}, dst: &pui32, expected: ((*uint32)(nil))},
{src: pgtype.OIDValue{Uint: 42, Status: pgtype.Present}, dst: &ui32, expected: uint32(42)},
{src: pgtype.OIDValue{Status: pgtype.Null}, dst: &pui32, expected: ((*uint32)(nil))},
}

for i, tt := range simpleTests {
Expand All @@ -61,11 +61,11 @@ func TestOidValueAssignTo(t *testing.T) {
}

pointerAllocTests := []struct {
src pgtype.OidValue
src pgtype.OIDValue
dst interface{}
expected interface{}
}{
{src: pgtype.OidValue{Uint: 42, Status: pgtype.Present}, dst: &pui32, expected: uint32(42)},
{src: pgtype.OIDValue{Uint: 42, Status: pgtype.Present}, dst: &pui32, expected: uint32(42)},
}

for i, tt := range pointerAllocTests {
Expand All @@ -80,10 +80,10 @@ func TestOidValueAssignTo(t *testing.T) {
}

errorTests := []struct {
src pgtype.OidValue
src pgtype.OIDValue
dst interface{}
}{
{src: pgtype.OidValue{Status: pgtype.Null}, dst: &ui32},
{src: pgtype.OIDValue{Status: pgtype.Null}, dst: &ui32},
}

for i, tt := range errorTests {
Expand Down
Loading

0 comments on commit 2140814

Please sign in to comment.