You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.1 KiB

  1. // Transaction Manager requests
  2. // http://msdn.microsoft.com/en-us/library/dd339887.aspx
  3. package mssql
  4. import (
  5. "encoding/binary"
  6. )
  7. const (
  8. tmGetDtcAddr = 0
  9. tmPropagateXact = 1
  10. tmBeginXact = 5
  11. tmPromoteXact = 6
  12. tmCommitXact = 7
  13. tmRollbackXact = 8
  14. tmSaveXact = 9
  15. )
  16. func sendBeginXact(buf *tdsBuffer, headers []headerStruct, isolation uint8,
  17. name string) (err error) {
  18. buf.BeginPacket(packTransMgrReq)
  19. writeAllHeaders(buf, headers)
  20. var rqtype uint16 = tmBeginXact
  21. err = binary.Write(buf, binary.LittleEndian, &rqtype)
  22. if err != nil {
  23. return
  24. }
  25. err = binary.Write(buf, binary.LittleEndian, &isolation)
  26. if err != nil {
  27. return
  28. }
  29. err = writeBVarChar(buf, name)
  30. if err != nil {
  31. return
  32. }
  33. return buf.FinishPacket()
  34. }
  35. const (
  36. fBeginXact = 1
  37. )
  38. func sendCommitXact(buf *tdsBuffer, headers []headerStruct, name string, flags uint8, isolation uint8, newname string) error {
  39. buf.BeginPacket(packTransMgrReq)
  40. writeAllHeaders(buf, headers)
  41. var rqtype uint16 = tmCommitXact
  42. err := binary.Write(buf, binary.LittleEndian, &rqtype)
  43. if err != nil {
  44. return err
  45. }
  46. err = writeBVarChar(buf, name)
  47. if err != nil {
  48. return err
  49. }
  50. err = binary.Write(buf, binary.LittleEndian, &flags)
  51. if err != nil {
  52. return err
  53. }
  54. if flags&fBeginXact != 0 {
  55. err = binary.Write(buf, binary.LittleEndian, &isolation)
  56. if err != nil {
  57. return err
  58. }
  59. err = writeBVarChar(buf, name)
  60. if err != nil {
  61. return err
  62. }
  63. }
  64. return buf.FinishPacket()
  65. }
  66. func sendRollbackXact(buf *tdsBuffer, headers []headerStruct, name string, flags uint8, isolation uint8, newname string) error {
  67. buf.BeginPacket(packTransMgrReq)
  68. writeAllHeaders(buf, headers)
  69. var rqtype uint16 = tmRollbackXact
  70. err := binary.Write(buf, binary.LittleEndian, &rqtype)
  71. if err != nil {
  72. return err
  73. }
  74. err = writeBVarChar(buf, name)
  75. if err != nil {
  76. return err
  77. }
  78. err = binary.Write(buf, binary.LittleEndian, &flags)
  79. if err != nil {
  80. return err
  81. }
  82. if flags&fBeginXact != 0 {
  83. err = binary.Write(buf, binary.LittleEndian, &isolation)
  84. if err != nil {
  85. return err
  86. }
  87. err = writeBVarChar(buf, name)
  88. if err != nil {
  89. return err
  90. }
  91. }
  92. return buf.FinishPacket()
  93. }