aboutsummaryrefslogtreecommitdiff
path: root/src/database
AgeCommit message (Collapse)Author
2025-12-11Revert "database/sql: allow drivers to override Scan behavior"Austin Clements
This reverts CL 588435. This new API is difficult to use correctly, and in many cases cannot be used efficiently. We're going to work on this problem a bit more. The release notes are removed by CL 729340, since they were moved to the x/website repository since the original CL was made. Reopens #67546. Change-Id: I2a2bd25f2fce5f02e4d28cd33a9cc651bf35ab50 Reviewed-on: https://go-review.googlesource.com/c/go/+/729360 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Sean Liao <sean@liao.dev>
2025-11-21database/sql: don't ignore ColumnConverter for unknown input countJonathan Hall
In the case a sql driver implements the ColumnConverter interface and also returns -1 for NumInputs, indicating an unknown number of input arguments to a query, the previous implementation would ignore the column converter would not be called, leading to unexpected or invalid arguments passed to the driver. Fixes #68342 Change-Id: Ib2ddaf040fa9be669d593eacdaa1e88ba66d7bc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/597115 Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-14std: fix printf("%q", int) mistakesAlan Donovan
For #72850 Change-Id: I07e64f05c82a34b1dadb9a72e16f5045e68cbd24 Reviewed-on: https://go-review.googlesource.com/c/go/+/720642 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-17all: remove unnecessary loop variable copies in testsTobias Klauser
Copying the loop variable is no longer necessary since Go 1.22. Change-Id: Iebb21dac44a20ec200567f1d786f105a4ee4999d Reviewed-on: https://go-review.googlesource.com/c/go/+/711640 Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-11database/sql: allow drivers to override Scan behaviorJack Christensen
Implementing RowsColumnScanner allows the driver to completely control how values are scanned. Fixes #67546 Change-Id: Id8e7c3a973479c9665e4476fe2d29e1255aee687 GitHub-Last-Rev: ed0cacaec4a4feead56b09c0d6eee86ed58fe1ee GitHub-Pull-Request: golang/go#67648 Reviewed-on: https://go-review.googlesource.com/c/go/+/588435 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-06database/sql: avoid closing Rows while scan is in progressDamien Neil
A database/sql/driver.Rows can return database-owned data from Rows.Next. The driver.Rows documentation doesn't explicitly document the lifetime guarantees for this data, but a reasonable expectation is that the caller of Next should only access it until the next call to Rows.Close or Rows.Next. Avoid violating that constraint when a query is cancelled while a call to database/sql.Rows.Scan (note the difference between the two different Rows types!) is in progress. We previously took care to avoid closing a driver.Rows while the user has access to driver-owned memory via a RawData, but we could still close a driver.Rows while a Scan call was in the process of reading previously-returned driver-owned data. Update the fake DB used in database/sql tests to invalidate returned data to help catch other places we might be incorrectly retaining it. Fixes #74831. Change-Id: Ice45b5fad51b679c38e3e1d21ef39156b56d6037 Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/2540 Reviewed-by: Roland Shoemaker <bracewell@google.com> Reviewed-by: Neal Patel <nealpatel@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/693735 Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-04-16database/sql: wake cleaner if maxIdleTime set to less than maxLifetimePhilip Roberts
The existing implementation wouldn't wake the connection cleaner if maxIdleTime was set to a value less than maxLifetime while an existing connection was open - resulting in idle connections not being discarded until after the first maxLifetime had passed. Fixes #45993 Change-Id: I074ed7ba9803354c8b3a41f2625ae0d8a7d5059b GitHub-Last-Rev: 0d149d8d38bc9c2ad42a2a20dcfc73994d54fe23 GitHub-Pull-Request: golang/go#58490 Reviewed-on: https://go-review.googlesource.com/c/go/+/467655 Auto-Submit: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-02-10database/sql: use t.Context in testsapocelipes
Replace "context.WithCancel(context.Background())" with "t.Context()". Updates #36532 Change-Id: I78a8ba422f076f4c697910922cf6dc35c628b1a7 GitHub-Last-Rev: 2eacdbe9ea97ac8d928704c2b605b276626d95dd GitHub-Pull-Request: golang/go#71599 Reviewed-on: https://go-review.googlesource.com/c/go/+/647555 Reviewed-by: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-10-29database/sql: allocate once when assigning a time.Time to a byte sliceCharlie Vieth
Change convertAssignRows to use time.AppendFormat and a pre-allocated buffer when assigning a time.Time to a byte slice. Previously, the result of time.Format was converted to a byte slice which required two allocations. Change-Id: I19db5e4d295e882070f947eca318a4e33520cda1 Reviewed-on: https://go-review.googlesource.com/c/go/+/622597 Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-10-28all: skip and fix various tests with -asan and -msanMichael Anthony Knyszek
First, skip all the allocation count tests. In some cases this aligns with existing skips for -race, but in others we've got new issues. These are debug modes, so some performance loss is expected, and this is clearly no worse than today where the tests fail. Next, skip internal linking and static linking tests for msan and asan. With asan we get an explicit failure that neither are supported by the C and/or Go compilers. With msan, we only get the Go compiler telling us internal linking is unavailable. With static linking, we segfault instead. Filed #70080 to track that. Next, skip some malloc tests with asan that don't quite work because of the redzone. This is because of some sizeclass assumptions that get broken with the redzone and the fact that the tiny allocator is effectively disabled (again, due to the redzone). Next, skip some runtime/pprof tests with asan, because of extra allocations. Next, skip some malloc tests with asan that also fail because of extra allocations. Next, fix up memstats accounting for arenas when asan is enabled. There is a bug where more is added to the stats than subtracted. This also simplifies the accounting a little. Next, skip race tests with msan or asan enabled; they're mutually incompatible. Fixes #70054. Fixes #64256. Fixes #64257. For #70079. For #70080. Change-Id: I99c02a0b9d621e44f1f918b307aa4a4944c3ec60 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-asan-clang15,gotip-linux-amd64-msan-clang15 Reviewed-on: https://go-review.googlesource.com/c/go/+/622855 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
2024-10-21database/sql: rewrite Null[T].Value method, update doc for Null[T]Jes Cok
Update doc for Null[T] to clarify that T should be one of the types accepted by driver.Value. Modify the Value() method of Null[T]: 1) recognize T implementing driver.Valuer interface and invoke it. 2) use the DefaultParameterConverter to convert native types that are not directly supported as driver.Value types. Fixes #69728 Fixes #69837 Change-Id: Iba782c878b2bde168125f5390abf319b88424149 GitHub-Last-Rev: 3df182d23dd57bd04828c3e9bd0c5222d8bef152 GitHub-Pull-Request: golang/go#69938 Reviewed-on: https://go-review.googlesource.com/c/go/+/620858 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-10-02all: use slices.Sorted(maps.Keys(m))Tobias Klauser
Use slices.Sorted(maps.Keys(m)) to get a sorted slices of the keys in a map. Do not change packages built during bootstrap, as the bootstrap compiler (currently 1.22.6) does not have the required maps and slices functions. Change-Id: Ie35565d241fa14aca56b730a69af010127b659ab Reviewed-on: https://go-review.googlesource.com/c/go/+/617356 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2024-08-24database/sql: fix panic with concurrent Conn and CloseNic Klaassen
The current implementation has a panic when the database is closed concurrently with a new connection attempt. connRequestSet.CloseAndRemoveAll sets connRequestSet.s to a nil slice. If this happens between calls to connRequestSet.Add and connRequestSet.Delete, there is a panic when trying to write to the nil slice. This is sequence is likely to occur in DB.conn, where the mutex is released between calls to db.connRequests.Add and db.connRequests.Delete This change updates connRequestSet.CloseAndRemoveAll to set the curIdx to -1 for all pending requests before setting its internal slice to nil. CloseAndRemoveAll already iterates the full slice to close all the request channels. It seems appropriate to set curIdx to -1 before deleting the slice for 3 reasons: 1. connRequestSet.deleteIndex also sets curIdx to -1 2. curIdx will not be relevant to anything after the slice is set to nil 3. connRequestSet.Delete already checks for negative indices Fixes #68949 Change-Id: I6b7ebc5a71b67322908271d13865fa12f2469b87 GitHub-Last-Rev: 7d2669155b24043dd9d276f915689511572f2e49 GitHub-Pull-Request: golang/go#68953 Reviewed-on: https://go-review.googlesource.com/c/go/+/607238 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Commit-Queue: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-07-11database/sql/driver: fix name in commentJonathan Hall
DefaultValueConverter => DefaultParameterConverter Change-Id: I0e726cfdbf21a5e00928899d1fd9144f89dcb805 Reviewed-on: https://go-review.googlesource.com/c/go/+/555235 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Shay Nehmad <dude500@gmail.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-05-29all: document legacy //go:linkname for final round of modulesRuss Cox
Add linknames for most modules with ≥50 dependents. Add linknames for a few other modules that we know are important but are below 50. Remove linknames from badlinkname.go that do not merit inclusion (very small number of dependents). We can add them back later if the need arises. Fixes #67401. (For now.) Change-Id: I1e49fec0292265256044d64b1841d366c4106002 Reviewed-on: https://go-review.googlesource.com/c/go/+/587756 Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Bypass: Russ Cox <rsc@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-05-23std: fix calls to Printf(s) with non-constant sAlan Donovan
In all cases the intent was not to interpret s as a format string. In one case (go/types), this was a latent bug in production. (These were uncovered by a new check in vet's printf analyzer.) Updates #60529 Change-Id: I3e17af7e589be9aec1580783a1b1011c52ec494b Reviewed-on: https://go-review.googlesource.com/c/go/+/587855 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Russ Cox <rsc@golang.org>
2024-05-23all: document legacy //go:linkname for modules with ≥500 dependentsRuss Cox
For #67401. Change-Id: I7dd28c3b01a1a647f84929d15412aa43ab0089ee Reviewed-on: https://go-review.googlesource.com/c/go/+/587575 Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-17all: add push linknames to allow legacy pull linknamesCherry Mui
CL 585358 adds restrictions to disallow pull-only linknames (currently off by default). Currently, there are quite some pull- only linknames in user code in the wild. In order not to break those, we add push linknames to allow them to be pulled. This CL includes linknames found in a large code corpus (thanks Matthew Dempsky and Michael Pratt for the analysis!), that are not currently linknamed. Updates #67401. Change-Id: I32f5fc0c7a6abbd7a11359a025cfa2bf458fe767 Reviewed-on: https://go-review.googlesource.com/c/go/+/586137 Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-14database/sql: reordering fields to reduce struct sizesapocelipes
There are 16 bytes reduced. Change-Id: I33ca96fd22002b3111f0462c3029d70df48adb6e GitHub-Last-Rev: 8df56a9655ef261be3ff9403491cbbe1ebda1ec0 GitHub-Pull-Request: golang/go#67055 Reviewed-on: https://go-review.googlesource.com/c/go/+/581935 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-04-10database/sql: avoid clobbering driver-owned memory in RawBytesDamien Neil
Depending on the query, a RawBytes can contain memory owned by the driver or by database/sql: If the driver provides the column as a []byte, RawBytes aliases that []byte. If the driver provides the column as any other type, RawBytes contains memory allocated by database/sql. Prior to this CL, Rows.Scan will reuse existing capacity in a RawBytes to permit a single allocation to be reused across rows. When a RawBytes is reused across queries, this can result in database/sql writing to driver-owned memory. Add a buffer to Rows to store RawBytes data, and reuse this buffer across calls to Rows.Scan. Fixes #65201 Change-Id: Iac640174c7afa97eeb39496f47dec202501b2483 Reviewed-on: https://go-review.googlesource.com/c/go/+/557917 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-02database/sql: refactor unused variables to use blank identifiersMohammad Abbasi
Hi I've replaced unused variables in database/sql with blank identifiers to improve code readability. This change has no impact on the functionality of the code, but makes it easier to read and understand. Change-Id: I701e93fd9bf86725f411085bf2e8f8e6b235af14 GitHub-Last-Rev: eb40bd5e2ef9e28871fae2e97b4433e8d6e2c652 GitHub-Pull-Request: golang/go#58986 Reviewed-on: https://go-review.googlesource.com/c/go/+/475675 Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-04-01database/sql: use slices to simplify the codeapocelipes
Change-Id: Ia198272330626271ee7d4e1ae46afca819ab2933 GitHub-Last-Rev: e713ac31638671f60cc3cf62fa514f784e834e66 GitHub-Pull-Request: golang/go#66572 Reviewed-on: https://go-review.googlesource.com/c/go/+/574995 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com>
2024-03-22database/sql: fix typo in commentguoguangwu
Change-Id: Ie8ac82b6a1685299a92ec59acbd80b6de38e377c GitHub-Last-Rev: 325df8d1488b02bfa239d66cdf870e3d37169d76 GitHub-Pull-Request: golang/go#66457 Reviewed-on: https://go-review.googlesource.com/c/go/+/573615 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com>
2024-03-20database/sql: fix memory leaks in Stmt.removeClosedStmtLockedapocelipes
Zero out elements before shrinking the slice to avoid memory leaks. Fixes #66410 Change-Id: I8f64c21455761f7f7c8b6fee0b6450b98f691d91 GitHub-Last-Rev: b15586e801199b9674f5bfcb12a848a55f15a80b GitHub-Pull-Request: golang/go#66419 Reviewed-on: https://go-review.googlesource.com/c/go/+/572956 TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
2024-03-19database/sql: close rows in testguoguangwu
This change invokes defer rows.Close() in TestQuery to properly close the rows. Change-Id: I1ab0d172ad2130e9caab7dbda93d671550c33c6b GitHub-Last-Rev: 76883a3bceefb80873e57150356a4acc001ee1a3 GitHub-Pull-Request: golang/go#66371 Reviewed-on: https://go-review.googlesource.com/c/go/+/572197 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-03-18database/sql: optimize connection request poolBrad Fitzpatrick
This replaces a map used as a set with a slice. We were using a surprising amount of CPU in this code, making mapiters to pull out a random element of the map. Instead, just rand.IntN to pick a random element of the slice. It also adds a benchmark: │ before │ after │ │ sec/op │ sec/op vs base │ ConnRequestSet-8 1818.0n ± 0% 452.4n ± 0% -75.12% (p=0.000 n=10) (whether random is a good policy is a bigger question, but this optimizes the current policy without changing behavior) Updates #66361 Change-Id: I3d456a819cc720c2d18e1befffd2657e5f50f1e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/572119 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>
2024-03-06database/sql: remove useless error checkguoguangwu
Change-Id: Id2d45a4b43b05deba4e2c31f7c03008c2f2c18a2 GitHub-Last-Rev: 587bed9a64da08d5b476d87333aed72649dad470 GitHub-Pull-Request: golang/go#66110 Reviewed-on: https://go-review.googlesource.com/c/go/+/569075 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-02-28database/sql: add error checkguoguangwu
Change-Id: Ib9f7a1a4bf23f76457dabf85610f4799502631dc GitHub-Last-Rev: afbb86fde12d2eeaa8121c25787b0e9c290edbc7 GitHub-Pull-Request: golang/go#65947 Reviewed-on: https://go-review.googlesource.com/c/go/+/566857 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2024-02-27database/sql: wrap errors with %w in driverArgsConnLockedaimuz
Use fmt.Errorf %w verb to wrap errors in driverArgsConnLocked, which allows for easier unwrapping and checking of error types. Add tests in sql_test.go to ensure that Stmt.Exec and Stmt.Query correctly wrap underlying Valuer errors, adhering to the new change. Fixes #64707. Change-Id: Id9f80e265735d0849ee7abba63e58e4c26e658ad GitHub-Last-Rev: 0df367e0fb5b213513d4e0ab7f5a87984798f96d GitHub-Pull-Request: golang/go#64728 Reviewed-on: https://go-review.googlesource.com/c/go/+/550116 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-16database/sql/driver: add a new test case for type tsivchari
Change-Id: I38bb68570f7f097a6dfeef1c75896396992d81f7 GitHub-Last-Rev: 10ba48a546956fa2a5b602680fb312638aade92d GitHub-Pull-Request: golang/go#53706 Reviewed-on: https://go-review.googlesource.com/c/go/+/416234 Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-12-14all: remove newline characters after return statementsDanil Timerbulatov
This commit is aimed at improving the readability and consistency of the code base. Extraneous newline characters were present after some return statements, creating unnecessary separation in the code. Fixes #64610 Change-Id: Ic1b05bf11761c4dff22691c2f1c3755f66d341f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/548316 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-11-27all: fix field namescui fliter
Change-Id: I3ad7a50707486ebdbbd676b3581df6e3ed0fd3a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/543476 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: shuang cui <imcusg@gmail.com>
2023-10-23database/sql: add godoc linksOlivier Mengué
Add godoc links in database/sql and database/sql/driver. Change-Id: I96ed79645a7cc656f5d23450ba3cfe005b04b31a Reviewed-on: https://go-review.googlesource.com/c/go/+/486815 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2023-10-18database: add available godoc linkcui fliter
Change-Id: I6150858f1186edc6cebd38ff166d57287fa430f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/535078 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-10-03database/sql: use the built-in min functionmstmdev
Change-Id: Ib6a0e1e1583e45e3d239455e8b131c81602b2d5d GitHub-Last-Rev: dc82635562a7fb4488f374d7a9ed26b29310e918 GitHub-Pull-Request: golang/go#63200 Reviewed-on: https://go-review.googlesource.com/c/go/+/530875 Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-20all: simplify bool conditionsOleksandr Redko
Change-Id: Id2079f7012392dea8dfe2386bb9fb1ea3f487a4a Reviewed-on: https://go-review.googlesource.com/c/go/+/526015 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com>
2023-08-08database/sql: use reflect.TypeFor for known typesIan Lance Taylor
For #60088 Change-Id: Ib05ba3d456b22f7370459037b3d263c4b3ebe3b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/514975 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-08-07database/sql: add Null[T]Inada Naoki
Generic version of NullString, NullInt64, etc. Fixes #60370 Change-Id: I166a05a6126e8b8571db5cbb026303bb6551d56b GitHub-Last-Rev: 3c8d2d5141c36f034d2124e19ee090620363ba24 GitHub-Pull-Request: golang/go#60677 Reviewed-on: https://go-review.googlesource.com/c/go/+/501700 Reviewed-by: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2023-07-07src/database/sql: run gofmtThan McIntosh
Run gofmt on a source file. Change-Id: I180d5cc7425fc5d8e9cf63005ac692f361beb1ed Reviewed-on: https://go-review.googlesource.com/c/go/+/508497 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Eli Bendersky <eliben@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-07-05database/sql: prevent internal context error from being returned from Rows.Err()zikaeroh
CL 497675 modified Rows such that context errors are propagated through Rows.Err(). This caused an issue where calling Close meant that an internal cancellation error would (eventually) be returned from Err: 1. A caller makes a query using a cancellable context. 2. initContextClose sees that either the query context or the transaction context can be canceled, so will need to spawn a goroutine to capture their errors. 3. initContextClose derives a context from the query context via WithCancel and sets rs.cancel. 4. When a user calls Close, rs.cancel is called. awaitDone's ctx is cancelled, which is good, since we don't want it to hang forever. 5. This internal cancellation (after CL 497675) has its error saved on contextDone. 6. Later, calling Err will return the error in contextDone if present. This leads to a race condition depending on how quickly Err is called after Close. The docs for Close and Err state that calling Close should have no affect on the return result for Err. So, a potential fix is to ensure that awaitDone does not save the error when the cancellation comes from a Close via rs.cancel. This CL does that, using a new context not derived from the query context, whose error is ignored as the query context's error used to be before the original bugfix. The included test fails before the CL, and passes afterward. Fixes #60932 Change-Id: I2bf4c549efd83d62b86e298c9c45ebd06a3ad89a Reviewed-on: https://go-review.googlesource.com/c/go/+/505397 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2023-06-13database/sql: fix flake in TestContextCancelDuringRawBytesScanRuss Cox
If the cancellation takes effect between Next and Scan, then Scan returns context.Canceled, but the test wasn't allowing this case. The old flake reproduced easily with: go test -c stress ./sql.test -test.count=100 -test.run=TestContextCancelDuringRawBytesScan The new test modes exercise that path directly instead of needing stress. The new check for context.Canceled fixes the new test mode "top". Fixes #60445. Change-Id: I3870039a0fbe0a43c3e261b43b175ef83f818765 Reviewed-on: https://go-review.googlesource.com/c/go/+/502876 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
2023-05-26database/sql: fix regression from earlier RawBytes fixBrad Fitzpatrick
The earlier CL 497675 for #60304 introduced a behavior change that, while not strictly a bug, caused a bunch of test failures in a large codebase. Rather than add behavior changes in a 10 year old package, revert to the old behavior: a context cancelation between Rows.Next reporting false and a call to Rows.Err should not result in Rows.Err returning the context error. That behavior was accidentally added in CL 497675 as part of changing how contexts and Rows iteration worked. Updates #60304 Updates #53970 Change-Id: I22f8a6a6b0b5a94b430576cf50e015efd01ec652 Reviewed-on: https://go-review.googlesource.com/c/go/+/498398 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-24database/sql: make RawBytes safely usable with contextsBrad Fitzpatrick
sql.RawBytes was added the very first Go release, Go 1. Its docs say: > RawBytes is a byte slice that holds a reference to memory owned by > the database itself. After a Scan into a RawBytes, the slice is only > valid until the next call to Next, Scan, or Close. That "only valid until the next call" bit was true at the time, until contexts were added to database/sql in Go 1.8. In the past ~dozen releases it's been unsafe to use QueryContext with a context that might become Done to get an *sql.Rows that's scanning into a RawBytes. The Scan can succeed, but then while the caller's reading the memory, a database/sql-managed goroutine can see the context becoming done and call Close on the database/sql/driver and make the caller's view of the RawBytes memory no longer valid, introducing races, crashes, or database corruption. See #60304 and #53970 for details. This change does the minimal surgery on database/sql to make it safe again: Rows.Scan was already acquiring a mutex to check whether the rows had been closed, so this change make Rows.Scan notice whether *RawBytes was used and, if so, doesn't release the mutex on exit before returning. That mean it's still locked while the user code operates on the RawBytes memory and the concurrent context-watching goroutine to close the database still runs, but if it fires, it then gets blocked on the mutex until the next call to a Rows method (Next, NextResultSet, Err, Close). Updates #60304 Updates #53970 (earlier one I'd missed) Change-Id: Ie41c0c6f32c24887b2f53ec3686c2aab73a1bfff Reviewed-on: https://go-review.googlesource.com/c/go/+/497675 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2023-04-04database/sql,testing/quick: use reflect.Value.SetZeroDaniel Martí
Change-Id: I2893a6aa8c2715f69745f424262c20c21370b05f Reviewed-on: https://go-review.googlesource.com/c/go/+/481355 Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
2023-03-14database/sql: remove a distracting alloc, use atomic.BoolBrad Fitzpatrick
This removes an allocation in Conn.grabConn that, while not super important, was distracting me when optimizing code elsewhere. While here, convert an atomic that was forgotten when this package was earlier updated to use the new Go 1.19 typed atomics. Change-Id: I4666256b4c0512e2162bd485c389130699f9d5ed Reviewed-on: https://go-review.googlesource.com/c/go/+/475415 Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2022-11-14database/sql: add a missing period to end of sentence in Rows.Scan docsBrad Fitzpatrick
Change-Id: I331d4ff3e0f76a26c1c5ec41297117a5b1f16911 Reviewed-on: https://go-review.googlesource.com/c/go/+/450295 Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joedian Reid <joedian@golang.org>
2022-09-28database: use bytes.Clonecuiweixie
Change-Id: I66aad199884cffd51946f53f01580a3a353f5c97 Reviewed-on: https://go-review.googlesource.com/c/go/+/435280 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Meng Zhuo <mzh@golangcn.org>
2022-09-15database: convert DB.{waitDuration,numClosed} to atomic typecuiweixie
Change-Id: I4a67a5e51a98938c07b3c38442f8d852db97cb2a Reviewed-on: https://go-review.googlesource.com/c/go/+/426085 Run-TryBot: Jenny Rakoczy <jenny@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jenny Rakoczy <jenny@golang.org> Run-TryBot: xie cui <523516579@qq.com> Auto-Submit: Jenny Rakoczy <jenny@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2022-09-08database: convert Tx.done to atomic typecuiweixie
Change-Id: I9ec725009376f5865adedca6c159b14140dde097 Reviewed-on: https://go-review.googlesource.com/c/go/+/426086 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
2022-09-07database/sql: simplify retry logic when the connection is badJinzhu
Simplify retry logic when got bad connection Change-Id: I92494c6c020576ec01bc4868334ee920ded7aa57 GitHub-Last-Rev: 7499b0c9419a31c9adce6d5096a1924aa3612f1d GitHub-Pull-Request: golang/go#54043 Reviewed-on: https://go-review.googlesource.com/c/go/+/419182 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com> Run-TryBot: hopehook <hopehook@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org>