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
+7.2k Golang : How to handle file size larger than available memory panic issue
+8.9k Golang : How to check if a string with spaces in between is numeric?
+8.8k Golang : Intercept and compare HTTP response code example
+12.2k Golang : Exit, terminating or aborting a program
+7.2k Golang : Rot13 and Rot5 algorithms example
+19.6k Golang : How to get own program name during runtime ?
+10.7k Golang : Read until certain character to break for loop
+5.1k Javascript : How to loop over and parse JSON data?
+14k Golang : Recombine chunked files example
+17.6k Golang : How to log each HTTP request to your web server?
+8.1k Golang: Prevent over writing file with md5 hash
+17.1k Golang : Get future or past hours, minutes or seconds