Commit Graph

203 Commits (1dc7133a63b463aec4cf79a19dfa64e38b374211)

Author SHA1 Message Date
Jack Christensen c672c0d595 Use environment variables for test configuration 2018-12-30 21:52:33 -06:00
Jack Christensen 67a15e6f7f Move connection tests to pgconn 2018-12-30 21:10:06 -06:00
Jack Christensen b3c8a73dc7 Restructure connect process
- Moved lots of connection logic to pgconn from pgx
- Extracted pgpassfile package
2018-12-30 16:55:56 -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
Jörg Thalheim 3410ad9122
Add host query parameter to support unix sockets
Currently there is no way to specify unix sockets in the connection
url. This patch adds a `host` query parameter that allows to set the path.
2018-11-03 21:07:33 +00:00
Valery Krivchikov 1f054a77ea fix new variables on left side 2018-09-15 14:50:17 +03:00
Valery Krivchikov 0468c97a7e Fix undefined cancel 2018-09-15 14:27:29 +03:00
Valery Krivchikov c844a2402b Call context.WithTimeout cancel function 2018-09-15 13:23:09 +03:00
Jack Christensen 39bbc98d99 Do not use same tls.Config for fallback in test 2018-06-08 15:19:56 -05:00
Jack Christensen 7b6f0ffc8c Fix race in TLS tests 2018-06-08 15:14:45 -05:00
Jack Christensen e04f5443d5 Fix test with formatting directive 2018-05-17 16:45:01 -05:00
Jack Christensen 6044dcbe21 Fix race in TLS test 2018-05-17 16:43:15 -05:00
Jack Christensen db7df79e10 Add domain support
fixes #407
2018-04-07 14:04:16 -05:00
Sean Chittenden d7f24b91f4
Make ParseURI() compatible with lib/pq's TLS keywords.
Add support for:

- `sslrootcert`
- `sslcert`
- `sslkey`

All three arguments, like thir `gitub.com/lib/pq` counterparts,
are filesystem paths.
2018-02-01 22:58:14 -08:00
Jack Christensen 5f24beb4f0 Test database name in parsing tests 2018-01-15 11:47:59 -06:00
Jack Christensen 2c07b03087 Parse connect_timeout into Dial func
Instead of adding Timeout field which could conflict with custom Dial
func.
2018-01-13 18:02:13 -06:00
Jack Christensen 9281f057ae Merge branch 'timeout' of https://github.com/cyberdelia/pgx into cyberdelia-timeout 2018-01-13 17:31:22 -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
ferhat elmas 763deea17e Run gofmt with simplify flag 2017-12-21 23:45:26 +01:00
Timothée Peignier 1bec450326
Handle timeout parameters 2017-12-16 19:18:33 -08:00
Felix Geisendörfer 1bebe56697 travis: add connection test coverage for cratedb 2017-11-12 15:47:26 +01:00
Jack Christensen fd7b776540 Merge pull request #323 from kelseyfrancis/namespace-oids
Prefix types in namespaces other than pg_catalog or public
2017-09-14 13:59:51 -05:00
Kelsey Francis 953e08df99 Prefix types in namespaces other than pg_catalog or public
It's possible to define a type (e.g., an enum) with the same name in two
different schemas. When initializing data types after connecting, types
defined within schemas other than pg_catalog or public should be
qualified with their schema name to disambiguate them and ensure all
types with the same base name get added to the map of OID to type.

