Commit Graph

29 Commits (5db1de5fc18703ddf645024dff9ff73c98bc9107)

Author SHA1 Message Date
Jack Christensen dd160540c4 Use Go 1.13 errors instead of xerrors 2021-03-25 09:08:27 -04:00
Jack Christensen 00d516f5c4 Fix panic on assigning empty array to non-slice or array
See https://github.com/jackc/pgx/issues/881
2020-11-27 11:56:21 -06:00
Jack Christensen 740b3a5115 Fix: Text array parsing disambiguates NULL and "NULL".
This solution is a little awkward, but it avoids breaking backwards
compatibility.

fixes #78
2020-11-07 07:41:49 -06:00
Jack Christensen af0ca3a39b Fix simple protocol empty array and original recursive empty array issue
Original issue https://github.com/jackc/pgtype/issues/68

This crash occurred in the recursive assignment system used to support
multidimensional arrays.

This was fixed in 9639a69d45. However,
that fix incorrectly used nil instead of an empty slice.

In hindsight, it appears the fundamental error is that an assignment to
a slice of a type that is not specified is handled with the recursive /
reflection path. Or another way of looking at it is as an unexpected
feature where []T can now be scanned if individual elements are
assignable to T even if []T is not specifically handled.

But this new reflection / recursive path did not handle empty arrays.

This fix handles the reflection path for an empty slice by allocating an
empty slice.
2020-10-31 17:12:16 -05:00
Jack Christensen 9d7fc8e63a AssignTo pointer to pointer to slice and named types
fixes #69
2020-10-24 09:21:42 -05:00
Simo Haasanen 9639a69d45 Adds checks for zero length arrays.
Assigning values from nil or zero length elements or dimensions now return immediately as there are no values to assign.
2020-10-20 19:52:05 +01:00
Jack Christensen 9da6afcad7 Fix selecting empty array
Failing test was in pgx: TestReadingValueAfterEmptyArray
2020-09-05 10:56:22 -05:00
Simo Haasanen ec14212d30 Add comments to explain the use of reflection after type assertion.
Removes one local variable, which is used twice only in an error.
2020-08-09 09:17:40 +01:00
Simo Haasanen b90570feb5 Restored more optimised array type conversions for a few select 1D-slice types.
Results of calls to the reflect lib are now stored as local variables for small performance gains.
2020-08-08 19:51:37 +01:00
Simo Haasanen 449a8a4f8e Add multidimensional array and slice support.
Adds array support - previously only slices were supported.
Adds new test cases for multidimensional arrays and slices.
All previous test cases are unmodified and passed (fully backwards compatible).
Removes hard-coded type conversions for arrays, instead now relies on the type support of the array element's type conversion support.
Less maintenance for arrays, new type conversions are automatically supported when array's element gains new type support.
Simplifies typed_array_gen.sh generator script by removing the hard-coded single-dimensional types for arrays.
Only typed_array.go.erb and typed_array_gen.sh have been changed + 1 new auxiliary function in array.go file + additional tests in test files for each array. Other changes are from generated code.
2020-08-07 13:10:32 +01:00
megaturbo bc07106f0e Add `Code generated` notice at the top of the file 2020-06-17 17:04:43 +02:00
Jack Christensen 55a56add23 Set will call Get on src if possible 2020-02-19 11:58:49 -06:00
Jack Christensen f3816bd1c0 Get implemented on T instead of *T
Methods defined on T are also available on *T. Thought this technically
changes the interface, because *T will be automatically dereferenced as
needed it shouldn't be a breaking change.

See a8802b16cc for similar change.
2020-02-19 10:48:09 -06:00
Jack Christensen be36a7e14b Fix test and avoid change to array signatures
typed_array.go.erb was not updated back in
a8802b16cc when Value, EncodeBinary,
EncodeText, and MarshalJSON were changed to be defined on T instead of
*T. This has been corrected.
2019-11-14 20:40:41 -06:00
Alex Gaynor 0079108e29 Fixes #11 -- support initializing Array types from a slice of the value 2019-11-08 14:59:19 -05:00
Jack Christensen a8802b16cc Value, EncodeBinary, EncodeText, and MarshalJSON on T instead of *T
Methods defined on T are also available on *T. This change makes Value
consistent with database/sql Value implementations. It also makes Value,
EncodeBinary, and EncodeText more convenient to use because you can
pass T or *T as an argument to a query.

The MarshalJSON change is even more significant because without it
json.Marshal would generate the "%v" format instead of the implemented
MarshalJSON.

Thought this technically changes the interface, because *T will be
automatically dereferenced as needed it shouldn't be a breaking change.

See: https://github.com/jackc/pgx/issues/538 for initial discussion.
2019-08-27 20:46:16 -05:00
Jack Christensen f25878662d Use golang.org/x/xerrors 2019-04-20 17:43:44 -05:00
Jack Christensen 4e79a104f7 Test domains when registered and unregistered
Fix bug assigning to unknown type.
2019-04-13 17:09:51 -05:00
Jack Christensen 0ac82007fb Use extracted packages with Go modules 2019-04-05 10:59:47 -05:00
Damir Vandic 79ba0275de Add the type of the value in all decode error messages 2018-06-04 21:02:20 +02:00
Jack Christensen 703ce85513 Generate UUIDArray from template
- Fix error in Set
- Specifically handle untyped nil
2017-08-29 14:33:25 -05:00
Jack Christensen a5f166bd21 Use github.com/pkg/errors 2017-06-04 21:30:03 -05:00
Jack Christensen 2140814606 Use Go casing convention for OID 2017-06-03 11:53:49 -05:00
Jack Christensen 6b906ca870 Refactor pgio and types to append buffers 2017-05-02 20:38:26 -05:00
Jack Christensen ab21bc4ec7 pgtype DecodeText and DecodeBinary do not copy
They now take ownership of the src argument.

Needed to change Scan to make a copy of []byte arguments as lib/pq apparently
gives Scan a shared memory buffer.
2017-04-29 12:23:51 -05:00
Jack Christensen b49035fdc1 Add shopspring.Numeric
This adds PostgreSQL numeric mapping to and from
github.com/shopspring/decimal.

Makes pgtype.NullAssignTo public as external types need this functionality.

Begin extraction of pgtype testing functionality so it can easily be used by
external types.
2017-04-14 12:24:44 -05:00
Jack Christensen 6f9ef694d0 Add database/sql support to pgtype 2017-03-18 21:11:43 -05:00
Jack Christensen 85f7df1e81 Factor out duplication in AssignTo 2017-03-18 16:54:08 -05:00
Jack Christensen df8f8e17cf Add pgtype.HstoreArray
This required restructuring array types to lookup oid of element instead of
hard-coding it due to hstore having a variable oid.
2017-03-18 12:40:54 -05:00