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
+8.2k Golang : Get final or effective URL with Request.URL example
+10.3k Golang : Convert file content to Hex
+6.3k Javascript : Generate random key with specific length
+8.3k Golang: Prevent over writing file with md5 hash
+7.7k Golang : Command line ticker to show work in progress
+5.5k Golang : Stop goroutine without channel
+11.7k Golang : How to detect a server/machine network interface capabilities?
+11.2k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+7.3k Golang : Calculate how many weeks left to go in a given year
+31.9k Golang : Convert an image file to []byte
+6k PHP : How to check if an array is empty ?
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example