Golang database/sql.Stmt.Exec function examples
package database/sql
Exec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
Golang database/sql.Stmt.Exec function usage examples
Example 1:
var queries = [...]struct {
in string
codes []string
}{
{"DROP TABLE IF EXISTS no_such_table", []string{"1051"}},
{"INSERT INTO test VALUES(10,'mysql'),(NULL,'test'),(300,'Open Source')", []string{"1265", "1048", "1264", "1265"}},
}
var stmt *sql.Stmt
var err error
for i := range queries {
stmt, err = dbt.db.Prepare(queries[i].in)
if err != nil {
dbt.Errorf("Error on preparing query %s: %s", queries[i].in, err.Error())
}
_, err = stmt.Exec()
...
Example 2:
var params ...interface{}
var sql string
stmt, err := this.connection.Prepare(sql)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
result, err := stmt.Exec(params...) // <---- here
if err != nil {
fmt.Println(err)
os.Exit(1)
stmt.Close()
}
References :
https://github.com/go-sql-driver/mysql/blob/master/driver_test.go
Advertisement
Something interesting
Tutorials
+14k Golang : Google Drive API upload and rename example
+23.7k Find and replace a character in a string in Go
+6k Golang : Compound interest over time example
+25.7k Golang : How to write CSV data to file
+17.7k Golang : Read data from config file and assign to variables
+10.1k Golang : Identifying Golang HTTP client request
+13.2k Golang : Convert(cast) int to int64
+5.4k How to check with curl if my website or the asset is gzipped ?
+17.2k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+52.6k Golang : How to get struct field and value by name
+6.2k Golang : Extract XML attribute data with attr field tag example
+19.3k Golang : Calculate entire request body length during run time