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
+5.1k Swift : Convert (cast) Float to Int or Int32 value
+6.5k Grep : How to grep for strings inside binary data
+6.2k Golang : Extract XML attribute data with attr field tag example
+11.3k Golang : Characters limiter example
+9.4k Golang : How to protect your source code from client, hosting company or hacker?
+6k Javascript : Get operating system and browser information
+14k Golang : Reverse IP address for reverse DNS lookup example
+41k Golang : How to check if a string contains another sub-string?
+9.3k Golang : How to get ECDSA curve and parameters data?
+14.8k Golang : Normalize unicode strings for comparison purpose
+9.5k Golang : Get all countries currencies code in JSON format
+6.7k Golang : Output or print out JSON stream/encoded data