Commit Graph

325 Commits (12857ad05b7ffa7d43eb68af9235555dbea2dc24)

Author SHA1 Message Date
Karl Seguin 04b54f03a5 Use LastIndex instead of Split for better performance getting the number of rows affected from CommandTag 2014-11-16 12:43:47 +07:00
Jack Christensen 5edd660971 WaitForNotification detects lost connections quicker
Ping server every 15 seconds while waiting if no traffic has occurred.
2014-10-03 14:58:04 -05:00
Jack Christensen 44f44c1baa Merge pull request #39 from anaxagoras/emptyquery
support EmptyQueryResponse message type
2014-09-27 14:37:13 -05:00
Jack Christensen 9e30e7aa93 Remove duplicate line 2014-09-27 12:20:36 -05:00
Jack Christensen 3d7974ce30 Always use keep-alive on TCP conns 2014-09-27 12:13:10 -05:00
Andy Walker f715715c86 add support for EmptyQueryResponse 2014-09-26 17:14:28 -04:00
Andy Walker 33fb73b8ab name consistency 2014-09-24 18:53:07 -04:00
Andy Walker b46ee0a951 Add keep-alive option by creating a dialer first, then setting KeepAlive option 2014-09-24 18:38:15 -04:00
Jack Christensen 98853ea98f more docs 2014-09-19 17:35:00 -05:00
Andy Walker 2f1ec582d7 Instead of native map[string]string, use type pgx.Hstore instead 2014-09-19 15:27:15 -05:00
Andy Walker 821605a8dd Adding hstore support. map[string]string will encode to hstores and throw errors on hstores with NULL values, and there is now a NullHstore type that is basically map[string]NullString and will both accept and decode NULL values properly 2014-09-19 15:27:15 -05:00
Jack Christensen 8f81acfb5f Enhance support for custom types
* Add per connection oid to name map
* Global default type format is now based on names not oids
* Add better docs for custom types
2014-09-19 15:27:15 -05:00
Brian Dunn and Jack Christensen a68115fc03 Fix data race with Rows and ConnPool
In an effort to reduce memory allocations, Rows was stored on the
Conn. This caused a race condition where Rows are closed and this
returns the Conn to the Pool. The Pool could then give out the Conn
again. Rows would then be reanimated and the original Rows could reclose
it.
2014-09-16 16:29:45 -05:00
Jack Christensen a5f082fa03 Extract more error information 2014-09-15 14:52:32 -05:00
Jack Christensen b21a653085 Truncate logged strings and byte slices 2014-09-15 13:53:59 -05:00
Jack Christensen f5156ac4eb discardLogger should be private 2014-09-04 16:45:35 -05:00
Jack Christensen ff905fe862 Finish compatible interface to inconshreveable/log15 2014-09-04 16:27:40 -05:00
Jack Christensen 98109c57bb Use interface for logging instead of log15 directly 2014-09-04 16:00:53 -05:00
Jack Christensen 311c332fdc More logging 2014-09-03 11:13:29 -05:00
Jack Christensen 0ddf94ef9d Add pgx.Oid serialization 2014-08-08 10:57:33 -05:00
Jack Christensen 2a04433355 Fix misleading error message 2014-08-08 10:31:47 -05:00
Jack Christensen fb55203324 Add support for varchar[] 2014-07-31 13:35:44 -05:00
Jack Christensen e29574d447 Add support for integer, float and text arrays
Restructure internals a bit so pgx/stdlib can turn off binary encoding and
receive text back for array types.
2014-07-26 15:03:52 -05:00
Jack Christensen 3144b5363f Support unknown PostgreSQL types as strings 2014-07-19 17:49:11 -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 aff5043df9 Added a lot of documentation 2014-07-12 21:17:38 -05:00
Jack Christensen 4fbd76bee5 Make MsgReader private 2014-07-12 20:08:17 -05:00
Jack Christensen 1cb3ac91f3 EncodeBinary checks oid of param 2014-07-12 09:46:33 -05:00
Jack Christensen ed2b3b3b49 Add timestamp support
But not to NullTime because of text vs binary encoding difficulties.

