Commit Graph

117 Commits (6fabd8f5b1db42e7626ae474cc813d7070ad96bc)

Author SHA1 Message Date
Jack Christensen 6fabd8f5b1 Fix encoding uint64 larger than math.MaxInt64 into numeric
fixes https://github.com/jackc/pgx/issues/1357
2022-10-29 08:47:12 -05:00
Jack Christensen 48b4807b33 Fix some reflect Kind checks to first check for nil
fixes https://github.com/jackc/pgx/issues/1335
2022-10-22 08:57:49 -05:00
Jack Christensen f2e7c8144d reflect.TypeOf can return nil. Check before using
https://github.com/jackc/pgx/issues/1331
2022-10-12 20:03:51 -05:00
Jack Christensen aff180b192 Remove dead code 2022-10-12 19:58:06 -05:00
Jack Christensen a581124dea Encode with driver.Valuer after trying TryWrapEncodePlanFuncs
However, all builtin TryWrapEncodePlanFuncs check for driver.Valuer and
skip themselves if it is found.
2022-10-12 19:52:57 -05:00
Jack Christensen c4407fb36e Prevent infinite loop for driver.Valuer / Codec edge case
A `driver.Valuer()` results in a `string` that the `Codec` for the
PostgreSQL type doesn't know how to handle. That string is scanned into
whatever the default type for that `Codec` is. That new value is
encoded. If the new value is the same type as the original type than an
infinite loop occured. Check that the types are different.

https://github.com/jackc/pgx/issues/1331
2022-10-12 19:46:15 -05:00
Jack Christensen af0b896290 Allow scanning null even if PG and Go types are incompatible
refs https://github.com/jackc/pgx/issues/1326
2022-10-08 09:10:43 -05:00
Jack Christensen 5655f9d593 Fix scan to pointer to pointer to renamed type
refs https://github.com/jackc/pgx/issues/1326
2022-10-08 08:10:40 -05:00
Jack Christensen 222e3b37bc Prefer driver.Value over wrap plans when encoding
This is tricky due to driver.Valuer returning any. For example, we can
plan for fmt.Stringer because it always returns a string.

Because of this driver.Valuer was always handled as the last option. But
with pgx v5 now having the ability to find underlying types like a
string and supporting fmt.Stringer it meant that driver.Valuer was
often not getting called because something else was found first.

This change tries driver.Valuer immediately after the initial PlanScan
for the Codec. So a type that directly implements a pgx interface should
be used, but driver.Valuer will be prefered before all the attempts to
handle renamed types, pointer deferencing, etc.

fixes https://github.com/jackc/pgx/issues/1319
fixes https://github.com/jackc/pgx/issues/1311
2022-10-01 12:20:23 -05:00
Jack Christensen 335c8621ff Fix sqlScannerWrapper NULL handling
https://github.com/jackc/pgx/issues/1312
2022-09-24 10:30:12 -05:00
Jack Christensen fe3a4f3150 Standardize casing for NULL in error messages 2022-08-22 21:01:18 -05:00
Jack Christensen 8256ab147f Add build tag to skip default PG type registration
https://github.com/jackc/pgx/issues/1273#issuecomment-1207338136
2022-08-13 08:09:44 -05:00
Jack Christensen e7eb8a3250 Use netip package for representing inet and cidr types 2022-07-10 14:31:55 -05:00
Jack Christensen 7974a102fc Improve Scan error messages 2022-07-09 21:47:39 -05:00
Jack Christensen b662ab6767 Better encode error message 2022-07-09 21:40:44 -05:00
Jack Christensen 01190e5d78 Update ScanPlan.Scan documentation 2022-04-30 08:29:51 -05:00
Jack Christensen dfb681d716 Build / rewrite / port multirange support 2022-04-23 12:50:18 -05:00
Jack Christensen a01a9ee6df Automatically register Array and FlatArray 2022-04-16 14:04:25 -05:00
Jack Christensen fccaebc93d Add pgtype.Map.SQLScanner
This enables compatibility with database/sql for types that cannot
implement Scan themselves.
2022-04-16 13:38:27 -05:00
Jack Christensen f1a4ae3070 Add Array and FlatArray container types 2022-04-16 11:33:45 -05:00
Jack Christensen d4abe83edb Revert use generics for RangeCodec
Reverted almost all of 976b1e0.

