-
Notifications
You must be signed in to change notification settings - Fork 501
/
rpc.go
83 lines (77 loc) · 1.77 KB
/
rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package mssql
import (
"encoding/binary"
)
type procId struct {
id uint16
name string
}
// parameter flags
const (
fByRevValue = 1
fDefaultValue = 2
)
type param struct {
Name string
Flags uint8
ti typeInfo
buffer []byte
}
var (
sp_Cursor = procId{1, ""}
sp_CursorOpen = procId{2, ""}
sp_CursorPrepare = procId{3, ""}
sp_CursorExecute = procId{4, ""}
sp_CursorPrepExec = procId{5, ""}
sp_CursorUnprepare = procId{6, ""}
sp_CursorFetch = procId{7, ""}
sp_CursorOption = procId{8, ""}
sp_CursorClose = procId{9, ""}
sp_ExecuteSql = procId{10, ""}
sp_Prepare = procId{11, ""}
sp_PrepExec = procId{13, ""}
sp_PrepExecRpc = procId{14, ""}
sp_Unprepare = procId{15, ""}
)
// http://msdn.microsoft.com/en-us/library/dd357576.aspx
func sendRpc(buf *tdsBuffer, headers []headerStruct, proc procId, flags uint16, params []param, resetSession bool) (err error) {
buf.BeginPacket(packRPCRequest, resetSession)
writeAllHeaders(buf, headers)
if len(proc.name) == 0 {
var idswitch uint16 = 0xffff
err = binary.Write(buf, binary.LittleEndian, &idswitch)
if err != nil {
return
}
err = binary.Write(buf, binary.LittleEndian, &proc.id)
if err != nil {
return
}
} else {
err = writeUsVarChar(buf, proc.name)
if err != nil {
return
}
}
err = binary.Write(buf, binary.LittleEndian, &flags)
if err != nil {
return
}
for _, param := range params {
if err = writeBVarChar(buf, param.Name); err != nil {
return
}
if err = binary.Write(buf, binary.LittleEndian, param.Flags); err != nil {
return
}
err = writeTypeInfo(buf, ¶m.ti)
if err != nil {
return
}
err = param.ti.Writer(buf, param.ti, param.buffer)
if err != nil {
return
}
}
return buf.FinishPacket()
}