[go] database/sql: add NullInt16

129 views
Skip to first unread message

Ariel Mashraki (Gerrit)

unread,
Apr 20, 2021, 9:19:19 AM4/20/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ariel Mashraki has uploaded this change for review.

View Change

database/sql: add NullInt16

Fixes #40082

Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
---
M src/database/sql/fakedb_test.go
M src/database/sql/sql.go
M src/database/sql/sql_test.go
3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/src/database/sql/fakedb_test.go b/src/database/sql/fakedb_test.go
index 72e16e0..836fde4 100644
--- a/src/database/sql/fakedb_test.go
+++ b/src/database/sql/fakedb_test.go
@@ -1186,9 +1186,11 @@
return driver.Bool
case "nullbool":
return driver.Null{Converter: driver.Bool}
+ case "int16":
+ return driver.NotNull{Converter: driver.DefaultParameterConverter}
case "int32":
return driver.Int32
- case "nullint32":
+ case "nullint32", "nullint16":
return driver.Null{Converter: driver.DefaultParameterConverter}
case "string":
return driver.NotNull{Converter: fakeDriverString{}}
@@ -1222,6 +1224,10 @@
return reflect.TypeOf(false)
case "nullbool":
return reflect.TypeOf(NullBool{})
+ case "int16":
+ return reflect.TypeOf(int16(0))
+ case "nullint16":
+ return reflect.TypeOf(NullInt16{})
case "int32":
return reflect.TypeOf(int32(0))
case "nullint32":
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
index 61b5018..157b2df 100644
--- a/src/database/sql/sql.go
+++ b/src/database/sql/sql.go
@@ -260,6 +260,32 @@
return int64(n.Int32), nil
}

+// NullInt16 represents an int16 that may be null.
+// NullInt16 implements the Scanner interface so
+// it can be used as a scan destination, similar to NullString.
+type NullInt16 struct {
+ Int16 int16
+ Valid bool // Valid is true if Int16 is not NULL
+}
+
+// Scan implements the Scanner interface.
+func (n *NullInt16) Scan(value interface{}) error {
+ if value == nil {
+ n.Int16, n.Valid = 0, false
+ return nil
+ }
+ n.Valid = true
+ return convertAssign(&n.Int16, value)
+}
+
+// Value implements the driver Valuer interface.
+func (n NullInt16) Value() (driver.Value, error) {
+ if !n.Valid {
+ return nil, nil
+ }
+ return int64(n.Int16), nil
+}
+
// NullFloat64 represents a float64 that may be null.
// NullFloat64 implements the Scanner interface so
// it can be used as a scan destination, similar to NullString.
diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go
index 94af39c..8ce9b09 100644
--- a/src/database/sql/sql_test.go
+++ b/src/database/sql/sql_test.go
@@ -1819,6 +1819,18 @@
nullTestRun(t, spec)
}

