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
+14.6k Golang : Execute function at intervals or after some delay
+7.2k Golang : Use modern ciphers only in secure connection
+7.8k Golang : Load DSA public key from file example
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes
+15.6k Golang : Validate hostname
+11.9k Golang : Convert(cast) bigint to string
+11.8k Golang : Verify Linux user password again before executing a program example
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+17.9k Golang : How to make a file read only and set it to writable again?
+16.5k Golang : Check if a string contains multiple sub-strings in []string?
+5.9k Golang : Extract unicode string from another unicode string example