Prior to this commit, the last type scanned would "win", and all others
with the same name would be missing from the ConnInfo type maps, which
would subsequently cause any PREPARE involving columns of those missing
types to return the error "unknown oid".
2017-09-11 11:29:42 -07:00
Jack Christensen a1e4d17e58 Fix sslmode require test 2017-09-09 11:05:27 -05:00
Kelsey Francis ea740fb316 Fix some invalid one round trip execs failing to return non-nil error
Prior to this commit, execEx() would write the one round trip exec to
the connection before first calling ensureConnectionReadyForQuery, which
ultimately caused any errors to be suppressed if the exec followed a
valid query, because the receive message processing would finish
successfully as soon as it received the ReadyForQuery that actually
belonged to the preceding query. So, the exec would never actually
receive the error message that it caused, leaving it to be incorrectly
received by the first subsequent query sent.
2017-08-28 18:51:35 -07:00
Jack Christensen fb90fb2729 Add notification response hook
refs #239
2017-06-04 21:18:26 -05:00
Jack Christensen 27ab289096 Use Go casing convention for OID 2017-06-03 11:53:49 -05:00
Jack Christensen 95c11a1fd1 Remove bad channel sync causing orphaned goroutine 2017-05-31 07:57:22 -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 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 855b735eae Add log adapters for testing and log15
Make LogLevel a type for Stringer interface.
2017-04-29 20:33:52 -05:00
Jack Christensen 7b1f461ec3 Add simple protocol suuport with (Query|Exec)Ex 2017-04-10 08:58:51 -05:00
James Lawrence c5d247830c enable sql.Open to support both DSN and URI based connection strings 2017-04-01 08:50:48 -05:00
Jack Christensen d7973d87dd Fix TestParseEnvLibpq when PGSSLMODE is set 2017-03-24 13:27:04 -05:00
Jack Christensen 9ab59a74a9 Remove oid constants from pgx 2017-03-18 14:59:34 -05:00
Jack Christensen 5eb19bc66a Add *Conn.CopyFrom
This replaces *Conn.CopyTo. CopyTo was named incorrectly. In PostgreSQL
COPY FROM is the command that copies from the client to the server. In
addition, CopyTo does not accept a schema qualified table name. This
commit introduces the Identifier type which handles multi-part names and
correctly quotes/sanitizes them. The new CopyFrom method uses this
Identifier type.

Conn.CopyTo is deprecated.

refs #243 and #190
2017-03-17 08:25:49 -05:00
Jack Christensen ba5f97176a Move not null Oid to pgtype
In preparation to ConnInfo implementation.
2017-03-13 21:34:38 -05:00
Jack Christensen 743b98b298 Name PG types as words
Though this doesn't follow Go naming conventions exactly it makes names more
consistent with PostgreSQL and it is easier to read. For example, TIDOID becomes
TidOid. In addition this is one less breaking change in the move to V3.
2017-03-11 17:03:23 -06:00
Jack Christensen 908c439317 Use stdlib context 2017-03-03 16:01:06 -06:00
Jack Christensen ccc65c361a Privatize Conn.SecretKey 2017-02-16 18:31:34 -06:00
Jack Christensen e390ac33f5 Fix Fatal -> Fatalf 2017-02-16 18:12:42 -06:00
Jack Christensen 11b82b3ca4 msgReader implemented in terms of ChunkReader
This should substantially reduce memory allocations and memory copies.

It also means that PostgreSQL messages are always entirely buffered in memory
before processing begins. This simplifies the message processing code.

