Golang database/sql.Stmt.QueryRow function examples
package database/sql
QueryRow executes a prepared query statement with the given arguments. If an error occurs during the execution of the statement, that error will be returned by a call to Scan on the returned *Row, which is always non-nil. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
Golang database/sql.Stmt.QueryRow function usage examples
Example 1:
var name string
err := nameByUseridStmt.QueryRow(id).Scan(&name)
Example 2:
var (
SELECT_BY_BANK_CODE = "SELECT 1 FROM BANK_DATA WHERE bankcode = ? and country = ?;"
SELECT_BY_BANK_CODE_STMT *sql.Stmt
)
// describes the structure of an IBAN
type Iban struct {
countryCode string
checkDigit string
bban string
original string
bic string
}
bankCode := iban.bban[0:length]
var res int
err := SELECT_BY_BANK_CODE_STMT.QueryRow(bankCode, iban.countryCode).Scan(&res) //< -- here
References :
https://github.com/fourcube/goiban/blob/master/bankcodevalidation.go
Advertisement
Something interesting
Tutorials
+17.3k Golang : Generate thumbnails from images
+5.6k Nginx : Password protect a directory/folder
+24.3k Golang : How to read integer value from standard input ?
+13.7k Golang : Search folders for file recursively with wildcard support
+25.6k Golang : dial tcp: too many colons in address
+8k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+12.8k Golang : convert rune to unicode hexadecimal value and back to rune character
+8.8k Golang : Identifying Golang HTTP client request
+6.1k Golang : Get environment variable
+12.2k Golang : Image to ASCII art example
+7k Golang : Handle Palindrome string with case sensitivity and unicode
+4.8k Fix fatal error: evacuation not done in time problem