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
+16.4k Golang : How to implement two-factor authentication?
+26.4k Golang : Get executable name behind process ID example
+6.3k Golang : Extract sub-strings
+7.9k Swift : Convert (cast) String to Float
+10.3k Golang : Convert file content to Hex
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+12.6k Golang : Transform comma separated string to slice example
+11.9k Golang : Convert decimal number(integer) to IPv4 address
+9.4k Golang : Web(Javascript) to server-side websocket example
+10.1k Golang : Compare files modify date example
+51.1k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+9k Golang : Get SPF and DMARC from email headers to fight spam