aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/database/sql/sql.go
AgeCommit message (Collapse)Author
2013-11-01[release-branch.go1.2] database/sql: document Result methodsAndrew Gerrand
««« CL 19280046 / 2ad8ac71220d database/sql: document Result methods Fixes #5110 R=golang-dev, r CC=golang-dev https://golang.org/cl/19280046 »»» R=golang-dev CC=golang-dev https://golang.org/cl/20650043
2013-11-01[release-branch.go1.2] database/sql: Fix typos in docAndrew Gerrand
««« CL 17590043 / fb5224487f1b database/sql: Fix typos in doc R=golang-dev CC=bradfitz, golang-dev https://golang.org/cl/17590043 »»» R=golang-dev CC=golang-dev https://golang.org/cl/20150046
2013-11-01[release-branch.go1.2] database/sql: link to wiki in package docsAndrew Gerrand
««« CL 14087043 / 7ebbddd21330 database/sql: link to wiki in package docs Update #5886 R=golang-dev, kamil.kisiel, adg, r, rsc, dave, arnehormann, bradfitz CC=golang-dev https://golang.org/cl/14087043 »»» R=golang-dev CC=golang-dev https://golang.org/cl/20610043
2013-10-16database/sql: Fix connection leak and potential deadlockAlberto García Hierro
CL 10726044 introduced a race condition which causes connections to be leaked under certain circumstances. If SetMaxOpenConns is used, the application eventually deadlocks. Otherwise, the number of open connections just keep growing indefinitely. Fixes #6593 R=golang-dev, bradfitz, tad.glines, bketelsen CC=golang-dev https://golang.org/cl/14611045
2013-10-16database/sql: fix double decrement of numOpen count; test for connection leaksAlberto García Hierro
Add a check at the end of every test to make sure there are no leaked connections after running a test. Avoid incorrectly decrementing the number of open connections when the driver connection ends up it a bad state (numOpen was decremented twice). Prevent leaking a Rows struct (which ends up leaking a connection) in Row.Scan() when a *RawBytes destination is improperly used. Close the Rows struct in TestRowsColumns. Update #6593 R=golang-dev, bradfitz, dave CC=golang-dev https://golang.org/cl/14642044
2013-08-30database/sql: add SetMaxOpenConnsTad Glines
Update #4805 Add the ability to set an open connection limit. Fixed case where the Conn finalCloser was being called with db.mu locked. Added separate benchmarks for each path for Exec and Query. Replaced slice based idle pool with list based idle pool. R=bradfitz CC=golang-dev https://golang.org/cl/10726044
2013-08-29undo CL 10726044 / c9bea548fb6fBrad Fitzpatrick
Breaks build, and has a race. ««« original CL description database/sql: add SetMaxOpenConns Update #4805 Add the ability to set an open connection limit. Fixed case where the Conn finalCloser was being called with db.mu locked. Added seperate benchmarks for each path for Exec and Query. Replaced slice based idle pool with list based idle pool. R=bradfitz CC=golang-dev https://golang.org/cl/10726044 »»» R=golang-dev CC=golang-dev https://golang.org/cl/13252046
2013-08-29database/sql: add SetMaxOpenConnsTad Glines
Update #4805 Add the ability to set an open connection limit. Fixed case where the Conn finalCloser was being called with db.mu locked. Added seperate benchmarks for each path for Exec and Query. Replaced slice based idle pool with list based idle pool. R=bradfitz CC=golang-dev https://golang.org/cl/10726044
2013-08-16database/sql: make Rows.Next returning false always implicitly callNigel Tao
Rows.Close. Previously, callers that followed the example code (but not call rows.Close after "for rows.Next() { ... }") could leak statements if the driver returned an error other than io.EOF. R=bradfitz, alex.brainman CC=golang-dev, rsc https://golang.org/cl/12677050
2013-08-14database/sql: fix accumulation of bad conns on prepared statementsMatt Joiner
Fixes an issue where prepared statements that outlive many connections become expensive to invoke. Fixes #6081 R=golang-dev CC=bradfitz, golang-dev https://golang.org/cl/12646044
2013-08-13database/sql: add a disabled broken testBrad Fitzpatrick
Update #6081 R=golang-dev, gri CC=golang-dev https://golang.org/cl/12810043
2013-07-23database/sql: close statement before connectionAlex Brainman
Fixes #5936 R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/11620046
2013-05-21database/sql: remove extra RemoveDep callBrad Fitzpatrick
This should have been removed in 45c12efb4635. Not a correctness issue, but unnecessary work. This CL also adds paranoia checks in removeDep so this doesn't happen again. Fixes #5502 R=adg CC=gobot, golang-dev, google https://golang.org/cl/9543043
2013-05-14database/sql: use method values instead of generating closuresBrad Fitzpatrick
Reduces garbage. R=adg, r CC=dsymonds, gobot, golang-dev https://golang.org/cl/9088045
2013-05-06database/sql: remove an unused field from RowsBrad Fitzpatrick
Found while debugging memory usage. Nobody accesses this field anymore. R=golang-dev, i.caught.air, adg, r CC=golang-dev https://golang.org/cl/9108043
2013-04-25database/sql: fix driver Conn refcounting with prepared statementsBrad Fitzpatrick
The refcounting of driver Conns was completedly busted and would leak (be held open forever) with any reasonable load. This was a significant regression from Go 1.0. The core of this patch is removing one line: s.db.addDep(dc, s) A database conn (dc) is a resource that be re-created any time (but cached for speed) should not be held open forever with a dependency refcount just because the Stmt (s) is alive (which typically last for long periods of time, like forever). The meat of the patch is new tests. In fixing the real issue, a lot of tests then failed due to the fakedb_test.go's paranoia about closing a fakeConn while it has open fakeStmts on it. I could've ignored that, but that's been a problem in the past for other bugs. Instead, I now track per-Conn open statements and close them when the the conn closes. The proper way to do this would've been making *driverStmt a finalCloser and using the dep mechanism, but it was much more invasive. Added a TODO instead. I'd like to give a way for drivers to opt-out of caring about driver.Stmt closes before a driver.Conn close, but that's a TODO for the future, and that TODO is added in this CL. I know this is very late for Go 1.1, but database/sql is currently nearly useless without this. I'd like to believe all these database/sql bugs in the past release cycle are the result of increased usage, number of drivers, and good feedback from increasingly-capable Go developers, and not the result of me sucking. It's also hard with all the real drivers being out-of-tree, so I'm having to add more and more hooks to fakedb_test.go to simulate things which real drivers end up doing. Fixes #5323 R=golang-dev, snaury, gwenn.kahz, google, r CC=golang-dev https://golang.org/cl/8836045
2013-04-15database/sql: close driver Stmt before releasing ConnBrad Fitzpatrick
From the issue, which describes it as well as I could: database/sql assumes that driver.Stmt.Close does not need the connection. see database/sql/sql.go:1308: This puts the Rows' connection back into the idle pool, and then calls the driver.Stmt.Close method of the Stmt it belongs to. In the postgresql driver implementation (https://github.com/lib/pq), Stmt.Close communicates with the server (on the connection that was just put back into the idle pool). Most of the time, this causes no problems, but if another goroutine makes a query at the right (wrong?) time, chaos results. In any case, traffic is being sent on "free" connections shortly after they are freed, leading to race conditions that kill the driver code. Fixes #5283 R=golang-dev, r CC=golang-dev https://golang.org/cl/8633044
2013-04-03database/sql: improve standard deviation response time under high concurrencyJames Tucker
See https://github.com/raggi/go-and-java for runtime benchmark. The patch reduces the amount of map key search, moving connection oriented variables onto the connection structs. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/8092045
2013-03-25database/sql: optimized []byte copy + []byte(nil) -> *interface fixJulien Schmidt
Make the copy directly in the convert switch instead of an extra loop. Also stops converting nil-[]byte to zero-[]byte when assigning to *interface R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/7962044
2013-03-25database/sql: link to driver wiki pageBrad Fitzpatrick
Fixes #5127 R=golang-dev, adg CC=golang-dev https://golang.org/cl/8011044
2013-03-25database/sql: don't close a driver.Conn until its Stmts are closedBrad Fitzpatrick
Fixes #5046 R=golang-dev, r CC=golang-dev https://golang.org/cl/8016044
2013-03-18database/sql: doc cleanup on the DB typeBrad Fitzpatrick
R=golang-dev, adg CC=golang-dev https://golang.org/cl/7865044
2013-03-18database/sql: add DB.SetMaxIdleConnsBrad Fitzpatrick
Update #4805 R=golang-dev, r CC=golang-dev https://golang.org/cl/7634045
2013-03-18database/sql: allow simultaneous queries, etc in a TxBrad Fitzpatrick
Now that revision 0c029965805f is in, it's easy to guarantee that we never access a driver.Conn concurrently, per the database/sql/driver contract, so we can remove this overlarge mutex. Fixes #3857 R=golang-dev, adg CC=golang-dev https://golang.org/cl/7707047
2013-03-14database/sql: associate a mutex with each driver interfaceBrad Fitzpatrick
The database/sql/driver docs make this promise: "Conn is a connection to a database. It is not used concurrently by multiple goroutines." That promises exists as part of database/sql's overall goal of making drivers relatively easy to write. So far this promise has been kept without the use of locks by being careful in the database/sql package, but sometimes too careful. (cf. golang.org/issue/3857) The CL associates a Mutex with each driver.Conn, and with the interface value progeny thereof. (e.g. each driver.Tx, driver.Stmt, driver.Rows, driver.Result, etc) Then whenever those interface values are used, the Locker is locked. This CL should be a no-op (aside from some new Lock/Unlock pairs) and doesn't attempt to fix Issue 3857 or Issue 4459, but should make it much easier in a subsequent CL. Update #3857 R=golang-dev, adg CC=golang-dev https://golang.org/cl/7803043
2013-03-14database/sql: document non-open of Open; add PingBrad Fitzpatrick
Fixes #4804 R=golang-dev, r CC=golang-dev https://golang.org/cl/7819043
2013-03-08database/sql: fix Conn leakBrad Fitzpatrick
Fixes #4902 R=golang-dev, alex.brainman, r, google CC=golang-dev https://golang.org/cl/7579045
2013-02-20database/sql: clarify that DB.Prepare's stmt is safe for concurrent useBrad Fitzpatrick
And add a test too, for Alex. :) Fixes #3734 R=golang-dev, adg CC=golang-dev https://golang.org/cl/7399046
2013-02-20database/sql: refcounting and lifetime fixesBrad Fitzpatrick
Simplifies the contract for Driver.Stmt.Close in the process of fixing issue 3865. Fixes #3865 Update #4459 (maybe fixes it; uninvestigated) R=golang-dev, rsc CC=golang-dev https://golang.org/cl/7363043
2013-02-13database/sql: Add an optional Queryer-Interface (like Execer)Julien Schmidt
Completly the same like the Execer-Interface, just for Queries. This allows Drivers to execute Queries without preparing them first R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/7085056
2013-01-11database/sql: document args, add a couple examplesBrad Fitzpatrick
Fixes #3460 R=golang-dev, alex.brainman CC=golang-dev https://golang.org/cl/7096046
2013-01-11database/sql: check NumInput on Stmt.ExecGwenael Treguier
Fixes #3678. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/6460087
2012-12-19all: fix typosShenghou Ma
caught by https://github.com/lyda/misspell-check. R=golang-dev, gri CC=golang-dev https://golang.org/cl/6949072
2012-12-12 database/sql: Alter *DB.begin to return driver.ErrBadConn when ↵James David Chalfant
driver.Conn.Begin returns driver.ErrBadConn Fixes #4433 R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/6845094
2012-11-01all: clear execute bitMikio Hara
R=golang-dev, r CC=golang-dev https://golang.org/cl/6826044
2012-08-23database/sql: stop reuse of bad connectionsJulien Schmidt
The second parameter for sql.putConn() (err) is always nil. As a result bad connections are reused, even if the driver returns an driver.ErrBadConn. Unsing a pointer to err instead achievs the desired behavior. See http://code.google.com/p/go/issues/detail?id=3777 for more details. Fixes #3777. R=golang-dev, dave, bradfitz, jameshuachow, BlakeSGentry CC=golang-dev https://golang.org/cl/6348069
2012-05-29database/sql: use driver.ColumnConverter everywhere consistentlyBrad Fitzpatrick
It was only being used for (*Stmt).Exec, not Query, and not for the same two methods on *DB. This unifies (*Stmt).Exec's old inline code into the old subsetArgs function, renaming it in the process (changing the old word "subset" to "driver", mostly converted earlier) Fixes #3640 R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6258045
2012-04-03sql: Propagate error from subsetTypeArgs in ExecMichael Lewis
Fixes #3449 R=golang-dev CC=bradfitz, golang-dev https://golang.org/cl/5970076
2012-03-10database/sql: ensure Stmts are correctly closed.Gwenael Treguier
To make sure that there is no resource leak, I suggest to fix the 'fakedb' driver such as it fails when any Stmt is not closed. First, add a check in fakeConn.Close(). Then, fix all missing Stmt.Close()/Rows.Close(). I am not sure that the strategy choose in fakeConn.Prepare/prepare* is ok. The weak point in this patch is the change in Tx.Query: - Tests pass without this change, - I found it by manually analyzing the code, - I just try to make Tx.Query look like DB.Query. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5759050
2012-03-10database/sql: fix double connection free on Stmt.Query errorBrad Fitzpatrick
In a transaction, on a Stmt.Query error, it was possible for a connection to be added to a db's freelist twice. Should use the local releaseConn function instead. Thanks to Gwenael Treguier for the failing test. Also in this CL: propagate driver errors through releaseConn into *DB.putConn, which conditionally ignores the freelist addition if the driver signaled ErrBadConn, introduced in a previous CL. R=golang-dev, gary.burd CC=golang-dev https://golang.org/cl/5798049
2012-03-08database/sql{,driver}: add ErrBadConnBrad Fitzpatrick
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5785043
2012-03-06database/sql: add docs about connection state, poolingBrad Fitzpatrick
Fixes #3223 R=golang-dev, r CC=golang-dev https://golang.org/cl/5755063
2012-03-06database/sql: fix typo bug resulting in double-PrepareBrad Fitzpatrick
Bug reported by Blake Mizerany found while writing his new Postgres driver. R=golang-dev, blake.mizerany CC=golang-dev https://golang.org/cl/5754057
2012-02-20database/sql/driver: API cleanupsBrad Fitzpatrick
-- add driver.Value type and documentation, convert from interface{} to Value where appropriate. -- don't say "subset" anywhere, -- SubsetValuer -> Valuer -- SubsetValue -> Value -- IsParameterSubsetType -> IsValue -- IsScanSubsetType -> IsScanValue Fixes #2842 R=golang-dev, r, rsc CC=golang-dev https://golang.org/cl/5674084
2012-02-10database/sql: remove Into from ScannerInto/ScanIntoBrad Fitzpatrick
Also fix a doc error. Fixes #2843 R=golang-dev, r, rsc CC=golang-dev https://golang.org/cl/5653050
2012-02-10database/sql: support ErrSkip in Tx.ExecAndrew Balholm
If the database driver supports the Execer interface but returns ErrSkip, calling Exec on a transaction was returning the error instead of using the slow path. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5654044
2012-02-10database/sql: rename ErrTransactionFinished to ErrTxDoneBrad Fitzpatrick
Part of issue 2843 R=golang-dev, gri CC=golang-dev https://golang.org/cl/5646063
2012-02-06database/sql: permit scanning into interface{}Brad Fitzpatrick
See thread http://goo.gl/7zzzU for background. R=rsc CC=golang-dev https://golang.org/cl/5624051
2012-01-26 database/sql: convert SQL null values to []byte as nil.James P. Cooper
Also allow string values to scan into []byte. Fixes #2788. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5577054
2012-01-25database/sql: fix Tx.QueryBlake Mizerany
Fixes #2784 R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5574073