Skip to main content

Module protocol

Module protocol 

Source
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 Type byte of the header.
prelogin_option
PRELOGIN option tokens.
status
Status bits from the Status byte of the header.
token
Token identifiers from the response stream.

Structs§

Done
Login7
Everything LOGIN7 carries that is not a constant.
LoginAck
The LOGINACK that says the credentials were accepted.
PacketHeader
The eight bytes in front of every packet.
PreloginResponse
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.
ServerError
An error or an informational message from the server.
TokenStream
Reads a reassembled response message one token at a time.

Enums§

DoneKind
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_executesql call 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_size bytes.
sql_batch
A statement with no parameters, sent as text.