summaryrefslogtreecommitdiff
path: root/src/database/sql
Commit message (Collapse)AuthorAgeFilesLines
* database/sql: fix wrong method name in descriptionAlexey Palazhchenko2017-07-181-1/+1
| | | | | | Change-Id: Ie6a88b70d7c45c59995ee2f57fb28f9a3cbb404d Reviewed-on: https://go-review.googlesource.com/49470 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: fix outdated package name in doc.txtMartin Garton2017-06-301-1/+1
| | | | | | Change-Id: I4417c5a8537095a6464ce919b2e5cb250e179939 Reviewed-on: https://go-review.googlesource.com/47332 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: ensure a Stmt from a Conn executes on the same driver.ConnDaniel Theophanes2017-06-132-94/+154
| | | | | | | | | | | | | | 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-122-34/+51
| | | | | | | | | | | 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: properly document QueryRowSarah Adams2017-06-121-0/+15
| | | | | | | | Fixes golang/go#20163 Change-Id: I0caf95fc84aa502715848151c93b6e7bee003ea5 Reviewed-on: https://go-review.googlesource.com/44890 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql: prevent race on Rows close with Tx RollbackDaniel Theophanes2017-06-123-12/+85
| | | | | | | | | | | | | | | | | | 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-122-34/+5
| | | | | | | | | | | | | | 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-072-5/+34
| | | | | | | | | | | | | | | | | | | | | | 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-052-13/+56
| | | | | | | | | | | 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-222-7/+54
| | | | | | | | | | | | | | | 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-186-90/+360
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-282-1/+46
| | | | | | | | | | | | | | | | | | 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-242-5/+283
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-122-6/+13
| | | | | | | | | | | | | 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: de-duplicate various methodsDaniel Theophanes2017-04-121-50/+41
| | | | | | | | | | | | | | | | Form a new method pattern where *driverConn and release functions are passed into the method. They are named DB.execDC, DB.queryDC, DB.beginDC. This allows more code to be de-duplicated when starting queries. The Stmt creation and management code are untouched. Change-Id: I24c853531e511d8a4bc1f53dd4dbdf968763b4e7 Reviewed-on: https://go-review.googlesource.com/39630 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: support scanning into user defined string typesDaniel Theophanes2017-03-313-3/+42
| | | | | | | | | | | | | | | | 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-082-31/+265
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: ensure driverConns are closed if not returned to poolDaniel Theophanes2017-02-101-2/+2
| | | | | | | | | | | | | | Previously if a connection was requested but timed out during the request and when acquiring the db.Lock the connection request is fulfilled and the request is unable to be returned to the connection pool, then then driver connection would not be closed. No tests were added or modified because I was unable to determine how to trigger this situation without something invasive. Change-Id: I9d4dc680e3fdcf63d79d212174a5b8b313f363f1 Reviewed-on: https://go-review.googlesource.com/36641 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-092-13/+93
| | | | | | | | | | | | | | | | | 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: fix typoKevin Burke2017-02-091-1/+1
| | | | | | Change-Id: I09fdcebb939417f18af09ed57f24460724cab64f Reviewed-on: https://go-review.googlesource.com/36632 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* database/sql: record the context error in Rows if canceledDaniel Theophanes2017-02-083-66/+100
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-012-2/+2
| | | | | | 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-262-35/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* all: fix misspellingsshawnps2017-01-071-1/+1
| | | | | | | | | Change-Id: I429637ca91f7db4144f17621de851a548dc1ce76 Reviewed-on: https://go-review.googlesource.com/34923 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Ian Lance Taylor <iant@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-022-5/+52
| | | | | | | | | | | | | | | | | | 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-145-77/+56
| | | | | | | | | | | | | 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: use complete sentences in new docsBrad Fitzpatrick2016-12-091-6/+13
| | | | | | | Change-Id: Icb842a80cab2b07b9ace1e8e14c4a19c48a92c43 Reviewed-on: https://go-review.googlesource.com/34247 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql: document that drivers may not return right after cancelDaniel Theophanes2016-12-091-1/+4
| | | | | | | | Fixes #18168 Change-Id: Idbfe3d4daedd93c7caf6f1770ecd988e9af39949 Reviewed-on: https://go-review.googlesource.com/34144 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: ensure Commit and Rollback return ErrTxDoneDaniel Theophanes2016-12-012-3/+34
| | | | | | | | | | | | | 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-015-9/+35
| | | | | | | | | | 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-302-5/+26
| | | | | | | | | | | | | 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-303-12/+23
| | | | | | | | | | | | 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-295-217/+242
| | | | | | | | | | | | | | | | | 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: force users of NamedParam to name struct literals fieldsBrad Fitzpatrick2016-11-241-0/+2
| | | | | | | | | | | Or they can use sql.Param instead. Change-Id: Icf21dbcc87170635c3f5d3f49736429a37abe9da Reviewed-on: https://go-review.googlesource.com/33576 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Minux Ma <minux@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-172-77/+88
| | | | | | | | | | | | | | 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>
* database/sql: additional underlying types in DefaultValueConverterScott Bell2016-11-172-3/+29
| | | | | | | | | | | | | | The previous documentation purported to convert underlying strings to []byte, which it did not do. This adds support for underlying bool, string, and []byte, which convert directly to their underlying type. Fixes #15174. Change-Id: I7fc4e2520577f097a48f39c9ff6c8160fdfb7be4 Reviewed-on: https://go-review.googlesource.com/27812 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
* database/sql: guard against driver.Stmt.Close panicsDaniel Theophanes2016-11-161-11/+13
| | | | | | | | | | | | Do not retain a lock when driver.Stmt.Close panic as the rest of the sql package ensures. Updates #16019 Change-Id: Idc7ea9258ae23f491e79cce3efc365684a708428 Reviewed-on: https://go-review.googlesource.com/33328 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: clarify when statement in transaction is closedIan Lance Taylor2016-11-161-6/+6
| | | | | | | | | Fixes #16346. Change-Id: Ie75a4ae7011036dd2c1f121a7a5e38d10177721e Reviewed-on: https://go-review.googlesource.com/33296 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@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: correctly spell constantsKevin Burke2016-10-311-3/+5
| | | | | | | | | | | | Also add a link to more information about isolation levels as defined by the SQL standard. Fixes #17682. Change-Id: I94c53b713f4c882af40cf15fe5f1e5dbc53ea741 Reviewed-on: https://go-review.googlesource.com/32418 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: add Pinger interface to driver ConnINADA Naoki2016-10-313-6/+73
| | | | | | | | | 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: add context helper methods and transaction typesDaniel Theophanes2016-10-304-8/+94
| | | | | | | | | | | | | | | Prior to this change, it was implied that transaction properties would be carried in the context value. However, no such properties were defined, not even common ones. Define two common properties: isolation level and read-only. Drivers may choose to support additional transaction properties. It is not expected any further transaction properties will be added in the future. Change-Id: I2f680115a14a1333c65ba6f943d9a1149d412918 Reviewed-on: https://go-review.googlesource.com/31258 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@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>