You really should never use timestamp anyway.
2014-07-12 09:33:49 -05:00
Jack Christensen c108378973 Reorganize code 2014-07-12 08:50:30 -05:00
Jack Christensen 713a8f48a7 Failing to write to Conn.conn kills Conn 2014-07-12 08:04:09 -05:00
Jack Christensen ae6a87545b Use database/sql style transaction interface 2014-07-12 07:59: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 6c1c819a5e Error detection for mismatched types 2014-07-11 16:07:08 -05:00
Jack Christensen 4bdefced66 Add NullTime 2014-07-11 15:25:26 -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 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
Jack Christensen efeaf10a2a Make nextColumn private 2014-07-10 08:13:19 -05:00
Jack Christensen 7d97dca9b1 Remove unused function 2014-07-09 08:23:38 -05:00
Jack Christensen 6ae7f63d00 Remove UnexpectedColumnCountError 2014-07-09 08:18:09 -05:00
Jack Christensen 009cdfa0b1 Use Scan and Encode* instead of ValueTranscoders 2014-07-09 07:56:48 -05:00
Jack Christensen 43dcd47a92 Move to Scan interface
Remove SelectValue
2014-07-05 18:23:19 -05:00
Jack Christensen 5b345e80e1 Remove SelectValueTo
Benchmarks revealed that it is no longer performant enough to pull
its own wait. Using go_db_bench to copy JSON results to HTTP responses
it was ~20% *slower* for ~4BK responses and less than 10% faster for
+1MB responses.

The the performance problem was in io.CopyN / io.Copy. io.Copy
allocates a 32KB buffer if it doesn't have io.WriterTo or io.ReaderFrom
available. This extra alloc on every request was more expensive than
just reading the result into a string and writing it out to the response
body.

