Golang database/sql.NullInt64 type examples

package database/sql

NullInt64 represents an int64 that may be null. NullInt64 implements the Scanner interface so it can be used as a scan destination, similar to NullString.

Golang database/sql.NullInt64 type usage examples

Example 1:

 var ni64 = sql.NullInt64{Valid: true}

Example 2:

 // NullInt64
 var ni sql.NullInt64

 // Invalid
 if err = nullStmt.QueryRow().Scan(&ni); err != nil {
 dbt.Fatal(err)
 }
 if ni.Valid {
 dbt.Error("Valid NullInt64 which should be invalid")
 }

References :

https://github.com/go-sql-driver/mysql/blob/master/driver_test.go

http://golang.org/pkg/database/sql/#NullInt64

Advertisement