Golang database/sql.Stmt type examples
package database/sql
Stmt is a prepared statement. Stmt is safe for concurrent use by multiple goroutines.
Golang database/sql.Stmt type usage examples
Example 1:
func closeResources(rows *sql.Rows, stmt *sql.Stmt) error {
var err error
if rows != nil {
err = rows.Close()
if err != nil {
return err
}
}
if stmt != nil { // <--- here
err = stmt.Close()
if err != nil {
return err
}
}
return nil
}
Example 2:
var (
SELECT_BIC = "SELECT bic FROM BANK_DATA WHERE bankcode = ? AND country = ?;"
SELECT_BIC_STMT *sql.Stmt
)
func prepareSelectBicStatement(db *sql.DB) {
var err error
SELECT_BIC_STMT, err = db.Prepare(SELECT_BIC)
if err != nil {
panic("Couldn't prepare statement: " + SELECT_BIC)
}
}
References :
https://github.com/fourcube/goiban/blob/master/external_data.go
Advertisement
Something interesting
Tutorials
+16k Golang : How to tell if a file is compressed either gzip or zip ?
+5.2k Golang : Experimenting with the Rejang script
+8.6k Golang : Quadratic example
+12.1k Generate salted password with OpenSSL example
+5.2k Golang : How to search a list of records or data structures
+4.1k Which content-type(MIME type) to use for JSON data
+10.7k CodeIgniter : Import Linkedin data
+26k Golang : Convert CSV data to JSON format and save to file
+14.8k Golang : Read large file with bufio.Scanner cause token too long error
+32.9k Golang : convert(cast) bytes to string
+18.6k Golang : Count JSON objects and convert to slice/array