In particular, Conn.WaitForNotification is dramatically simplified by this
change.
2017-02-13 20:45:42 -06:00
Jack Christensen 7fbff4a495 Merge branch 'context' into v3-experimental 2017-02-12 15:13:47 -06:00
Jack Christensen e4f9108e82 wip 2017-02-11 14:59:16 -06:00
Jack Christensen a9e7e3acbc Extract connection dead on server test 2017-02-04 16:03:20 -06:00
Jack Christensen 78adfb13d7 Add Ping, PingContext, and ExecContext 2017-02-04 14:20:00 -06:00
Jack Christensen ec513248ac Conn.PID accessed through method 2017-01-07 13:37:36 -06:00
Jack Christensen 93e5c68f69 Merge branch 'master' into v3-experimental 2016-12-10 12:21:08 -06:00
Martin Hamrle 9f6b99e332 Cleanups
Cleanups suggested by gometalinter tools.
2016-08-30 20:05:44 +02:00
Jack Christensen 73124171e2 Rename Pid to PID 2016-08-02 15:10:00 -05:00
Jack Christensen 390f75c0e1 Reduce Logger interface to Log method 2016-08-02 14:42:31 -05:00
Jack Christensen 214443deb7 Rename Oid to OID 2016-08-02 13:31:55 -05:00
Jack Christensen 40f00f4a82 Pass PrepareEx opts as pointer and DRY implementation 2016-05-20 08:30:10 -05:00
Jack Christensen 129ff96567 TestFatalRxError expects multiple error types 2016-03-24 16:22:27 -05:00
Jack Christensen 9ce1b2b16e Fix Listen/Unlisten with special characters
fixes #132
2016-03-24 15:26:44 -05:00
Jack Christensen d88242b0ca Tweak error reporting on TestFatalRxError 2016-03-15 08:28:07 -05:00
Jack Christensen 9d7cf39563 Fix go vet identified format strings 2016-02-15 12:32:24 -06:00
Jack Christensen 0f7bf19387 Add *Conn.SetLogLevel
Allow changing log level after connection is established. Because
log level and loggers can be set independently, it is now possible
to have a log level above none when there is a nil logger. This
means all log statements need to check for nil logger and an
appropriate log level. This check has been factored out into
*Conn.shouldLog.
2016-02-13 10:13:10 -06:00
Jack Christensen cffae7ff5d Add SetLogger to *Conn
Allow replacing logger after connection is established. Also
refactor internals of logging such that there is a log method that
adds the pid to all log calls instead of making a new logger object.
The reason for this is so pid will be logged regardless of whether
loggers are replaced and restored.
2016-02-12 17:49:04 -06:00
Jack Christensen ec8f6259e6 ParseEnvLibpq extracts PGAPPNAME 2015-10-16 16:13:15 -05:00
Jack Christensen 829d61ce40 ParseDSN extracts RuntimeParams 2015-10-16 15:48:24 -05:00
Jack Christensen 5b0550c1cb ParseURI extracts run-time parameters
refs #99
2015-10-16 15:37:49 -05:00
Jack Christensen 1fb63a4b41 Add RuntimeParams to ConnConfig 2015-10-16 15:37:32 -05:00
Jack Christensen 984eace2b5 Make *Conn.Prepare idempotent.
fixes #94
2015-10-16 14:17:07 -05:00
Jack Christensen 36fb7a3aec Use Skip when skipping tests rather than just return 2015-09-26 13:29:40 -05:00
Jack Christensen 9fd5c7e6ab Add test for Unlisten 2015-09-21 08:05:53 -05:00
Jack Christensen 90b2e0acb7 Add additional testing around listen/notify 2015-09-17 17:40:04 -05:00
Jack Christensen 86837e5576 Add guards against usage of busy connection 2015-09-16 10:22:16 -05:00
Jack Christensen 6e5fa60c4c Fix cases where net conn write failure was not marking connection as dead
Also added loop to run these timing sensitive tests multiple times.
2015-09-12 19:32:55 -05:00
Rick Snyder 6413491657 Add support for specifying sslmode in connection strings
Add tests for sslmode parameter when calling ParseURI.  Fix existing tests to work since default sslmode is 'prefer'

Make sure we default to prefer if sslmode is not provided in ParseDSN

Fix existing tests for ParseDSN to expect TLS configuration for prefer since prefer is the default sslmode; also, add tests for ParseDSN when specifying sslmode parameter on connection string
2015-08-19 11:33:12 -04:00
Jack Christensen 07a11abc07 Add basic PGSSLMODE support to ParseEnvLibpq 2015-05-23 13:49:26 -05:00
Jack Christensen 51d6d1a3a6 Add ParseEnvLibpq with support for basic envvars 2015-05-23 12:46:36 -05:00
Jack Christensen dd9d960ba3 Add fallback TLS ConnConfig option
This is in preparation for supporting libpq style SSL options.
2015-05-23 11:57:36 -05:00
Lewis Marshall 784d12cbbc Support using a custom dialer
For example I may want to use a dialer which retries transient network
errors (e.g. DNS issues).

