Commit Graph

139 Commits (2263521f7031ef3eec5b257bf5d54344c38cbe31)

Author SHA1 Message Date
Jack Christensen 1b8f0016e9 Split pgtype into own repo 2019-04-20 19:20:00 -05:00
Jack Christensen cc3461e65d Use golang.org/x/xerrors 2019-04-20 17:43:44 -05:00
Jack Christensen efb333df6b Fix go modules
Wow. This is fun. Sure is easy to get modules wrong when upgrading a v2+
project.
2019-04-20 17:41:08 -05:00
Jack Christensen b7e56b003a Replace lastStmtSent with pgconn support 2019-04-20 17:12:20 -05:00
Jack Christensen 0f95329c5a Remove commented out unused one round trip mode 2019-04-20 12:02:02 -05:00
Jack Christensen 2978a7440a Use pgconn for more conn status 2019-04-19 16:18:47 -05:00
Jack Christensen 2a55a4048a Add QueryResultFormats option 2019-04-13 14:06:48 -05:00
Jack Christensen c53c9e6eb5 Remove simple protocol and one round trip query options
It is impossible to guarantee that the a query executed with the simple
protocol will behave the same as with the extended protocol. This is
because the normal pgx path relies on knowing the OID of query
parameters. Without this encoding a value can only be determined by the
value instead of the combination of value and PostgreSQL type. For
example, how should a []int32 be encoded? It might be encoded into a
PostgreSQL int4[] or json.

Removal also simplifies the core query path.

The primary reason for the simple protocol is for servers like PgBouncer
that may not be able to support normal prepared statements. After
further research it appears that issuing a "flush" instead "sync" after
preparing the unnamed statement would allow PgBouncer to work.

The one round trip mode can be better handled with prepared statements.

As a last resort, all original server functionality can still be accessed by
dropping down to PgConn.
2019-04-13 11:39:01 -05:00
Jack Christensen f756d9d591 Extract scan value to pgtype 2019-04-12 21:31:59 -05:00
Jack Christensen 69946b35d8 Remove blank line 2019-04-12 21:24:14 -05:00
Jack Christensen 938ee9f434 Rows and Row are now interfaces 2019-04-11 17:58:16 -05:00
Jack Christensen 2f948c5249 Remove unused code 2019-04-10 14:33:35 -05:00
Jack Christensen acd15cf589 Remove some obsolete context handling 2019-04-10 14:25:06 -05:00
Jack Christensen 7718ee6207 Remove Ex versions of Query and QueryRow
Always require context and prepend options to arguments if necessary.
2019-04-10 12:12:22 -05:00
Jack Christensen 77a2da2b46 Replace connection pool 2019-04-10 11:09:42 -05:00
Jack Christensen 858d00788a Use extracted packages with Go modules 2019-04-05 10:59:47 -05:00
Jack Christensen 4ed4e0122d Restore simple protocol support 2019-02-02 13:27:18 -06:00
Jack Christensen bd181764bf Remove ensureConnectionReadyForQuery 2019-02-02 13:00:31 -06:00
Jack Christensen 577bc57ba5 Remove sendSimpleQuery
In preparation for removing ready for query tracking.
2019-02-02 12:55:12 -06:00
Jack Christensen 08c8b49fe4 Remove another no longer used method 2019-02-02 11:54:04 -06:00
Jack Christensen d3a2c1c107 Partial conversion of pgx to use pgconn 2019-01-26 16:46:30 -06:00
Jack Christensen 1ff8024df9 Access underlying net.Conn via method
Also remove some dead code.
2018-12-31 18:00:08 -06:00
Jack Christensen 44de49ffa1 Rename runtime params to parameter status 2018-12-28 12:25:59 -06:00
Jack Christensen b63370e5d5 Rename base.Conn to base.PgConn
- pgx.Conn embeds base.PgConn privately
- Add pgx.Conn.ParameterStatus
2018-12-28 12:16:50 -06:00
Jack Christensen a9a178bc98 Merge branch 'master' into v4-experimental 2018-12-01 11:17:30 -06:00
James Hartig 6d336eccb1 Added LastStmtSent and use it to retry on errors if statement was not sent
Previously, a failed connection could be put back in a pool and when the
next query was attempted it would fail immediately trying to prepare the
query or reset the deadline. It wasn't clear if the Query or Exec call
could safely be retried since there was no way to know where it failed.

You can now call LastQuerySent and if it returns false then you're
guaranteed that the last call to Query(Ex)/Exec(Ex) didn't get far enough
to attempt to send the query. The call can be retried with a new
connection.

This is used in the stdlib to return a ErrBadConn if a network error
occurred and the statement was not attempted.