Still may consider a way to get DecodeValue to be strongly typed but
that feature isn't worth the complications of generics. Especially in
that applying this style to ArrayCodec would make Conn.LoadType
impossible for arrays.
2022-04-16 10:39:12 -05:00
Jack Christensen 976b1e03a9 Use generics for RangeCodec
This allows DecodeValue to return a more strongly typed value.
2022-04-09 10:21:17 -05:00
Jack Christensen c8025fd79a Use generics for Range values 2022-04-09 09:34:37 -05:00
Jack Christensen f14fb3d692 Replace interface{} with any 2022-04-09 09:12:55 -05:00
Jack Christensen ee93440ac1 pgtype uses pgxtest
Added ValueRoundTripTest to pgxtest
Removed pgtype/testutil

pgtype tests now run with all (applicable) query modes. This gives
better coverage than before and revealed several bugs which are also
fixed in this commit.
2022-04-02 14:34:19 -05:00
Jack Christensen 500c0721d7 Improve error messages for query argument encoding 2022-04-01 18:00:25 -05:00
Jack Christensen 5ca048ed2d Fix crash with pointer to nil struct 2022-03-22 20:33:24 -05:00
Jack Christensen 8c18d7808b Add documentation 2022-03-19 17:01:12 -05:00
Jack Christensen c4b08378f2 Handle driver.Valuers inside Map.Encode 2022-03-05 21:27:17 -06:00
Jack Christensen 0905d1f452 Register more default types and handle unknown types better 2022-03-05 21:19:58 -06:00
Jack Christensen e5685a34fc Simplify encoding extended query arguments 2022-03-05 20:16:57 -06:00
Jack Christensen e7f90ba6e4 Remove unused pgtype.Map field 2022-03-05 09:00:49 -06:00
Jack Christensen ec8f7c4204 Add comment for FormatCodeForOID 2022-03-05 08:56:41 -06:00
Jack Christensen 45a8b00271 Do not recursively call public PlanScan that caches
Otherwise, wrapper types get cached. Wrapper types are expected to fail
most of the time. These failures should not be cached. In addition,
wrappers wrap multiple different types so it doesn't make sense to cache
results of a wrapper.
2022-03-04 11:04:46 -06:00
Jack Christensen 43083cb0e3 Memoize pgtype.Map.PlanScan 2022-02-21 10:10:16 -06:00
Jack Christensen 9c538cd4a9 Remove actualTarget argument 2022-02-21 09:30:01 -06:00
Jack Christensen f3defbc150 Rename pgtype.None to pgtype.Finite 2022-02-21 09:25:30 -06:00
Jack Christensen 1f2f239d09 Renamed pgtype.ConnInfo to pgtype.Map 2022-02-21 09:13:09 -06:00
Jack Christensen bda10b2ec9 Rename pgtype.DataType to pgtype.Type 2022-02-21 09:01:48 -06:00
Jack Christensen a3c351d11a RegisterDataType now accepts *DataType 2022-02-21 08:49:04 -06:00
Jack Christensen 7193e48923 Restore multi-dimensional slices
Move ArrayCode to use pgtype wrapper pattern as well
2022-02-08 10:07:40 -06:00
Jack Christensen 3a94113118 Add composite to arbitrary struct encoding and decoding 2022-02-05 14:24:34 -06:00
Jack Christensen 727fc19cb7 Another error message improvement 2022-02-05 13:10:58 -06:00
Jack Christensen 28ea2cd190 Better error messages 2022-02-05 13:05:23 -06:00
Jack Christensen ba4583cf4c Add range array types 2022-02-02 08:47:56 -06:00
Jack Christensen cebe44ee85 Restore range support 2022-02-02 08:40:42 -06:00
Jack Christensen 11223497b3 Restore record support 2022-01-31 20:42:12 -06:00
Jack Christensen 558748ef9c ArrayCodec contains element DataType 2022-01-29 16:41:07 -06:00
Jack Christensen 0ddf9e3b4b Try wrapping scan target before sql.Scanner
This allows wrappers to directly avoid the slow sql.Scanner interface.
2022-01-22 18:40:46 -06:00
Jack Christensen 5ed95dcd1c Expose wrap functions on ConnInfo
- Remove rarely used ScanPlan.Scan arguments
- Plus other refactorings and fixes that fell out of this change.
- Plus rows Scan now handles checking for changed type.
2022-01-22 17:50:19 -06:00