summaryrefslogtreecommitdiff
path: root/src/database/sql/sql_test.go
Commit message (Collapse)AuthorAgeFilesLines
* database/sql: ensure a Stmt from a Conn executes on the same driver.ConnDaniel Theophanes2017-06-131-1/+37
| | | | | | | | | | | | | | Ensure a Stmt prepared on a Conn executes on the same driver.Conn. This also removes another instance of duplicated prepare logic as a side effect. Fixes #20647 Change-Id: Ia00a19e4dd15e19e4d754105babdff5dc127728f Reviewed-on: https://go-review.googlesource.com/45391 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: correct level of write to same var for race detectorDaniel Theophanes2017-06-121-8/+4
| | | | | | | | | | | Rather then write to the same variable per fakeConn, write to either fakeConn or rowsCursor. Fixes #20646 Change-Id: Ifc79f989bd1606b8e3ebecb1e7844cce3ad06e17 Reviewed-on: https://go-review.googlesource.com/45393 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: prevent race on Rows close with Tx RollbackDaniel Theophanes2017-06-121-11/+64
| | | | | | | | | | | | | | | | | | In addition to adding a guard to the Rows close, add a var in the fakeConn that gets read and written to on each operation, simulating writing or reading from the server. TestConcurrency/TxStmt* tests have been commented out as they now fail after checking for races on the fakeConn. See issue #20646 for more information. Fixes #20622 Change-Id: I80b36ea33d776e5b4968be1683ff8c61728ee1ea Reviewed-on: https://go-review.googlesource.com/45275 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* Revert "database/sql: Use Tx.ctx in Tx non-context methods"Daniel Theophanes2017-06-121-29/+0
| | | | | | | | | | | | | | This reverts commit ef0f7fb92b9458d7d35ee3c10ae853e3dc3077eb. Reason for revert: Altered behavior of Queries prior to Tx commit. See #20631. Change-Id: I2548507c2935a7c60b92aae377dcc8e9aca66331 Reviewed-on: https://go-review.googlesource.com/45231 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Bulat Gaifullin <gaifullinbf@gmail.com> Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: Use Tx.ctx in Tx non-context methodsBulat Gaifullin2017-06-071-0/+29
| | | | | | | | | | | | | | | | | | | | | | The Tx methods Query and Exec uses context.Background() even Tx was created by context. This patch enables using Tx.ctx in all Tx methods which do not has context arg. Backward compatibility: - If Tx has created without context, nothing changes. - If Tx has created with context and non-context method is called: - If context is expired, the execution fails, but it can fail on Commit or Rollback as well, so in terms of whole transaction - nothing changes. - If context is not expired, nothing changes too. Fixes #20098 Change-Id: I9570a2deaace5875bb4c5dcf7b3a084a6bcd0d00 Reviewed-on: https://go-review.googlesource.com/44956 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: ensure Rows is closed when Tx closesDaniel Theophanes2017-06-051-0/+26
| | | | | | | | | | | Close any Rows queried within a Tx when the Tx is closed. This prevents the Tx from blocking on rollback if a Rows query has not been closed yet. Fixes #20575 Change-Id: I4efe9c4150e951d8a0f1c40d9d5e325964fdd608 Reviewed-on: https://go-review.googlesource.com/44812 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: allow Stmt Query and Exec methods to open a new connDaniel Theophanes2017-05-221-1/+40
| | | | | | | | | | | | | | | Query and Exec functions on DB first attempt to get a cached connection before requesting the connection pool to ignore the cache and get a new connection. This change aligns Stmt to that behavior as well. Fixes #20433 Change-Id: Idda5f61927289d7ad0882effa3a50ffc9efd88e6 Reviewed-on: https://go-review.googlesource.com/43790 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: allow drivers to support custom arg typesDaniel Theophanes2017-05-181-0/+125
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously all arguments were passed through driver.IsValid. This checked arguments against a few fundamental go types and prevented others from being passed in as arguments. The new interface driver.NamedValueChecker may be implemented by both driver.Stmt and driver.Conn. This allows this new interface to completely supersede the driver.ColumnConverter interface as it can be used for checking arguments known to a prepared statement and arbitrary query arguments. The NamedValueChecker may be skipped with driver.ErrSkip after all special cases are exhausted to use the default argument converter. In addition if driver.ErrRemoveArgument is returned the argument will not be passed to the query at all, useful for passing in driver specific per-query options. Add a canonical Out argument wrapper to be passed to OUTPUT parameters. This will unify checks that need to be written in the NameValueChecker. The statement number check is also moved to the argument converter so the NamedValueChecker may remove arguments passed to the query. Fixes #13567 Fixes #18079 Updates #18417 Updates #17834 Updates #16235 Updates #13067 Updates #19797 Change-Id: I89088bd9cca4596a48bba37bfd20d987453ef237 Reviewed-on: https://go-review.googlesource.com/38533 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: ensure releaseConn is defined before a possible closeDaniel Theophanes2017-04-281-0/+40
| | | | | | | | | | | | | | | | | | When running a Query on Stmt a dependency is added to the stmt and rows. To do that it needs a reference to Rows, so the releaseConn function is defined after the definition. However the rows.initContextClose was set to run before the releaseConn was set on rows, setting up a situation where the connection could be canceled before the releaseConn was set and resulting in a segfault. Fixes #20160 Change-Id: I5592e7db2cf653dfc48d42cbc2b03ca20501b1a0 Reviewed-on: https://go-review.googlesource.com/42139 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: allow using a single connection from the databaseDaniel Theophanes2017-04-241-0/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Databases have the following concepts: Statement, Batch, and Session. A statement is often a single line like: SELECT Amount from Account where ID = 50; A batch is one or more statements submitted together for the query to process. It may be a DELETE, INSERT, two UPDATES and a SELECT in a single query text. A session is usually represented by a single database connection. This often is an issue when dealing with scopes in databases. Temporary tables and variables can have batch, session, or global scope depending on the syntax, database, and use. Furthermore, some databases (sybase and derivatives in perticular) that prevent certain statements from being in the same batch and may necessitate being in the same session. By allowing users to extract a Conn from the database they can manage session on their own without hacking around it by making connection pools of single connections (a real workaround presented in issue). It is tempting to just use a transaction, but this isn't always desirable or an option if running an interactive session or alter script set that itself starts transactions. Fixes #18081 Change-Id: I9bdf0796632c48d4bcaef3624c629641984ffaf2 Reviewed-on: https://go-review.googlesource.com/40694 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: correctly guard the query Row preventing early releaseDaniel Theophanes2017-04-121-1/+0
| | | | | | | | | | | | | When a Tx starts a query, prevent returning the connection to the pool until after the query finishes. Fixes #19058 Change-Id: I2c0480d9cca9eeb173b5b3441a5aeed6f527e0ac Reviewed-on: https://go-review.googlesource.com/40400 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: support scanning into user defined string typesDaniel Theophanes2017-03-311-0/+18
| | | | | | | | | | | | | | | | User defined numeric types such as "type Int int64" have been able to be scanned into without a custom scanner by using the reflect scan code path used to convert between various numeric types. Add in a path for string types for symmetry and least surprise. Fixes #18101 Change-Id: I00553bcf021ffe6d95047eca0067ee94b54ff501 Reviewed-on: https://go-review.googlesource.com/39031 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: fix spelling mistake in testsKevin Burke2017-03-081-1/+1
| | | | | | Change-Id: I04e150d4e4123aad2f277e5c6e9f2abd15628a28 Reviewed-on: https://go-review.googlesource.com/37941 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: proper prepared statement support in transactionsSarah Adams2017-03-081-0/+190
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change was originally written by Marko Tiikkaja <marko@joh.to>. https://go-review.googlesource.com/#/c/2035/ Previously *Tx.Stmt always prepared a new statement, even if an existing one was available on the connection the transaction was on. Now we first see if the statement is already available on the connection and only prepare if it isn't. Additionally, when we do need to prepare one, we store it in the parent *Stmt to allow it to be later reused by other calls to *Tx.Stmt on that statement or just straight up by *Stmt.Exec et al. To make sure that the statement doesn't disappear unexpectedly, we record a dependency from the statement returned by *Tx.Stmt to the *Stmt it came from and set a new field, parentStmt, to point to the originating *Stmt. When the transaction's *Stmt is closed, we remove the dependency. This way the "parent" *Stmt can be closed by the user without her having to know whether any transactions are still using it or not. Fixes #15606 Change-Id: I41b5056847e117ac61130328b0239d1e000a4a08 Reviewed-on: https://go-review.googlesource.com/35476 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql: convert test timeouts to explicit waits with checksDaniel Theophanes2017-02-131-20/+37
| | | | | | | | | | | | | | | | When testing context cancelation behavior do not rely on context timeouts. Use explicit checks in all such tests. In closeDB convert the simple check for zero open conns with a wait loop for zero open conns. Fixes #19024 Fixes #19041 Change-Id: Iecfcc4467e91249fceb21ffd1f7c62c58140d8e9 Reviewed-on: https://go-review.googlesource.com/36902 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* database/sql: replace the expr of timeunit * N with N * timeunit in testMikio Hara2017-02-091-7/+7
| | | | | | | | Change-Id: I97981b30a9629916f896cb989cc2a42a8bdbef47 Reviewed-on: https://go-review.googlesource.com/36672 Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: fix nits in testMikio Hara2017-02-091-3/+5
| | | | | | | | Change-Id: I451b33d8da8d97917f2b257e6a25392c6e6582db Reviewed-on: https://go-review.googlesource.com/36671 Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: do not exhaust connection pool on conn request timeoutDaniel Theophanes2017-02-091-0/+57
| | | | | | | | | | | | | | | | | Previously if a context was canceled while it was waiting for a connection request, that connection request would leak. To prevent this remove the pending connection request if the context is canceled and ensure no connection has been sent on the channel. This requires a change to how the connection requests are represented in the DB. Fixes #18995 Change-Id: I9a274b48b8f4f7ca46cdee166faa38f56d030852 Reviewed-on: https://go-review.googlesource.com/36563 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: record the context error in Rows if canceledDaniel Theophanes2017-02-081-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously it was intended that Rows.Scan would return an error and Rows.Err would return nil. This was problematic because drivers could not differentiate between a normal Rows.Close or a context cancel close. The alternative is to require drivers to return a Scan to return an error if the driver is closed while there are still rows to be read. This is currently not how several drivers currently work and may be difficult to detect when there are additional rows. At the same time guard the the Rows.lasterr and prevent a close while a Rows operation is active. For the drivers that do not have Context methods, do not check for context cancelation after the operation, but before for any operation that may modify the database state. Fixes #18961 Change-Id: I49a25318ecd9f97a35d5b50540ecd850c01cfa5e Reviewed-on: https://go-review.googlesource.com/36485 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: fix spelling mistakeKevin Burke2017-02-011-1/+1
| | | | | | Change-Id: I67db3b342929a7bd11f01bf3b9afb49f4da69a0a Reviewed-on: https://go-review.googlesource.com/35841 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: fix race when canceling queries immediatelyDaniel Theophanes2017-01-261-8/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously the following could happen, though in practice it would be rare. Goroutine 1: (*Tx).QueryContext begins a query, passing in userContext Goroutine 2: (*Tx).awaitDone starts to wait on the context derived from the passed in context Goroutine 1: (*Tx).grabConn returns a valid (*driverConn) The (*driverConn) passes to (*DB).queryConn Goroutine 3: userContext is canceled Goroutine 2: (*Tx).awaitDone unblocks and calls (*Tx).rollback (*driverConn).finalClose obtains dc.Mutex (*driverConn).finalClose sets dc.ci = nil Goroutine 1: (*DB).queryConn obtains dc.Mutex in withLock ctxDriverPrepare accepts dc.ci which is now nil ctxCriverPrepare panics on the nil ci The fix for this is to guard the Tx methods with a RWLock holding it exclusivly when closing the Tx and holding a read lock when executing a query. Fixes #18719 Change-Id: I37aa02c37083c9793dabd28f7f934a1c5cbc05ea Reviewed-on: https://go-review.googlesource.com/35550 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: let tests wait for db pool to come to expected stateDaniel Theophanes2017-01-251-16/+16
| | | | | | | | | | | | | | | Slower builders were failing TestQueryContext because the cancel and return to conn pool happens async. TestQueryContext already uses a wait method for this reason. Use the same method for other context tests. Fixes #18759 Change-Id: I84cce697392b867e4ebdfadd38027a06ca14655f Reviewed-on: https://go-review.googlesource.com/35750 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: fix typo and wordingKevin Burke2017-01-021-6/+6
| | | | | | | | | Clean up the phrasing a little bit, make the comment fit in 80 characters, and fix the spelling of "guard." Change-Id: I688a3e760b8d67ea83830635f64dff04dd9a5911 Reviewed-on: https://go-review.googlesource.com/34792 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: prevent Tx.rollback from racing Tx.closeDaniel Theophanes2017-01-021-0/+48
| | | | | | | | | | | | | | | | | | Previously Tx.done was being set in close, but in a Tx rollback and Commit are the real closing methods, and Tx.close is just a helper common to both. Prior to this change a multiple rollback statements could be called, one would enter close and begin closing it while the other was still in rollback breaking it. Fix that by setting done in rollback and Commit, not in Tx.close. Fixes #18429 Change-Id: Ie274f60c2aa6a4a5aa38e55109c05ea9d4fe0223 Reviewed-on: https://go-review.googlesource.com/34716 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: do not store Tx options in ContextDaniel Theophanes2016-12-141-1/+1
| | | | | | | | | | | | | Drivers which previously supported tip will need to update to this revision before release. Fixes #18284 Change-Id: I70b8e7afff1558a8b5348885ce9f50e067c72ee9 Reviewed-on: https://go-review.googlesource.com/34330 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: ensure Commit and Rollback return ErrTxDoneDaniel Theophanes2016-12-011-0/+31
| | | | | | | | | | | | | Ensure documented behavior of returning ErrTxDone if the Tx has already been committed or rolled back. Fixes #18147 Change-Id: I07dc75bef4dbd4dd88dd252c96dc8ab99f28c00e Reviewed-on: https://go-review.googlesource.com/33793 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: document expectations for named parametersDaniel Theophanes2016-12-011-2/+2
| | | | | | | | | | Require parameter names to not begin with a symbol. Change-Id: I5dfe9d4e181f0daf71dad2f395aca41c68678cbe Reviewed-on: https://go-review.googlesource.com/33493 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: deflake query cancel testsDaniel Theophanes2016-11-301-4/+15
| | | | | | | | | | | | | Rather then using a sleep in the fake DB, go to a channel select and wait for the context to be done. Fixes #18115 Change-Id: I6bc3a29db58c568d0a7ea06c2a354c18c9e798b2 Reviewed-on: https://go-review.googlesource.com/33712 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: rename NamedParam to NamedArg and Param to NamedDaniel Theophanes2016-11-301-3/+3
| | | | | | | | | | | | Be consistent with the argument names already provided. Also parameter is the variable, argument is the value. Fixes #18099 Change-Id: Idb3f4e9ffc214036c721ddb4f614ec6c95bb7778 Reviewed-on: https://go-review.googlesource.com/33660 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* database/sql: do not bypass the driver locks with Context methodsDaniel Theophanes2016-11-291-4/+76
| | | | | | | | | | | | | | | | | When context methods were initially added it was attempted to unify behavior between drivers without Context methods and those with Context methods to always return right away when the Context expired. However in doing so the driver call could be executed outside of the scope of the driver connection lock and thus bypassing thread safety. The new behavior waits until the driver operation is complete. It then checks to see if the context has expired and if so returns that error. Change-Id: I4a5c7c3263420c57778f36a5ed6fa0ef8cb32b20 Reviewed-on: https://go-review.googlesource.com/32422 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: fix TestPendingConnsAfterErrDaniel Theophanes2016-11-221-9/+31
| | | | | | | | | | | | | | | | | | TestPendingConnsAfterErr showed a failure on slower systems. Wait and check for the database to close all connections before pronouncing failure. A more careful method was attempted but the connection pool behavior is too dependent on the scheduler behavior to be predictable. Fixes #15684 Change-Id: Iafdbc90ba51170c76a079db04c3d5452047433a4 Reviewed-on: https://go-review.googlesource.com/33418 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: ensure all driver Stmt are closed onceDaniel Theophanes2016-11-171-1/+1
| | | | | | | | | | | | | | Previously driver.Stmt could could be closed multiple times in edge cases that drivers may not test for initially. Make their job easier by ensuring the driver is only closed a single time. Fixes #16019 Change-Id: I1e4777ef70697a849602e6ef9da73054a8feb4cd Reviewed-on: https://go-review.googlesource.com/33352 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: don't call t.Fatal from a goroutineIan Lance Taylor2016-11-151-1/+2
| | | | | | | | | | Fixes #17900. Change-Id: I42cda6ac9cf48ed739d3a015a90b3cb15edf8ddf Reviewed-on: https://go-review.googlesource.com/33243 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: add Pinger interface to driver ConnINADA Naoki2016-10-311-0/+44
| | | | | | | | | Change-Id: If6eb3a7c9ad48a517e584567b1003479c1df6cca Reviewed-on: https://go-review.googlesource.com/32136 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: fix possible context leak in testAlexander Döring2016-10-241-0/+1
| | | | | | | | | | Fixes #17560 Change-Id: I96fcdec87220391ef5432571b5c090b5be27491a Reviewed-on: https://go-review.googlesource.com/31771 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: update the conversion errors to be clearerDaniel Theophanes2016-10-211-2/+2
| | | | | | | | | | | | | | There was some ambiguity over which argument was referred to when a conversion error was returned. Now refer to the argument by either explicit ordinal position or name if present. Fixes #15676 Change-Id: Id933196b7e648baa664f4121fa3fb1b07b3c4880 Reviewed-on: https://go-review.googlesource.com/31262 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: support returning query database typesDaniel Theophanes2016-10-181-0/+50
| | | | | | | | | | | | | Creates a ColumnType structure that can be extended in to future. Allow drivers to implement what makes sense for the database. Fixes #16652 Change-Id: Ieb1fd64eac1460107b1d3474eba5201fa300a4ec Reviewed-on: https://go-review.googlesource.com/29961 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: add option to use named parameter in query argumentsDaniel Theophanes2016-10-171-0/+47
| | | | | | | | | | | | | | | Modify the new Context methods to take a name-value driver struct. This will require more modifications to drivers to use, but will reduce the overall number of structures that need to be maintained over time. Fixes #12381 Change-Id: I30747533ce418a1be5991a0c8767a26e8451adbd Reviewed-on: https://go-review.googlesource.com/30166 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: add support for multiple result setsDaniel Theophanes2016-10-151-0/+76
| | | | | | | | | | | | | | | Many database systems allow returning multiple result sets in a single query. This can be useful when dealing with many intermediate results on the server and there is a need to return more then one arity of data to the client. Fixes #12382 Change-Id: I480a9ac6dadfc8743e0ba8b6d868ccf8442a9ca1 Reviewed-on: https://go-review.googlesource.com/30592 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: close Rows when context is cancelledDaniel Theophanes2016-09-291-0/+58
| | | | | | | | | | To prevent leaking connections, close any open Rows when the context is cancelled. Also enforce context cancel while reading rows off of the wire. Change-Id: I62237ecdb7d250d6734f6ce3d2b0bcb16dc6fda7 Reviewed-on: https://go-review.googlesource.com/29957 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: add context methodsDaniel Theophanes2016-09-271-3/+6
| | | | | | | | | | | | | | | | | | | | Add context methods to sql and sql/driver methods. If the driver doesn't implement context methods the connection pool will still handle timeouts when a query fails to return in time or when a connection is not available from the pool in time. There will be a follow-up CL that will add support for context values that specify transaction levels and modes that a driver can use. Fixes #15123 Change-Id: Ia99f3957aa3f177b23044dd99d4ec217491a30a7 Reviewed-on: https://go-review.googlesource.com/29381 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: don't hang if the driver Exec method panicsIan Lance Taylor2016-08-291-0/+47
| | | | | | | | | | Fixes #13677. Fixes #15901. Change-Id: Idffb82cdcba4985954d061bdb021217f47ff4984 Reviewed-on: https://go-review.googlesource.com/23576 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: deflake TestPendingConnsAfterErr and fix races, panicsBrad Fitzpatrick2016-06-281-2/+4
| | | | | | | | | | | | | | | | | | | TestPendingConnsAfterErr only cared that things didn't deadlock, so 5 seconds is a sufficient timer. We don't need 100 milliseconds. I was able to reproduce with a tiny (5 nanosecond) timeout value, instead of 100 milliseconds. In the process of testing with -race and a high -count= value, I noticed several data races and panics (sendings on a closed channel) which are also fixed in this change. Fixes #15684 Change-Id: Ib4605fcc0f296e658cb948352ed642b801cb578c Reviewed-on: https://go-review.googlesource.com/24550 Reviewed-by: Marko Tiikkaja <marko@joh.to> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
* all: single space after period.Brad Fitzpatrick2016-03-021-1/+1
| | | | | | | | | | | | | | | | | | | | The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: fix typos and spellingMartin Möhrmann2016-02-241-1/+1
| | | | | | | | Change-Id: Icd06d99c42b8299fd931c7da821e1f418684d913 Reviewed-on: https://go-review.googlesource.com/19829 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: guard against panics in driver.Stmt implementationRuss Cox2016-01-081-0/+40
| | | | | | | | For #13677, but there is more to do. Change-Id: Id1af999dc972d07cdfc771e5855a1a7dca47ca96 Reviewed-on: https://go-review.googlesource.com/18046 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: Add DB.SetConnMaxLifetimeINADA Naoki2015-12-021-30/+101
| | | | | | | | | | | | | | | | | | Long lived connections may make some DB operation difficult. (e.g. retiring load balanced DB server.) So SetConnMaxLifetime closes long lived connections. It can be used to limit maximum idle time, too. Closing idle connections reduces active connections while application is idle and avoids connections are closed by server side (cause errBadConn while querying). fixes #9851 Change-Id: I2e8e824219c1bee7f4b885d38ed96d11b7202b56 Reviewed-on: https://go-review.googlesource.com/6580 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: avoid deadlock waiting for connectionsChris Hines2015-10-161-0/+61
| | | | | | | | | | | | | | | | | | | | | Previously with db.maxOpen > 0, db.maxOpen+n failed connection attempts started concurrently could result in a deadlock. DB.conn and DB.openNewConnection did not trigger the DB.connectionOpener go routine after a failed connection attempt. This omission could leave go routines waiting for DB.connectionOpener forever. In addition the logic to track the state of the pool was inconsistent. db.numOpen was sometimes incremented optimistically and sometimes not. This change harmonizes the logic and eliminates the db.pendingOpens variable, making the logic easier to understand and maintain. Fixes #10886 Change-Id: I983c4921a3dacfbd531c3d7f8d2da8a592e9922a Reviewed-on: https://go-review.googlesource.com/14547 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: fix case where Stmt.Close discards errorIan Gudger2015-10-021-0/+38
| | | | | | | | | | | | Fixes a case where the Stmt.Close() function in database/sql discards any error generated by the Close() function of the contained driverStmt. Fixes #12798 Change-Id: I40384d6165856665b062d15a643e4ecc09d63fda Reviewed-on: https://go-review.googlesource.com/15178 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: close bad connections in commit or rollback:Chris Hines2015-09-031-0/+71
| | | | | | | | | | | | | | | | Previously Tx.close always passed a nil error to tx.db.putConn. As a result bad connections were reused, even if the driver returned driver.ErrBadConn. Adding an err parameter to Tx.close allows it to receive the driver error from Tx.Commit and Tx.Rollback and pass it to tx.db.putConn. Fixes #11264 Change-Id: I142b6b2509fa8d714bbc135cef7281a40803b3b8 Reviewed-on: https://go-review.googlesource.com/13912 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>