Fixes #427
2018-11-19 10:44:40 -05:00
Jack Christensen 2e72ca854a First extraction of base.Conn 2018-11-10 18:48:43 -06:00
Jack Christensen 670e85136f Remove Conn.lastActivityTime
It was only read in one place and that was an optimization to get the
current time. Replaced that usage with time.Now()
2018-11-09 15:33:31 -06:00
Jack Christensen 52fc785a43 Fix incorrect reuse of Value in Rows.Values()
fixes #386
2018-02-03 11:04:49 -06:00
Jack Christensen bd76a96882 Add ConnConfig.PreferSimpleProtocol
Allows configuring on a connection basis to prefer the simple protocol /
disable implicit prepared statements.

refs #331
2018-01-13 12:05:33 -06:00
Jack Christensen 2b4558fe22 Fix time logging for QueryEx
fixes #341
2017-10-28 13:05:46 -05:00
Jack Christensen 53e5d8e341 Fix incomplete selects during batch
An incompletely read select followed by an insert would fail. This was
caused by query methods in the non-batch path always calling
ensureConnectionReadyForQuery. This ensures that connections interrupted
by context cancellation are still usable. However, in the batch case
query methods are not being called while reading the result. A
incompletely read select followed by another select would not manifest
this error due to it starting by reading until row description. But when
an incomplete select (which even a successful QueryRow would be
considered) is followed by an Exec, the CommandComplete message from the
select would be considered as the response to the subsequent Exec.

The fix is the batch tracking whether a CommandComplete is pending and
reading it before advancing to the next result. This is similar in
principle to ensureConnectionReadyForQuery, just specific to Batch.
2017-09-21 11:19:52 -05:00
Gaspard Douady b4f9d149c1 Fix queryRow leftover message on conn
those leftover messages are tossed by ensureConnectionReadyForQuery but
in the batch use case this is not called between each query.
2017-09-21 11:12:50 +02:00
Kelsey Francis fc18cc8d76 Always return non-nil *Rows from Query to fix QueryRow
Since QueryRow delegates to Query, it needs Query to always return
non-nil *Rows to prevent a nil pointer deference when the QueryRow
caller calls Scan(). This commit fixes the few returns in QueryEx that
return nil on errors rather than *Rows with its err field set.
2017-08-31 11:37:20 -07:00
Jack Christensen 8f4178b3d3 Use github.com/pkg/errors 2017-06-04 21:30:03 -05:00
Jack Christensen 27ab289096 Use Go casing convention for OID 2017-06-03 11:53:49 -05:00
Jack Christensen 73f496d7de Finish core batch operations 2017-06-03 11:49:27 -05:00
Jack Christensen fe0af9b357 Happy-path batch query mode 2017-06-02 14:54:17 -05:00
Jack Christensen dd5e6a77dc Add QueryEx single round-trip mode 2017-05-29 11:27:44 -05:00
Jack Christensen dd5de3e49e Add single round-trip mode for ExecEx 2017-05-29 09:11:52 -05:00
Jack Christensen 8a7165dd98 Add ctx to PrepareEx
Remove PrepareExContext
2017-05-20 18:03:59 -05:00
Jack Christensen 2df4b1406b Do not double call termContext in QueryEx
QueryEx was calling termContext and rows.fatal on err of sendPreparedQuery.
rows.fatal calls rows.Close which already calls termContext. This sequence of
calls was causing underlying io timeout errors to be returned instead of context
errors.

In addition, added fatalWriteErr helper method to allow recovery of write
timeout errors where no bytes were written.

This should solve flickering errors on Travis.
2017-05-20 10:58:44 -05:00
Jack Christensen 2a49569747 Remove AfterClose() and Conn() from Tx and Rows 2017-05-06 10:00:49 -05:00
Jack Christensen 8322171bd8 Remove Rows.Fatal 2017-05-06 09:37:49 -05:00
Jack Christensen 280bce7078 Added log adapter for logrus
Also changed standard logger interface to take a map instead of varargs for
extra data.
2017-04-29 21:28:38 -05:00
Jack Christensen f04c58338b Introduce pgproto3 package
pgproto3 will wrap the message encoding and decoding for the PostgreSQL
frontend/backend protocol version 3.
2017-04-29 10:02:38 -05:00
Jack Christensen 932ab58cf7 Remove ValueReader 2017-04-12 07:46:25 -05:00
Jack Christensen 7b1f461ec3 Add simple protocol suuport with (Query|Exec)Ex 2017-04-10 08:58:51 -05:00
Jack Christensen bec9bd261b Add database/sql support to pgtype 2017-03-18 21:11:43 -05:00
Jack Christensen 92cff1d961 Simplify []byte scanning 2017-03-18 14:42:36 -05:00