Tests indicated that if MsgReader implemented a custom Copy that used a
shared buffer it might have a few percent performance advantage. But the
additional complexity is not worth the performance gain.
2014-07-05 09:32:47 -05:00
Jack Christensen b27d828311 Add RowReader.CopyBytes
Implement SelectValueTo in terms of RowReader.CopyBytes
2014-07-05 07:51:32 -05:00
Jack Christensen 7083c51689 Finish migration to writeBuf 2014-07-04 13:34:27 -05:00
Jack Christensen 81cc33f1ed Use writeBuf more 2014-07-04 13:29:23 -05:00
Jack Christensen 9ab8fb4877 Partially migrate to writeBuf 2014-07-04 13:27:24 -05:00
Jack Christensen b25aea5c52 MsgReader no longer uses double buffering 2014-07-04 13:08:37 -05:00
Jack Christensen 78b8e0b6f2 Safely handle bad reads of QueryResult 2014-06-30 19:01:36 -05:00
Jack Christensen 718c4dfdc8 Add *RowReader.ReadInt64 2014-06-30 08:14:13 -05:00
Jack Christensen d30ef1b8b9 Replace SelectFunc with Query as core 2014-06-28 17:07:31 -05:00
Jack Christensen b6ac3ef2b0 Rename Execute to Exec 2014-06-27 14:56:27 -05:00
Jack Christensen aeb6cea1cf Replace binary.Read
It does memory allocs that can be avoided by passing a slice directly to
binary.BigEndian.*
2014-06-27 08:20:15 -05:00
Jack Christensen e8f367ede4 Use flyweight for DataRowReader 2014-06-27 08:00:32 -05:00
Jack Christensen 84dd626bcc Make MessageReader a type of bytes.Buffer 2014-06-26 18:12:30 -05:00
Jack Christensen 3706b9519f Do not defer in rxMsgHeader
Slightly faster.
2014-06-26 08:39:29 -05:00
Jack Christensen aa6e9d0ddf Improve prepared statement performance
* Do not use bufio.Writer - use net.Conn directly
* Use byte slice instead of bytes.Buffer when building query message
* Use binary.BigEndian.* instead of binary.Write
2014-06-23 18:26:15 -05:00
Jack Christensen 7d0e178424 Determine automatically if Host is socket
Instead of requiring user to specify either Host or Socket unify these fields.
It can be automatically determined whether it is a socket or not.
2014-06-21 12:53:38 -05:00
Jack Christensen d9522a4741 Inform database/sql when connections die 2014-06-20 16:33:51 -05:00
Jack Christensen 7a8e80ac0d Make Conn Close idempotent
* die (which is called by Close) now closes underlying connection
2014-06-20 14:50:36 -05:00
Jack Christensen 247fd3be53 Fix CommandTag RowsAffected for INSERT 2014-06-20 13:38:01 -05:00
Jack Christensen 4efa61bf5b Prepare returns *PreparedStatement 2014-06-20 10:47:31 -05:00
Jack Christensen cc445627b0 Expose DataRowReader FieldDescriptions 2014-06-20 10:46:47 -05:00
Jack Christensen 772c6ca7d7 Remove MessageWriter 2014-06-19 18:10:04 -05:00
Jack Christensen 3b9a1ce659 ValueTranscoder EncodeTo now receives io.Writer 2014-06-19 17:48:26 -05:00
Jack Christensen 884252675e Handle ValueTranscoder EncodeTo returns error on bad type
Instead of panicking
2014-06-19 08:03:14 -05:00
Jack Christensen 5fe3dd7ecf Reduce nesting in message loops 2014-06-17 16:39:44 -05:00
Jack Christensen 928612917d Fix a couple go vet discovered issues 2014-06-11 07:59:43 -05:00
Jack Christensen b982aeb102 Improve logging some more 2014-06-05 17:36:40 -05:00
Jack Christensen ad88123f9c Improve logging 2014-06-04 09:31:54 -05:00
Jack Christensen cbddbb423e Replace logging functionality with log15
gopkg.in/inconshreveable/log15.v2
2014-06-02 19:47:09 -05:00
Jack Christensen f119d5221c Add CommandTag 2014-05-19 09:32:31 -05:00
Jack Christensen bc2a120301 Add constants for transaction isolation levels 2014-05-19 08:25:34 -05:00
Jack Christensen f9a2501100 Rename ConnectionPool to ConnPool 2014-05-17 13:40:50 -05:00
Jack Christensen 1ff653ae15 Rename ConnectionParameters to ConnConfig 2014-05-17 13:38:13 -05:00
Jack Christensen 4eb597d20b Rename pgx.Connection to pgx.Conn 2014-05-17 13:11:30 -05:00
Jack Christensen 70e461b769 Renamed conn* to connection* 2013-04-20 11:55:13 -05:00
Jack Christensen 58ae1855cb Extract Connection.SelectAll* to own file 2013-04-20 11:34:52 -05:00
Jack Christensen e27511a4c5 Extract Connection.Select* to own file 2013-04-20 11:30:06 -05:00
Jack Christensen 0b1ac12c0e Added basic null handling
* Connection.SelectRows leaves null values empty
* Select* and SelectAll* now error on null

refs #4
2013-04-20 11:14:01 -05:00
Jack Christensen ee25d4a03a Rename Select to SelectFunc to conform to Go standard lib style 2013-04-19 16:35:44 -05:00
Jack Christensen bf86100fec Rename Query to SelectRows 2013-04-19 16:18:11 -05:00
Jack Christensen 9a5c299563 Added Select to process rows as they come over the wire
This was accomplished by promoting private query function to
public Select.

fixes #12
2013-04-19 16:10:14 -05:00
Jack Christensen 310c7f5fd8 go fmt 2013-04-19 15:48:45 -05:00
Jack Christensen fa4c70907c Rename pgx.conn to pgx.Connection 2013-04-17 08:26:01 -05:00
Jack Christensen d306d42afb Added conn.Execute to run arbitrary SQL without a result set
fixed #13
2013-04-16 20:13:06 -05:00
Jack Christensen cbf03821e1 Revert making query methods automatically escape arguments.
Must now call SanitizeSql explicitly.

