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
+7.7k Golang : Routes multiplexer routing example with regular expression control
+14.5k Golang : Get HTTP protocol version example
+35.7k Golang : Convert date or time stamp from string to time.Time type
+35.3k Golang : Validate IP address
+15.4k Golang : Loop each day of the current month example
+11.8k Golang : Forwarding a local port to a remote server example
+7.1k SSL : How to check if current certificate is sha1 or sha2 from command line
+11.2k Golang : How to detect a server/machine network interface capabilities?
+14.6k nginx: [emerg] unknown directive "ssl"
+12.4k Golang : How to calculate the distance between two coordinates using Haversine formula
+17.8k Golang : Logging with logrus
+9.4k Golang : Setting variable value with ldflags