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
+6.1k Golang : Grab news article text and use NLP to get each paragraph's sentences
+10.1k Golang : Compare files modify date example
+8.7k Golang : How to join strings?
+7.8k Golang : Example of how to detect which type of script a word belongs to
+4.5k Java : Generate multiplication table example
+25.5k Golang : Generate MD5 checksum of a file
+11.2k CodeIgniter : How to check if a session exist in PHP?
+10.1k Golang : Get login name from environment and prompt for password
+8.9k Golang : Sort lines of text example
+14.9k Golang : Submit web forms without browser by http.PostForm example
+18.5k Golang : Send email with attachment
+17k Golang : Get input from keyboard