Signed-off-by: Lewis Marshall <lewis@lmars.net>
2015-04-18 22:42:55 +01:00
deoxxa 36d1a58b42 add tests for ParseDSN 2015-04-08 14:55:15 +10:00
Jack Christensen 28ef19702f Detect too many parameters on Prepare
refs #65
2015-03-14 18:58:09 -05:00
Karl Seguin 67292290cf support for inserting []time.Time into timestamp[] columns 2014-12-21 13:35:39 +07:00
Karl Seguin d1b42d1c8e support inserting into bool[] 2014-12-21 13:01:24 +07:00
Karl Seguin e5b2fbd819 select; is valid in 9.4. This causes the two tests to exec successfully when
we're trying to get a syntax error.
2014-11-17 21:21:08 +07:00
Jack Christensen 6a4284a30c Add test for no-op Exec 2014-09-27 14:40:13 -05:00
Jack Christensen b06d71f684 Update test to work on Windows 2014-07-26 09:50:43 -05:00
Jack Christensen 61bf7d841a Always use bound parameters
PostgreSQL has two string syntaxes, one that allows backslash escapes and one
that does not (SQL standard conforming strings). By default PostgreSQL uses
standard conforming strings. QuoteString was only designed for use with
standard conforming strings. If PostgreSQL was configured with certain
combinations of the standard_conforming_strings and backslash_quote settings,
QuoteString may not correctly sanitize strings. QuoteString was only used in
unprepared queries, bound parameters are used for prepared queries.

This commit alters pgx to use always use bound parameters.

As a consequence of never doing string interpolation there is no need to have
separate Text and Binary encoders. There is now only the Encoder interface.

This change had a negative effect on the performance of simple unprepared
queries, but prepared statements should already be used for performance.

fixes #26

https://github.com/jackc/pgx/issues/26
2014-07-18 16:51:11 -05:00
Jack Christensen c108378973 Reorganize code 2014-07-12 08:50:30 -05:00
Jack Christensen f31665c5db wip 2014-07-12 07:11:16 -05:00
Jack Christensen 19537badff Add Rows.Values 2014-07-11 16:55:45 -05:00
Jack Christensen 294c05efcc Add test for date 2014-07-11 14:39:06 -05:00
Jack Christensen 93677e40dd Add test for timestamptz 2014-07-11 14:37:16 -05:00
Jack Christensen 12861ff7f1 Remove unused code 2014-07-11 14:36:58 -05:00
Jack Christensen 7ca95d7f73 Add NullString
Changes EncodeText interface to work for null values in SQL interpolation
and in prepared statements text format.
2014-07-11 14:16:25 -05:00
Jack Christensen 24395d98df Add more testing of Encode*
Handle case where TextEncoder is used to a core type that the driver
could otherwise have handled as binary.
2014-07-11 11:16:12 -05:00
Jack Christensen 6884fdfb52 Move Query tests together 2014-07-11 08:33:09 -05:00
Jack Christensen 986f9a1e66 Run TestConnQueryReadTooManyValues in parallel 2014-07-11 08:29:57 -05:00
Jack Christensen 646136fb44 Rename *Rows.NextRow to *Rows.Next
Conform closer to database/sql
2014-07-11 08:26:01 -05:00
Jack Christensen d7529600e0 Rename QueryResult to Rows
This helps conform closer to database/sql
2014-07-11 08:21:29 -05:00
Jack Christensen 01f261c71c Conform closer to database/sql style and add no rows test 2014-07-11 08:16:21 -05:00
Jack Christensen 566d713285 More tests and bug fixes 2014-07-11 07:50:44 -05:00