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
+13.6k Golang : reCAPTCHA example
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+10.2k Golang : Check a web page existence with HEAD request example
+12.3k Golang : How to display image file or expose CSS, JS files from localhost?
+12.1k Golang : Save webcamera frames to video file
+12.4k Golang : Search and extract certain XML data example
+11.7k Golang : Secure file deletion with wipe example
+12.1k Golang : md5 hash of a string
+15.8k Golang : Get digits from integer before and after given position example
+7.9k Golang : Get today's weekday name and calculate target day distance example
+5.4k Golang : Reclaim memory occupied by make() example
+39.2k Golang : How to read CSV file