denisenkom / pytds

Python DBAPI driver for MSSQL using pure Python TDS (Tabular Data Stream) protocol implementation
MIT License
192 stars 53 forks source link

Parse UDT_INFO structs in TYPE_INFO (Fixes #65) #67

Closed josePhoenix closed 7 years ago

josePhoenix commented 7 years ago

The type ID 240 is reserved for CLR types. (UDTTYPE = SYBMSUDT = 240) The UDT_INFO_IN_COLMETADATA layout is described in [MS-TDS] Section 2.2.5.5.2: "Common Language Runtime (CLR) Instances". The contents of the column are specified in [MS-SSCLRT].

This PR makes no attempt to parse the bytes within the column, beyond interpreting them as partially-length-prefixed with the existing PlpReader class.

josePhoenix commented 7 years ago

This might need some more methods to enable round-trip of the binary blobs... perhaps inspired by VarBinarySerializerMax's write* methods?

class VarBinarySerializerMax(VarBinarySerializer):
# [ ... ]
    def write_info(self, w):
        w.put_usmallint(tds_base.PLP_MARKER)

    def write(self, w, val):
        if val is None:
            w.put_uint8(tds_base.PLP_NULL)
        else:
            w.put_uint8(len(val))
            if val:
                w.put_uint(len(val))
                w.write(val)
            w.put_uint(0)
# [ ... ]
denisenkom commented 7 years ago

Looks good to me, merging. Maybe you can add some tests for it?

josePhoenix commented 7 years ago

I'll have a look at the existing tests, but I'm not sure if I'll be able to craft a good test case. I have read-only access to this database I'm using, which is bad for experimenting

josePhoenix commented 7 years ago

Actually, if you could give me some pointers as to where in the test code I should look and what I should attempt to test, that would help. I see some tests with byte strings and fake sockets, which I could try to replicate with my wireshark capture of the UDT info.