From 2806884f34be85e0e839a483c1097245be790124 Mon Sep 17 00:00:00 2001 From: Ilja Heitlager Date: Wed, 3 Aug 2016 09:04:56 +0200 Subject: [PATCH 01/14] Update references.md --- references.md | 1 + 1 file changed, 1 insertion(+) diff --git a/references.md b/references.md index ae4de6e..b61fcf6 100644 --- a/references.md +++ b/references.md @@ -9,6 +9,7 @@ Here are some external sources of information we've found to be helpful. * [http://jmoiron.net/blog/gos-database-sql/](http://jmoiron.net/blog/gos-database-sql/) * [http://jmoiron.net/blog/built-in-interfaces/](http://jmoiron.net/blog/built-in-interfaces/) * The VividCortex blog, e.g. [transparent encryption](https://vividcortex.com/blog/2014/11/11/encrypting-data-in-mysql-with-go/) +* Overview of SQL Drivers from [golang github](https://github.com/golang/go/wiki/SQLDrivers) We hope you've found this website to be helpful. If you have any suggestions for improvements, please send pull requests or open an issue report at From c90d644aa2268e5a94136111c0e78e627c50fe56 Mon Sep 17 00:00:00 2001 From: Sartaj Singh Date: Mon, 22 May 2017 20:24:44 +0530 Subject: [PATCH 02/14] Add SetConnMaxLifetime details to connection pool --- connection-pool.md | 1 + 1 file changed, 1 insertion(+) diff --git a/connection-pool.md b/connection-pool.md index ae1dc6f..097945f 100644 --- a/connection-pool.md +++ b/connection-pool.md @@ -14,6 +14,7 @@ useful to know: * In Go 1.2.1 or newer, you can use `db.SetMaxOpenConns(N)` to limit the number of *total* open connections to the database. Unfortunately, a [deadlock bug](https://groups.google.com/d/msg/golang-dev/jOTqHxI09ns/x79ajll-ab4J) ([fix](https://code.google.com/p/go/source/detail?r=8a7ac002f840)) prevents `db.SetMaxOpenConns(N)` from safely being used in 1.2. * Connections are recycled rather fast. Setting a high number of idle connections with `db.SetMaxIdleConns(N)` can reduce this churn, and help keep connections around for reuse. * Keeping a connection idle for a long time can cause problems (like in [this issue](https://github.com/go-sql-driver/mysql/issues/257) with MySQL on Microsoft Azure). Try `db.SetMaxIdleConns(0)` if you get connection timeouts because a connection is idle for too long. +* You can also specify the maximum amount of time a connection may be reused by setting `db.SetConnMaxLifetime(duration)` since reusing long lived connections may cause network issues. This closes the unused connections lazily i.e. closing expired connection may be deferred. **Previous: [Working with Unknown Columns](varcols.html)** **Next: [Surprises, Antipatterns and Limitations](surprises.html)** From ceadad3644eb23bb437029f8873027f0d084a3d6 Mon Sep 17 00:00:00 2001 From: kenny Date: Thu, 15 Feb 2018 13:20:58 -0600 Subject: [PATCH 03/14] Update nulls.md Rename value used for selecting column to `otherField` to reflect comment below --- nulls.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nulls.md b/nulls.md index 274b450..389315c 100644 --- a/nulls.md +++ b/nulls.md @@ -42,7 +42,7 @@ If you can't avoid having NULL values in your database, there is another work ar rows, err := db.Query(` SELECT name, - COALESCE(other_field, '') as other_field + COALESCE(other_field, '') as otherField WHERE id = ? `, 42) From 6b46e2e38dcdf47b7f1cb61ed3625e84ab2c5577 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 8 May 2018 15:04:43 +0800 Subject: [PATCH 04/14] Possible missing stmt.Close Are you missing `derfer stmt.Close` on here or you just did it on purpose? Please explain to us why you don't need to stmt.Close() in this scenario --- retrieving.md | 1 + 1 file changed, 1 insertion(+) diff --git a/retrieving.md b/retrieving.md index 85e14c2..33cee55 100644 --- a/retrieving.md +++ b/retrieving.md @@ -167,6 +167,7 @@ stmt, err := db.Prepare("select name from users where id = ?") if err != nil { log.Fatal(err) } +defer stmt.Close() var name string err = stmt.QueryRow(1).Scan(&name) if err != nil { From 167139ec1528e5c86956329ab427cc015f693963 Mon Sep 17 00:00:00 2001 From: Dimitri Balios Date: Sat, 6 Oct 2018 15:28:10 +0200 Subject: [PATCH 05/14] Update importing.md --- importing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/importing.md b/importing.md index 9b6608a..ef1ab3a 100644 --- a/importing.md +++ b/importing.md @@ -30,7 +30,7 @@ import ( Notice that we're loading the driver anonymously, aliasing its package qualifier to `_` so none of its exported names are visible to our code. Under the hood, the driver registers itself as being available to the `database/sql` package, -but in general nothing else happens. +but in general nothing else happens with the exception that the init function is run. Now you're ready to access a database. From d36f9a6ce2d9c498f5c972f23b0a711f54668a60 Mon Sep 17 00:00:00 2001 From: Baron Schwartz Date: Mon, 29 Oct 2018 15:33:53 -0400 Subject: [PATCH 06/14] fix deprecated pygments --- _config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 953722e..9e1bfd3 100644 --- a/_config.yml +++ b/_config.yml @@ -2,6 +2,6 @@ title: Go database/sql tutorial description: Use database/sql effectively! safe: true lsi: false -pygments: true +highlighter: rouge timezone: UTC markdown: kramdown From cb7dc9b43218891d5f7b9ee0edd02edece71cb40 Mon Sep 17 00:00:00 2001 From: "Afriza N. Arief" <68133+afriza@users.noreply.github.com> Date: Fri, 18 Jan 2019 15:46:39 +0700 Subject: [PATCH 07/14] fix typo in overview.md change `db.SQL` to `sql.DB` --- overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overview.md b/overview.md index 92d344a..1a3287a 100644 --- a/overview.md +++ b/overview.md @@ -21,7 +21,7 @@ The `sql.DB` abstraction is designed to keep you from worrying about how to manage concurrent access to the underlying datastore. A connection is marked in-use when you use it to perform a task, and then returned to the available pool when it's not in use anymore. One consequence of this is that **if you fail -to release connections back to the pool, you can cause `db.SQL` to open a lot of +to release connections back to the pool, you can cause `sql.DB` to open a lot of connections**, potentially running out of resources (too many connections, too many open file handles, lack of available network ports, etc). We'll discuss more about this later. From 8d17aaeb98d9a466f19b649de8ff2d1b277e5cb5 Mon Sep 17 00:00:00 2001 From: cglotr Date: Tue, 29 Jan 2019 14:40:03 +0800 Subject: [PATCH 08/14] fix navigation not showing --- _data/nav.yml | 37 +++++++++++++++++++++++++++++++++++++ _includes/leftnav.html | 24 ++++++------------------ 2 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 _data/nav.yml diff --git a/_data/nav.yml b/_data/nav.yml new file mode 100644 index 0000000..1d2d2a1 --- /dev/null +++ b/_data/nav.yml @@ -0,0 +1,37 @@ +docs: + + - title: Go database/sql tutorial + url: index.html + + - title: Overview + url: overview.html + + - title: Accessing the Database + url: accessing.html + + - title: Retrieving Result Sets + url: retrieving.html + + - title: Modifying Data and Using Transactions + url: modifying.html + + - title: Using Prepared Statements + url: prepared.html + + - title: Handling Errors + url: errors.html + + - title: Working with NULLs + url: nulls.html + + - title: Working with Unknown Columns + url: varcols.html + + - title: The Connection Pool + url: connection-pool.html + + - title: Surprises, Antipatterns and Limitations + url: surprises.html + + - title: Related Reading and Resources + url: references.html diff --git a/_includes/leftnav.html b/_includes/leftnav.html index df91360..832c653 100644 --- a/_includes/leftnav.html +++ b/_includes/leftnav.html @@ -1,23 +1,11 @@

From 910626ff2bcd0b772f03948a243b0c812daf35ba Mon Sep 17 00:00:00 2001 From: cglotr Date: Thu, 31 Jan 2019 12:36:11 +0800 Subject: [PATCH 09/14] add missing importing nav --- _data/nav.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/_data/nav.yml b/_data/nav.yml index 1d2d2a1..dfab5a9 100644 --- a/_data/nav.yml +++ b/_data/nav.yml @@ -6,6 +6,9 @@ docs: - title: Overview url: overview.html + - title: Importing a Database Driver + url: importing.html + - title: Accessing the Database url: accessing.html From 86f6735f4f287c776e12b8ba1eb2bb1596587ad0 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 6 Mar 2019 06:26:05 -0800 Subject: [PATCH 10/14] Fix grammar typo --- overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overview.md b/overview.md index 1a3287a..337973b 100644 --- a/overview.md +++ b/overview.md @@ -12,7 +12,7 @@ of a "database" or "schema." It's an abstraction of the interface and existence of a database, which might be as varied as a local file, accessed through a network connection, or in-memory and in-process. -The `sql.DB` performs some important tasks for you behind the scenes: +`sql.DB` performs some important tasks for you behind the scenes: * It opens and closes connections to the actual underlying database, via the driver. * It manages a pool of connections as needed, which may be a variety of things as mentioned. From 9d2e80505f0f4ef12e7c35fab637f9aecd87bf2f Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 6 Mar 2019 06:39:53 -0800 Subject: [PATCH 11/14] Grammar fix --- modifying.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modifying.md b/modifying.md index 074188a..f649022 100644 --- a/modifying.md +++ b/modifying.md @@ -12,7 +12,7 @@ Statements that Modify Data =========================== Use `Exec()`, preferably with a prepared statement, to accomplish an `INSERT`, -`UPDATE`, `DELETE`, or other statement that doesn't return rows. The following +`UPDATE`, `DELETE`, or another statement that doesn't return rows. The following example shows how to insert a row and inspect metadata about the operation:

From 07f6fad65812bc6db25e748c834da8d634b052e8 Mon Sep 17 00:00:00 2001
From: Eli Bendersky 
Date: Thu, 7 Mar 2019 07:03:00 -0800
Subject: [PATCH 12/14] Fix reference to 'db' var

In the rest of the example `db` is used, not `Db`. Moreover, I think that a simple example here could help clarify the terminology, because it gets a bit murky between `db` (object of type `DB`) and `tx` (object of type `Tx`). Something like:

```
// Create an object of type Tx
tx, err := db.Begin()
...
```
---
 modifying.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/modifying.md b/modifying.md
index f649022..487aac3 100644
--- a/modifying.md
+++ b/modifying.md
@@ -84,8 +84,8 @@ code. Bad things might result:
 * You could believe you're executing queries on a single connection, inside of a transaction, when in reality Go has created several connections for you invisibly and some statements aren't part of the transaction.
 
 While you are working inside a transaction you should be careful not to make
-calls to the `Db` variable. Make all of your calls to the `Tx` variable that you
-created with `db.Begin()`. The `Db` is not in a transaction, only the `Tx` is.
+calls to the `db` variable. Make all of your calls to the `Tx` variable that you
+created with `db.Begin()`. `db` is not in a transaction, only the `Tx` object is.
 If you make further calls to `db.Exec()` or similar, those will happen outside
 the scope of your transaction, on other connections.
 

From 75b25123d375bc1a86a6b83f4070f0e28c215c38 Mon Sep 17 00:00:00 2001
From: "whitesource-for-github.amrom.workers.dev[bot]"
 <50673670+whitesource-for-github.amrom.workers.dev[bot]@users.noreply.github.com>
Date: Wed, 24 Jun 2020 14:11:58 +0000
Subject: [PATCH 13/14] Add .whitesource configuration file

---
 .whitesource | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 .whitesource

diff --git a/.whitesource b/.whitesource
new file mode 100644
index 0000000..60fc783
--- /dev/null
+++ b/.whitesource
@@ -0,0 +1,13 @@
+{
+  "scanSettings": {
+    "configMode": "AUTO",
+    "configExternalURL": "",
+    "projectToken" : ""
+  },
+  "checkRunSettings": {
+    "vulnerableCheckRunConclusionLevel": "failure"
+  },
+  "issueSettings": {
+    "minSeverityLevel": "LOW"
+  }
+}
\ No newline at end of file

From ae7ad3a8886f5ff92f269fe35debe3021005d336 Mon Sep 17 00:00:00 2001
From: "whitesource-for-github.amrom.workers.dev[bot]"
 <50673670+whitesource-for-github.amrom.workers.dev[bot]@users.noreply.github.com>
Date: Tue, 15 Dec 2020 15:54:46 +0000
Subject: [PATCH 14/14] Migrate .whitesource configuration file to inheritance
 mode

---
 .whitesource | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/.whitesource b/.whitesource
index 60fc783..d7eebc0 100644
--- a/.whitesource
+++ b/.whitesource
@@ -1,13 +1,3 @@
 {
-  "scanSettings": {
-    "configMode": "AUTO",
-    "configExternalURL": "",
-    "projectToken" : ""
-  },
-  "checkRunSettings": {
-    "vulnerableCheckRunConclusionLevel": "failure"
-  },
-  "issueSettings": {
-    "minSeverityLevel": "LOW"
-  }
+  "settingsInheritedFrom": "VividCortex/whitesource-config@master"
 }
\ No newline at end of file