Golang database/sql.Tx.Exec and Rollback functions examples
package database/sql
Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
Rollback aborts the transaction.
Golang database/sql.Tx.Exec and Rollback functions usage examples
Example 1:
result, err := tx.Exec(`INSERT INTO order_request (member_id) VALUES (?)`, memberId)
if err != nil {
log.Print(err.Error())
}
orderId, err := result.LastInsertId()
Example 2:
_, err = tx.Exec("DELETE FROM "+SqlTableName+" WHERE id = $1", id)
if err != nil {
tx.Rollback()
return err
}
References :
Advertisement
Something interesting
Tutorials
+23.1k Golang : simulate tail -f or read last line from log file example
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+18.5k Golang : Write file with io.WriteString
+11.2k Google Maps URL parameters configuration
+8.2k Golang : Find relative luminance or color brightness
+6.1k Golang : Debug with Godebug
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+4.8k Which content-type(MIME type) to use for JSON data
+29.4k Golang : JQuery AJAX post data to server and send data back to client example
+13k Golang : Get terminal width and height example
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+5.3k Golang : Pad file extension automagically