Skip to content

Design goals

tdslite exists so that small, constrained devices (microcontrollers, IoT nodes) can talk to Microsoft SQL Server directly, without a gateway or a web service in between.

Only pay for what you use

Most SQL Server clients assume a computer with megabytes of memory, threads and a full C++ standard library. An Arduino Uno has 2 kB of RAM and none of that. So tdslite is built around C++'s "zero cost" idea: a feature you don't use costs no flash and no RAM.

That shapes the API:

  • You own the big allocations. The network buffer is yours, sized by you, often a global array. tdslite never grows it.
  • Rows aren't collected. They go to a callback, one at a time, and are gone when it returns. See the memory model.
  • Optional work is opt-in. Column names, for example, aren't stored unless you ask for them.
  • No exceptions, no RTTI. Errors are return values, so tdslite builds with -fno-exceptions -fno-rtti, the default on many embedded toolchains.

No dependencies

tdslite doesn't need the C++ standard library. The few pieces it needs, such as type traits, span and expected, are implemented in the library itself. From the toolchain, it uses a handful of C headers (stdint.h, stddef.h, string.h, stdlib.h). The requirement is a C++11 compiler, nothing more, which is what lets the same code run on an 8-bit AVR and on a 64-bit server.

It's also header-only: there is no library to build and link, and the compiler removes what your program doesn't call.

Not all of TDS

The protocol tdslite speaks, MS-TDS, is decades old and carries many features that small devices never need. tdslite doesn't aim to implement the specification to the letter. It implements what typical embedded use needs (logging in, running queries and parameterized queries, reading result sets, encryption) and adds the rest as it's needed, rather than up front.

That's why, for example, it logs in as a TDS 7.1 client: it's enough for the common data types, and SQL Server converts the newer ones to types a 7.1 client understands. TDS versions and encryption has the details.

Two parts

tdslite is made of two parts, in two folders of the repository:

  • src/tdslite: the protocol. It builds TDS packets and parses responses, and knows nothing about networks.
  • src/tdslite-net: the network backends that carry the packets: Arduino clients, BSD sockets, ESP-IDF's esp-tls, Boost.ASIO.

The main class, tdsl::driver<NetImpl>, joins the two: NetImpl is the backend. The network abstraction explains why they are kept apart.