本站源代码
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.

111 lines
2.5KB

  1. package mssql
  2. // Transaction Manager requests
  3. // http://msdn.microsoft.com/en-us/library/dd339887.aspx
  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. type isoLevel uint8
  17. const (
  18. isolationUseCurrent isoLevel = 0
  19. isolationReadUncommited = 1
  20. isolationReadCommited = 2
  21. isolationRepeatableRead = 3
  22. isolationSerializable = 4
  23. isolationSnapshot = 5
  24. )
  25. func sendBeginXact(buf *tdsBuffer, headers []headerStruct, isolation isoLevel, name string, resetSession bool) (err error) {
  26. buf.BeginPacket(packTransMgrReq, resetSession)
  27. writeAllHeaders(buf, headers)
  28. var rqtype uint16 = tmBeginXact
  29. err = binary.Write(buf, binary.LittleEndian, &rqtype)
  30. if err != nil {
  31. return
  32. }
  33. err = binary.Write(buf, binary.LittleEndian, &isolation)
  34. if err != nil {
  35. return
  36. }
  37. err = writeBVarChar(buf, name)
  38. if err != nil {
  39. return
  40. }
  41. return buf.FinishPacket()
  42. }
  43. const (
  44. fBeginXact = 1
  45. )
  46. func sendCommitXact(buf *tdsBuffer, headers []headerStruct, name string, flags uint8, isolation uint8, newname string, resetSession bool) error {
  47. buf.BeginPacket(packTransMgrReq, resetSession)
  48. writeAllHeaders(buf, headers)
  49. var rqtype uint16 = tmCommitXact
  50. err := binary.Write(buf, binary.LittleEndian, &rqtype)
  51. if err != nil {
  52. return err
  53. }
  54. err = writeBVarChar(buf, name)
  55. if err != nil {
  56. return err
  57. }
  58. err = binary.Write(buf, binary.LittleEndian, &flags)
  59. if err != nil {
  60. return err
  61. }
  62. if flags&fBeginXact != 0 {
  63. err = binary.Write(buf, binary.LittleEndian, &isolation)
  64. if err != nil {
  65. return err
  66. }
  67. err = writeBVarChar(buf, name)
  68. if err != nil {
  69. return err
  70. }
  71. }
  72. return buf.FinishPacket()
  73. }
  74. func sendRollbackXact(buf *tdsBuffer, headers []headerStruct, name string, flags uint8, isolation uint8, newname string, resetSession bool) error {
  75. buf.BeginPacket(packTransMgrReq, resetSession)
  76. writeAllHeaders(buf, headers)
  77. var rqtype uint16 = tmRollbackXact
  78. err := binary.Write(buf, binary.LittleEndian, &rqtype)
  79. if err != nil {
  80. return err
  81. }
  82. err = writeBVarChar(buf, name)
  83. if err != nil {
  84. return err
  85. }
  86. err = binary.Write(buf, binary.LittleEndian, &flags)
  87. if err != nil {
  88. return err
  89. }
  90. if flags&fBeginXact != 0 {
  91. err = binary.Write(buf, binary.LittleEndian, &isolation)
  92. if err != nil {
  93. return err
  94. }
  95. err = writeBVarChar(buf, name)
  96. if err != nil {
  97. return err
  98. }
  99. }
  100. return buf.FinishPacket()
  101. }
上海开阖软件有限公司 沪ICP备12045867号-1