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
+6.9k Mac OSX : Find large files by size
+15.8k Golang : Get digits from integer before and after given position example
+5k Golang : micron to centimeter example
+31.1k Golang : Calculate percentage change of two values
+9.4k Golang : Web(Javascript) to server-side websocket example
+7.9k Javascript : How to check a browser's Do Not Track status?
+20.3k Golang : Check if os.Stdin input data is piped or from terminal
+20.2k Golang : Convert seconds to human readable time format example
+28.2k Golang : Connect to database (MySQL/MariaDB) server
+21.6k Golang : Encrypt and decrypt data with TripleDES
+6k Golang : Compound interest over time example
+7.8k Golang : Lock executable to a specific machine with unique hash of the machine