我已经使用SQL了10年但现在我意识到我从未知道客户端如何实际接收和处理从服务器获取的数据。
我的问题是,Microsoft SQL Server的结果实际上是如何以原始格式显示的?与HTTP服务器的结果相同,包含HTTP标头和Content-Type
标头,以告知正文格式(主要是网页的HTML)。
答案 0 :(得分:3)
协议名称是TDS(表格数据流)。
MSDN提供了一些文档
对于简单查询select 'foo' as 'bar'
Packet header (type, legth, etc)
01 01 00 5C 00 00 01 00
Packet data
16 00 00 00 - headers total length
12 00 00 00 - first header length
02 00 - type
00 00 00 00 00 00 00 01 00 00 00 00 - data
0A 00 73 00 65 00 6C 00 65 00 63 00 74 00 20 00
27 00 66 00 6F 00 6F 00 27 00 20 00 61 00 73 00
20 00 27 00 62 00 61 00 72 00 27 00 0A 00 20 00
20 00 20 00 20 00 20 00 20 00 20 00 20 00 - sql
Packet header (type, legth, etc)
04 01 00 33 00 00 01 00
Packet data
columns metadata
81 - record id
01 - count
first column
00 00 00 00 00 - user type
20 00 - flags
A7 - type
03 00 - length
09 04 D0 00 34 - colation
03 - column name length
62 00 61 00 72 00 - column name bytes
rows
D1 - record id
03 00 - length
66 6F 6F - value
ending data
FD - record id
10 00 - status
C1 00
01 00 00 00 00 00 00 00 - rows total
我们也可以通过reference sources查看解析器的实现。