Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(406)

Issue 5630052: code review 5630052: database/sql: treat pointers as nullable types like enc...

Can't Edit
Can't Publish+Mail
Start Review
Created:
9 years, 11 months ago by awpritchard
Modified:
4 days, 2 hours ago
Reviewers:
ikedam, bradfitz
CC:
golang-dev, bradfitz, rsc, rog
Visibility:
Public.

Description

database/sql: treat pointers as nullable types like encoding/json - convert from nil pointers to the nil interface{} - dereference non-nil pointers - convert from nil interface{}s to nil pointers - allocate pointers for non-nil interface{}s - tests for all of the above

Patch Set 1 #

Patch Set 2 : diff -r 9f2be4fbbf69 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r d920eda8b6ac https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 82bac8cdab6b50b9f42f1c203b694c0915be7fa6 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+41 lines, -0 lines) Patch
M src/pkg/database/sql/convert.go View 1 2 3 1 chunk +8 lines, -0 lines 0 comments Download
M src/pkg/database/sql/convert_test.go View 1 2 3 6 chunks +22 lines, -0 lines 0 comments Download
M src/pkg/database/sql/driver/types.go View 1 1 chunk +7 lines, -0 lines 0 comments Download
M src/pkg/database/sql/driver/types_test.go View 1 2 chunks +4 lines, -0 lines 0 comments Download

Messages

Total messages: 10
awpritchard
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
9 years, 11 months ago (2012-02-04 11:42:12 UTC) #1
bradfitz
If we allow this for parameters then I fear people will expect it to work ...
9 years, 11 months ago (2012-02-04 20:21:35 UTC) #2
awpritchard
This patch does add the same behavior for Scan; I've been using it in a ...
9 years, 11 months ago (2012-02-04 20:30:46 UTC) #3
rsc
This only affects places where people want to use NullInt64 and so on, right? What ...
9 years, 11 months ago (2012-02-05 02:56:15 UTC) #4
rog
On 5 February 2012 02:56, Russ Cox <rsc@golang.org> wrote: > This only affects places where ...
9 years, 11 months ago (2012-02-06 11:15:51 UTC) #5
bradfitz
Okay, we've decided to allow this, as well as keeping NullString for people who care ...
9 years, 11 months ago (2012-02-06 19:07:52 UTC) #6
awpritchard
Hello golang-dev@googlegroups.com, bradfitz@golang.org, rsc@golang.org, rogpeppe@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
9 years, 11 months ago (2012-02-06 19:44:15 UTC) #7
bradfitz
LGTM Thanks! On Mon, Feb 6, 2012 at 11:44 AM, <awpritchard@gmail.com> wrote: > Hello golang-dev@googlegroups.com, ...
9 years, 11 months ago (2012-02-08 06:14:02 UTC) #8
bradfitz
*** Submitted as http://code.google.com/p/go/source/detail?r=0eab3b57c894 *** database/sql: treat pointers as nullable types like encoding/json - convert ...
9 years, 11 months ago (2012-02-08 06:14:21 UTC) #9
ikedam
4 days, 2 hours ago (2022-01-15 04:24:18 UTC) #10
Hi,

I believe this feature works perfect (and really useful! Thanks!).
https://go.dev/play/p/oN8MLbd_T_L

But somehow it doesn't look documented anywhere.

I plan to add following descriptions to
https://github.com/golang/go/wiki/SQLInterface ("Dealing with NULL" section):

----
You can also pass pointer types. Be careful for performance issues as it
requires extra memory allocations.

```go
var name *string
err := db.QueryRowContext(ctx, "SELECT name FROM names WHERE id = $1",
id).Scan(&name)
```
----

That's a Wiki and provides no reviewing system, and I want this reviewed before
publish.
Let me know if this feature should not be documented for some reason.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b