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.
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.
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.
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.
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.
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.
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.