Skip to content

Data types

Reading columns

Read a field with row[i].as<T>(). For integer and floating point types, T must have the same size as the column: a narrower column, or a NULL, reads as zero. row[i].is_null() tells a NULL from a zero or an empty value.

SQL type Read as
bit as<bool>()
tinyint as<tdsl::uint8_t>()
smallint as<tdsl::int16_t>()
int as<tdsl::int32_t>()
bigint as<tdsl::int64_t>()
real as<float>()
float as<double>(), on platforms where double is 8 bytes
char, varchar, text as<tdsl::char_view>(): not null-terminated, use data() and size()
nchar, nvarchar, ntext as<tdsl::u16le_view>(): UTF-16 code units
money, smallmoney as<tdsl::sql_money>(), with integer(), fraction() (four decimal digits) and raw()
binary, varbinary, image, uniqueidentifier, timestamp the field itself: a view of the raw bytes (data(), size_bytes())
sql_variant not supported: the query reports response_error

Views point into the network buffer and are valid until the row callback returns.

Types SQL Server converts

tdslite logs in as a TDS 7.1 client, so SQL Server converts the types that came after TDS 7.1 before sending them:

Column type Arrives as Read as
date, time, datetime2, datetimeoffset nvarchar, e.g. 2020-01-02 03:04:05.0000000 as<tdsl::u16le_view>()
varchar(max) text as<tdsl::char_view>()
nvarchar(max), xml ntext as<tdsl::u16le_view>()
varbinary(max) image the field itself

Query parameters

execute_rpc accepts these parameter types:

SQL type Parameter type Constructed from
bit tdsl::sql_parameter_bit bool
tinyint tdsl::sql_parameter_tinyint tdsl::uint8_t
smallint tdsl::sql_parameter_smallint tdsl::int16_t
int tdsl::sql_parameter_int tdsl::int32_t
bigint tdsl::sql_parameter_bigint tdsl::int64_t
real tdsl::sql_parameter_float4 float
char, varchar tdsl::sql_parameter_char, tdsl::sql_parameter_varchar tdsl::string_view
nchar, nvarchar tdsl::sql_parameter_nchar, tdsl::sql_parameter_nvarchar tdsl::wstring_view
binary, varbinary tdsl::sql_parameter_binary, tdsl::sql_parameter_varbinary tdsl::byte_view
uniqueidentifier tdsl::sql_parameter_guid tdsl::byte_view (16 bytes)

float (8 bytes), decimal, numeric, money and the date and time types can't be bound as parameters yet, and neither can NULL.