Support multiple TDB versions in SQL building