This was necessary because go supports variadic arguments but not
totally optional arguments. So it would require something to
always be passed in.
2013-04-16 19:55:01 -05:00
Jack Christensen 8392883350 Added SQL parameter sanitization
fixes #3
2013-04-15 20:22:28 -05:00
Jack Christensen 2ed4f46454 Refactored query logic so only one place has query message loop
Also combined with this refactor is multiple functions that previously
called a []string function and then casted that to the correct type
now directly read into []correcttypt.
2013-04-13 20:28:54 -05:00
Jack Christensen d2ad78b90e Added SelectAll*
fixes #2
2013-04-13 19:03:00 -05:00
Jack Christensen f977a3fe80 Added Select* for individual typed values.
fixes #1
2013-04-12 16:50:13 -05:00
Jack Christensen 3a85bae314 package name is pgx not pqx 2013-04-12 08:07:05 -05:00
Jack Christensen 1a7cf8ccc4 Added connect with md5 password 2013-04-11 21:39:44 -05:00
Jack Christensen 9e9815ae5a Added plain text password authentication 2013-04-11 21:13:47 -05:00
Jack Christensen 7683e5cfa7 go fmt 2013-04-11 21:12:02 -05:00
Jack Christensen 0e8f00e11c Added understanding of error messages from server 2013-04-11 20:22:55 -05:00
Jack Christensen 3e5096afef Added ability to choose user to log in as 2013-04-11 19:42:24 -05:00
Jack Christensen 996aed65ee Added ability to connect to databases by name
Add documentation to readme on how to set up tests
2013-04-11 08:56:31 -05:00
Jack Christensen bf0891db7d Added basic Query functionality 2013-04-08 21:28:44 -05:00
Jack Christensen 63d16ae3ac Refactor 2013-04-08 21:23:25 -05:00
Jack Christensen f56abaf154 Move connection specific message handling to Connect 2013-04-08 20:50:27 -05:00
Jack Christensen 006a98d1a2 Pass *messageReader to rx* instead of raw buffer 2013-04-08 20:37:09 -05:00
Jack Christensen d6ca7af1e3 Rename processCommonMsg to processContextFeeMsg 2013-04-08 20:25:04 -05:00
Jack Christensen d1a586ed64 go fmt 2013-04-08 20:16:49 -05:00
Jack Christensen 98890b1a50 Store backend pid and secret key 2013-04-08 20:15:34 -05:00
Jack Christensen 34e47ed59e Store runtime parameters 2013-04-08 20:00:48 -05:00
Jack Christensen 577f9707f7 Separate receiving and processing a message 2013-04-06 16:52:06 -04:00
Jack Christensen 0cbf3b6f9e Factor out sendSimpleQuery 2013-04-06 16:39:20 -04:00
Jack Christensen aff1eee892 Basic query functionality 2013-04-06 14:52:08 -04:00
Jack Christensen bc830d4a21 Added conn.Close 2013-03-30 21:53:56 -05:00
Jack Christensen 0e992bbaa5 Extract conn.getBuf 2013-03-30 21:47:27 -05:00
Jack Christensen 9fb925d55e Remove debug prints 2013-03-30 21:21:56 -05:00
Jack Christensen efa94833e4 Extract txStartupMessage 2013-03-30 21:21:10 -05:00
Jack Christensen 24e11001c5 Connect receives messages until ReadyForQuery 2013-03-30 21:20:56 -05:00
Jack Christensen e37c0c9e3a Parse messages up to ready for query 2013-03-30 20:56:51 -05:00
Jack Christensen aefc85a67b Parse ParameterStatus 2013-03-30 20:28:23 -05:00
Jack Christensen 226142ae1b Added rxMsg* 2013-03-30 19:57:37 -05:00
Jack Christensen 18e225b66d go fmt 2013-03-30 18:13:40 -05:00
Jack Christensen 05f94f7107 Messages use Bytes instead of WriteTo 2013-03-30 18:08:47 -05:00
Jack Christensen 5563e0c825 Extracting connection 2013-03-30 17:56:31 -05:00