+func TestNullInt16Param(t *testing.T) {
+ spec := nullTestSpec{"nullint16", "int16", [6]nullTestRow{
+ {NullInt16{31, true}, 1, NullInt16{31, true}},
+ {NullInt16{-22, false}, 1, NullInt16{0, false}},
+ {22, 1, NullInt16{22, true}},
+ {NullInt16{33, true}, 1, NullInt16{33, true}},
+ {NullInt16{222, false}, 1, NullInt16{0, false}},
+ {0, NullInt16{31, false}, nil},
+ }}
+ nullTestRun(t, spec)
+}
+
func TestNullFloat64Param(t *testing.T) {
spec := nullTestSpec{"nullfloat64", "float64", [6]nullTestRow{
{NullFloat64{31.2, true}, 1, NullFloat64{31.2, true}},

To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
Gerrit-Change-Number: 311572
Gerrit-PatchSet: 1
Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
Gerrit-MessageType: newchange

Ian Lance Taylor (Gerrit)

unread,
Apr 20, 2021, 3:49:22 PM4/20/21
to Ariel Mashraki, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, Daniel Theophanes, Kevin Burke, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: Daniel Theophanes, Brad Fitzpatrick, Ariel Mashraki.

Patch set 1:Run-TryBot +1

View Change

    To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    Gerrit-Change-Number: 311572
    Gerrit-PatchSet: 1
    Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Go Bot <go...@golang.org>
    Gerrit-CC: Kevin Burke <k...@inburke.com>
    Gerrit-Attention: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Comment-Date: Tue, 20 Apr 2021 19:49:15 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Emmanuel Odeke (Gerrit)

    unread,
    Apr 20, 2021, 7:20:54 PM4/20/21
    to Ariel Mashraki, goph...@pubsubhelper.golang.org, Go Bot, Ian Lance Taylor, Brad Fitzpatrick, Daniel Theophanes, Kevin Burke, golang-co...@googlegroups.com

    Attention is currently required from: Daniel Theophanes, Brad Fitzpatrick, Ariel Mashraki.

    View Change

    2 comments:

    • Commit Message:

    • Patchset:

      • Patch Set #1:

        Thank you for this change, Ariel. Could we perhaps combine CL 311989
        into this and then we can keep the "Fixes #NNNN"?

    To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    Gerrit-Change-Number: 311572
    Gerrit-PatchSet: 1
    Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-CC: Kevin Burke <k...@inburke.com>
    Gerrit-Attention: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Comment-Date: Tue, 20 Apr 2021 23:20:49 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Ariel Mashraki (Gerrit)

    unread,
    Apr 21, 2021, 2:10:03 AM4/21/21
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Daniel Theophanes, Brad Fitzpatrick, Ariel Mashraki.

    Ariel Mashraki uploaded patch set #2 to this change.

    View Change

    database/sql: add NullInt16 and NullByte


    Fixes #40082

    Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    ---
    M src/database/sql/fakedb_test.go
    M src/database/sql/sql.go
    M src/database/sql/sql_test.go
    3 files changed, 83 insertions(+), 1 deletion(-)

    To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    Gerrit-Change-Number: 311572
    Gerrit-PatchSet: 2
    Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-CC: Kevin Burke <k...@inburke.com>
    Gerrit-Attention: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-MessageType: newpatchset

    Ariel Mashraki (Gerrit)

    unread,
    Apr 21, 2021, 2:11:07 AM4/21/21
    to goph...@pubsubhelper.golang.org, Emmanuel Odeke, Go Bot, Ian Lance Taylor, Brad Fitzpatrick, Daniel Theophanes, Kevin Burke, golang-co...@googlegroups.com

    Attention is currently required from: Daniel Theophanes, Brad Fitzpatrick, Emmanuel Odeke.

    View Change

    2 comments:

    • Commit Message:

      • Ack

    • Patchset:

      • Patch Set #1:

        Thank you for this change, Ariel. Could we perhaps combine CL 311989 […]

        Sure.

    To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    Gerrit-Change-Number: 311572
    Gerrit-PatchSet: 2
    Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-CC: Kevin Burke <k...@inburke.com>
    Gerrit-Attention: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-Comment-Date: Wed, 21 Apr 2021 06:11:00 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-MessageType: comment

    Emmanuel Odeke (Gerrit)

    unread,
    Apr 21, 2021, 3:29:34 PM4/21/21
    to Ariel Mashraki, goph...@pubsubhelper.golang.org, Go Bot, Ian Lance Taylor, Brad Fitzpatrick, Daniel Theophanes, Kevin Burke, golang-co...@googlegroups.com

    Attention is currently required from: Daniel Theophanes, Brad Fitzpatrick, Ariel Mashraki.

    Patch set 2:Run-TryBot +1

    View Change

    3 comments:

    • Patchset:

    • File src/database/sql/sql.go:

      • Patch Set #2, Line 277:

        	n.Valid = true
        return convertAssign(&n.Int16, value)

        As per #45662, this code pattern is invalid, we need to have:
        err := convertAssign(&n.Int16, value)
        n.Valid = err == nil
        return err
      • Patch Set #2, Line 303:

        	n.Valid = true
        return convertAssign(&n.Byte, value)

        As per #45662, this code pattern is invalid, we need to have:
        err := convertAssign(&n.Byte, value)
        n.Valid = err == nil
        return err

    To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    Gerrit-Change-Number: 311572
    Gerrit-PatchSet: 2
    Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Kevin Burke <k...@inburke.com>
    Gerrit-Attention: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Comment-Date: Wed, 21 Apr 2021 19:29:29 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Ariel Mashraki (Gerrit)

    unread,
    Apr 21, 2021, 4:18:31 PM4/21/21
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Daniel Theophanes, Brad Fitzpatrick, Ariel Mashraki.

    Ariel Mashraki uploaded patch set #3 to this change.

    View Change

    database/sql: add NullInt16 and NullByte

    Fixes #40082

    Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    ---
    M src/database/sql/fakedb_test.go
    M src/database/sql/sql.go
    M src/database/sql/sql_test.go
    3 files changed, 85 insertions(+), 1 deletion(-)

    To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    Gerrit-Change-Number: 311572
    Gerrit-PatchSet: 3
    Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Kevin Burke <k...@inburke.com>
    Gerrit-Attention: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-MessageType: newpatchset

    Ariel Mashraki (Gerrit)

    unread,
    Apr 21, 2021, 4:19:26 PM4/21/21
    to goph...@pubsubhelper.golang.org, Go Bot, Emmanuel Odeke, Ian Lance Taylor, Brad Fitzpatrick, Daniel Theophanes, Kevin Burke, golang-co...@googlegroups.com

    Attention is currently required from: Daniel Theophanes, Brad Fitzpatrick, Emmanuel Odeke.

    View Change

    3 comments:

    • Patchset:

    • File src/database/sql/sql.go:

      • As per #45662, this code pattern is invalid, we need to have: […]

        Done

      • As per #45662, this code pattern is invalid, we need to have: […]

        Done

    To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    Gerrit-Change-Number: 311572
    Gerrit-PatchSet: 3
    Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Kevin Burke <k...@inburke.com>
    Gerrit-Attention: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-Comment-Date: Wed, 21 Apr 2021 20:19:21 +0000

    Emmanuel Odeke (Gerrit)

    unread,
    Apr 21, 2021, 5:17:20 PM4/21/21
    to Ariel Mashraki, goph...@pubsubhelper.golang.org, Go Bot, Ian Lance Taylor, Brad Fitzpatrick, Daniel Theophanes, Kevin Burke, golang-co...@googlegroups.com

    Attention is currently required from: Kevin Burke, Daniel Theophanes, Brad Fitzpatrick, Ariel Mashraki, Ian Lance Taylor.

    Patch set 3:Run-TryBot +1Code-Review +2

    View Change

    1 comment:

    • Patchset:

      • Patch Set #3:

        LGTM, thank you Ariel! Daniel, Brad, Ian, Kevin, please take a look too.

    To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
    Gerrit-Change-Number: 311572
    Gerrit-PatchSet: 3
    Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Kevin Burke <k...@inburke.com>
    Gerrit-Attention: Kevin Burke <k...@inburke.com>
    Gerrit-Attention: Daniel Theophanes <kard...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ariel Mashraki <ar...@mashraki.co.il>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Wed, 21 Apr 2021 21:16:23 +0000

    Daniel Theophanes (Gerrit)

    unread,
    May 4, 2021, 11:14:30 AM5/4/21
    to Ariel Mashraki, goph...@pubsubhelper.golang.org, Go Bot, Emmanuel Odeke, Ian Lance Taylor, Brad Fitzpatrick, Kevin Burke, golang-co...@googlegroups.com

    Attention is currently required from: Kevin Burke, Brad Fitzpatrick, Ariel Mashraki, Ian Lance Taylor.

    Patch set 3:Code-Review +2

    View Change

      To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
      Gerrit-Change-Number: 311572
      Gerrit-PatchSet: 3
      Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
      Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-CC: Kevin Burke <k...@inburke.com>
      Gerrit-Attention: Kevin Burke <k...@inburke.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Ariel Mashraki <ar...@mashraki.co.il>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Comment-Date: Tue, 04 May 2021 15:14:21 +0000

      Emmanuel Odeke (Gerrit)

      unread,
      May 4, 2021, 1:31:36 PM5/4/21
      to Ariel Mashraki, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Daniel Theophanes, Go Bot, Ian Lance Taylor, Brad Fitzpatrick, Kevin Burke, golang-co...@googlegroups.com

      Emmanuel Odeke submitted this change.

      View Change

      Approvals: Daniel Theophanes: Looks good to me, approved Emmanuel Odeke: Looks good to me, approved; Run TryBots Go Bot: TryBots succeeded
      database/sql: add NullInt16 and NullByte

      Fixes #40082

      Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
      Reviewed-on: https://go-review.googlesource.com/c/go/+/311572
      Reviewed-by: Emmanuel Odeke <emma...@orijtech.com>
      Reviewed-by: Daniel Theophanes <kard...@gmail.com>
      Run-TryBot: Emmanuel Odeke <emma...@orijtech.com>
      TryBot-Result: Go Bot <go...@golang.org>

      ---
      M src/database/sql/fakedb_test.go
      M src/database/sql/sql.go
      M src/database/sql/sql_test.go
      3 files changed, 85 insertions(+), 1 deletion(-)

      diff --git a/src/database/sql/fakedb_test.go b/src/database/sql/fakedb_test.go
      index 72e16e0..4b68f1c 100644

      --- a/src/database/sql/fakedb_test.go
      +++ b/src/database/sql/fakedb_test.go
      @@ -1186,9 +1186,11 @@
      return driver.Bool
      case "nullbool":
      return driver.Null{Converter: driver.Bool}
      +	case "byte", "int16":

      + return driver.NotNull{Converter: driver.DefaultParameterConverter}
      case "int32":
      return driver.Int32
      - case "nullint32":
      +	case "nullbyte", "nullint32", "nullint16":

      return driver.Null{Converter: driver.DefaultParameterConverter}
      case "string":
      return driver.NotNull{Converter: fakeDriverString{}}
      @@ -1222,6 +1224,10 @@
      return reflect.TypeOf(false)
      case "nullbool":
      return reflect.TypeOf(NullBool{})
      + case "int16":
      + return reflect.TypeOf(int16(0))
      + case "nullint16":
      + return reflect.TypeOf(NullInt16{})
      case "int32":
      return reflect.TypeOf(int32(0))
      case "nullint32":
      diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
      index 61b5018..68fb392 100644
      --- a/src/database/sql/sql.go
      +++ b/src/database/sql/sql.go
      @@ -260,6 +260,60 @@

      return int64(n.Int32), nil
      }

      +// NullInt16 represents an int16 that may be null.
      +// NullInt16 implements the Scanner interface so
      +// it can be used as a scan destination, similar to NullString.
      +type NullInt16 struct {
      + Int16 int16
      + Valid bool // Valid is true if Int16 is not NULL
      +}
      +
      +// Scan implements the Scanner interface.
      +func (n *NullInt16) Scan(value interface{}) error {
      + if value == nil {
      + n.Int16, n.Valid = 0, false
      + return nil
      + }
      +	err := convertAssign(&n.Int16, value)
      + n.Valid = err == nil
      + return err

      +}
      +
      +// Value implements the driver Valuer interface.
      +func (n NullInt16) Value() (driver.Value, error) {
      + if !n.Valid {
      + return nil, nil
      + }
      + return int64(n.Int16), nil
      +}
      +
      +// NullByte represents a byte that may be null.
      +// NullByte implements the Scanner interface so

      +// it can be used as a scan destination, similar to NullString.
      +type NullByte struct {
      + Byte byte
      + Valid bool // Valid is true if Byte is not NULL

      +}
      +
      +// Scan implements the Scanner interface.
      +func (n *NullByte) Scan(value interface{}) error {

      + if value == nil {
      +		n.Byte, n.Valid = 0, false
      + return nil
      + }
      + err := convertAssign(&n.Byte, value)
      + n.Valid = err == nil
      + return err

      +}
      +
      +// Value implements the driver Valuer interface.
      +func (n NullByte) Value() (driver.Value, error) {

      + if !n.Valid {
      + return nil, nil
      + }
      +	return int64(n.Byte), nil

      +}
      +
      // NullFloat64 represents a float64 that may be null.
      // NullFloat64 implements the Scanner interface so
      // it can be used as a scan destination, similar to NullString.
      diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go
      index 94af39c..80f63e8 100644
      --- a/src/database/sql/sql_test.go
      +++ b/src/database/sql/sql_test.go
      @@ -1819,6 +1819,30 @@

      nullTestRun(t, spec)
      }

      +func TestNullInt16Param(t *testing.T) {
      + spec := nullTestSpec{"nullint16", "int16", [6]nullTestRow{
      + {NullInt16{31, true}, 1, NullInt16{31, true}},
      + {NullInt16{-22, false}, 1, NullInt16{0, false}},
      + {22, 1, NullInt16{22, true}},
      + {NullInt16{33, true}, 1, NullInt16{33, true}},
      + {NullInt16{222, false}, 1, NullInt16{0, false}},
      + {0, NullInt16{31, false}, nil},
      + }}
      + nullTestRun(t, spec)
      +}
      +
      +func TestNullByteParam(t *testing.T) {
      + spec := nullTestSpec{"nullbyte", "byte", [6]nullTestRow{
      + {NullByte{31, true}, 1, NullByte{31, true}},
      + {NullByte{0, false}, 1, NullByte{0, false}},
      + {22, 1, NullByte{22, true}},
      + {NullByte{33, true}, 1, NullByte{33, true}},
      + {NullByte{222, false}, 1, NullByte{0, false}},
      + {0, NullByte{31, false}, nil},

      + }}
      + nullTestRun(t, spec)
      +}
      +
      func TestNullFloat64Param(t *testing.T) {
      spec := nullTestSpec{"nullfloat64", "float64", [6]nullTestRow{
      {NullFloat64{31.2, true}, 1, NullFloat64{31.2, true}},

      To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
      Gerrit-Change-Number: 311572
      Gerrit-PatchSet: 4
      Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
      Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-CC: Kevin Burke <k...@inburke.com>
      Gerrit-MessageType: merged

      Emmanuel Odeke (Gerrit)

      unread,
      May 4, 2021, 4:15:27 PM5/4/21
      to Ariel Mashraki, goph...@pubsubhelper.golang.org, Daniel Theophanes, Go Bot, Ian Lance Taylor, Brad Fitzpatrick, Kevin Burke, golang-co...@googlegroups.com

      View Change

      1 comment:

      To view, visit change 311572. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325
      Gerrit-Change-Number: 311572
      Gerrit-PatchSet: 4
      Gerrit-Owner: Ariel Mashraki <ar...@mashraki.co.il>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Daniel Theophanes <kard...@gmail.com>
      Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-CC: Kevin Burke <k...@inburke.com>
      Gerrit-Comment-Date: Tue, 04 May 2021 20:15:22 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Gerrit-MessageType: comment
      Reply all
      Reply to author
      Forward
      0 new messages