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.7k Golang : How to capture return values from goroutines?
+8.8k Golang : How to use Gorilla webtoolkit context package properly
+10.2k Swift : Convert (cast) String to Integer
+9.2k Facebook : Getting the friends list with PHP return JSON format
+8.4k Golang : Progress bar with ∎ character
+9.1k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+5.4k Golang : Shortening import identifier
+9.1k Golang : Create unique title slugs example
+7.2k Golang : Gorrila set route name and get the current route name
+16.2k Golang : How to implement two-factor authentication?
+5.4k Swift : Get substring with rangeOfString() function example
+21.8k Golang : How to run Golang application such as web server in the background or as daemon?