1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-17 23:54:25 +00:00
gitea/vendor/github.com/denisenkom/go-mssqldb/tran.go
btrepp 25b5ffb6af Enables mssql support (#383)
* Enables mssql support

Port of dlobs work in gogs.
Enables options in index.js
Enables MSSQL as a database option in go.
Sets ID to 0 on initial migration. Required for
MSSQL insert statements.

Signed-off-by: Beau Trepp <beautrepp@gmail.com>

* Vendors in denisenkom/go-mssqldb

Includes golang.org/x/crypto/md4
as this is required by go-msssqldb

Signed-off-by: Beau Trepp <beautrepp@gmail.com>
2016-12-24 09:37:35 +08:00

100 lines
2.1 KiB
Go

// Transaction Manager requests
// http://msdn.microsoft.com/en-us/library/dd339887.aspx
package mssql
import (
"encoding/binary"
)
const (
tmGetDtcAddr = 0
tmPropagateXact = 1
tmBeginXact = 5
tmPromoteXact = 6
tmCommitXact = 7
tmRollbackXact = 8
tmSaveXact = 9
)
func sendBeginXact(buf *tdsBuffer, headers []headerStruct, isolation uint8,
name string) (err error) {
buf.BeginPacket(packTransMgrReq)
writeAllHeaders(buf, headers)
var rqtype uint16 = tmBeginXact
err = binary.Write(buf, binary.LittleEndian, &rqtype)
if err != nil {
return
}
err = binary.Write(buf, binary.LittleEndian, &isolation)
if err != nil {
return
}
err = writeBVarChar(buf, name)
if err != nil {
return
}
return buf.FinishPacket()
}
const (
fBeginXact = 1
)
func sendCommitXact(buf *tdsBuffer, headers []headerStruct, name string, flags uint8, isolation uint8, newname string) error {
buf.BeginPacket(packTransMgrReq)
writeAllHeaders(buf, headers)
var rqtype uint16 = tmCommitXact
err := binary.Write(buf, binary.LittleEndian, &rqtype)
if err != nil {
return err
}
err = writeBVarChar(buf, name)
if err != nil {
return err
}
err = binary.Write(buf, binary.LittleEndian, &flags)
if err != nil {
return err
}
if flags&fBeginXact != 0 {
err = binary.Write(buf, binary.LittleEndian, &isolation)
if err != nil {
return err
}
err = writeBVarChar(buf, name)
if err != nil {
return err
}
}
return buf.FinishPacket()
}
func sendRollbackXact(buf *tdsBuffer, headers []headerStruct, name string, flags uint8, isolation uint8, newname string) error {
buf.BeginPacket(packTransMgrReq)
writeAllHeaders(buf, headers)
var rqtype uint16 = tmRollbackXact
err := binary.Write(buf, binary.LittleEndian, &rqtype)
if err != nil {
return err
}
err = writeBVarChar(buf, name)
if err != nil {
return err
}
err = binary.Write(buf, binary.LittleEndian, &flags)
if err != nil {
return err
}
if flags&fBeginXact != 0 {
err = binary.Write(buf, binary.LittleEndian, &isolation)
if err != nil {
return err
}
err = writeBVarChar(buf, name)
if err != nil {
return err
}
}
return buf.FinishPacket()
}