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
+19.3k Golang : Get host name or domain name from IP address
+9.9k Golang : Translate language with language package example
+13.4k Golang : Verify token from Google Authenticator App
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+15.2k Golang : Save(pipe) HTTP response into a file
+7.3k Golang : Of hash table and hash map
+6.9k Mac/Linux/Windows : Get CPU information from command line
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+8.5k Linux/Unix : fatal: the Postfix mail system is already running
+17.9k Golang : Login and logout a user after password verification and redirect example
+30.5k Golang : Generate random string