Expand description
TDS — the Tabular Data Stream protocol SQL Server speaks.
Everything travels in packets: an eight-byte header and a payload, with a
message being the run of packets ending in one whose status carries the
end-of-message bit. Requests are built as one payload and split by
split_message; responses are reassembled and then read as a stream of
tokens by TokenStream.
Unlike PostgreSQL, TDS is little-endian everywhere except the packet header, whose length and SPID are network order. That single inconsistency is the source of most first-attempt bugs, so the header has its own type rather than being read inline.
Modules§
- encryption
- The values the ENCRYPTION option can carry, in both directions.
- packet
- Packet types, from the
Typebyte of the header. - prelogin_
option - PRELOGIN option tokens.
- status
- Status bits from the
Statusbyte of the header. - token
- Token identifiers from the response stream.
Structs§
- Done
- Login7
- Everything LOGIN7 carries that is not a constant.
- Login
Ack - The LOGINACK that says the credentials were accepted.
- Packet
Header - The eight bytes in front of every packet.
- Prelogin
Response - What the server answered in its PRELOGIN.
- Reader
- A cursor over a reassembled message.
- RpcParameter
- One parameter of an RPC call: a name and its already-encoded type and value.
- Server
Error - An error or an informational message from the server.
- Token
Stream - Reads a reassembled response message one token at a time.
Enums§
- Done
Kind - Which of the three DONE tokens arrived.
- EnvChange
- A change of session state the server announces rather than being asked.
- Token
Constants§
- DEFAULT_
PACKET_ SIZE - The packet size assumed before the server says otherwise.
- HEADER_
LEN - The fixed size of a packet header.
- SP_
EXECUTESQL - The well-known procedure id of
sp_executesql. - TDS_
VERSION_ 7_ 4 - TDS 7.4, which is what SQL Server 2012 and later speak.
Functions§
- all_
headers - The ALL_HEADERS block every batch and RPC carries in TDS 7.2 and later.
- decode_
ucs2 - Decode UTF-16LE, which TDS calls UCS-2 and uses for every string it sends.
- execute_
sql - Build the
sp_executesqlcall for a parameterised statement. - login7
- parse_
prelogin - prelogin
- Build a PRELOGIN payload asking for a particular encryption level.
- rpc
- split_
message - Frame a payload as one or more packets of at most
packet_sizebytes. - sql_
batch - A statement with no parameters, sent as text.