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
+5.4k Clean up Visual Studio For Mac installation failed disk full problem
+11.4k Golang : Generate DSA private, public key and PEM files example
+22.7k Golang : simulate tail -f or read last line from log file example
+7.3k Golang : Process json data with Jason package
+21.7k Golang : Use TLS version 1.2 and enforce server security configuration over client
+14.3k Golang : Parsing or breaking down URL
+39.9k Golang : UDP client server read write example
+6.7k Mac/Linux/Windows : Get CPU information from command line
+12k Golang : Pagination with go-paginator configuration example
+9.7k Golang : ffmpeg with os/exec.Command() returns non-zero status
+7.2k Golang : alternative to os.Exit() function
+19.7k Golang : Count JSON objects and convert to slice/array