Golang database/sql.NullString type example
package database/sql
NullString represents a string that may be null. NullString implements the Scanner interface so it can be used as a scan destination:
Golang database/sql.NullString type usage example
Example 1: ( from http://golang.org/pkg/database/sql/#NullString )
var s NullString
err := db.QueryRow("SELECT name FROM foo WHERE id=?", id).Scan(&s)
...
if s.Valid {
// use s.String
} else {
// NULL value
}
Example 2:
var num int
var text string
var blob []byte
var nothing sql.NullString
err = txn.QueryRow("SELECT * FROM temp").Scan(&num, &text, &blob, ¬hing)
if err != nil {
t.Fatal(err)
}
Reference :
Advertisement
Something interesting
Tutorials
+8.9k Golang : How to join strings?
+12.2k Golang : Save webcamera frames to video file
+12.8k Golang : Transform comma separated string to slice example
+4.9k Facebook : How to place save to Facebook button on your website
+21.2k Golang : Sort and reverse sort a slice of strings
+8.3k Golang : Tell color name with OpenCV example
+6.5k Golang : Break string into a slice of characters example
+11.2k Golang : Read until certain character to break for loop
+7.1k Golang : Fibonacci number generator examples
+7.7k Golang : How to stop user from directly running an executable file?
+9.5k Golang : Terminate-stay-resident or daemonize your program?
+6k Golang : Generate multiplication table from an integer example