Implementing parsing support for SQL Server data types in OrcaMDF is a simple matter of implementing the ISqlType interface:
IsVariableLength returns whether this data type has a fixed length size or is variable. FixedLength returns the fixed length of the data type, provided that it is fixed length, otherwise it returns null. The data type parser itself does not care about the length of variable length fields, the size of the input bytes will determine that. Finally GetValue parses the input bytes into and converts them into a .NET object of relevant type.
SqlInt implementation
int is very simple as it’s fixed length and is very straight forward to convert using BitConverter:
And the related tests:
SqlNVarchar implementation
nvarchar is very simple as well – note that we return null for the length as the length varies and the ISqlType implementation must be stateless. GetValue simply converts whatever amount of input bytes it gets into the relevant .NET data type, string in this case.
And the relevant test in this case:
Other implementations
OrcaMDF currently supports 12 data types out of the box. I’ll be covering datetime and bit later as those are a tad special compared to the rest of the current types. As the remaining types are implemented, I will be covering those too.
Mark S. Rasmussen
I'm the CTO at iPaper where I cuddle with databases, mold code and maintain the overall technical & team responsibility. I'm an avid speaker at user groups & conferences. I love life, motorcycles, photography and all things technical. Say hi on Twitter, write me an email or look me up on LinkedIn.