transaction.go 750 B

12345678910111213141516171819202122232425262728293031323334
  1. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
  2. //
  3. // Copyright 2012 Julien Schmidt. All rights reserved.
  4. // http://www.julienschmidt.com
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla Public
  7. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  8. // You can obtain one at http://mozilla.org/MPL/2.0/.
  9. package mysql
  10. type mysqlTx struct {
  11. mc *mysqlConn
  12. }
  13. func (tx *mysqlTx) Commit() (err error) {
  14. if tx.mc == nil || tx.mc.netConn == nil {
  15. return errInvalidConn
  16. }
  17. err = tx.mc.exec("COMMIT")
  18. tx.mc = nil
  19. return
  20. }
  21. func (tx *mysqlTx) Rollback() (err error) {
  22. if tx.mc == nil || tx.mc.netConn == nil {
  23. return errInvalidConn
  24. }
  25. err = tx.mc.exec("ROLLBACK")
  26. tx.mc = nil
  27. return
  28. }