FreeTDS 和 unixodbc 之间的区别?

Difference between FreeTDS and unixodbc?

我正在尝试弄清楚当连接到 linux.

上的 MS-SQL 服务器时,这两个拼图是如何相互作用和组合在一起的

据我了解,FreeTDS 是与 MS-SQL 对话的协议(即一组规则),它是实际进行对话的东西。 Unixodbc 是一个实现 ODBC API 的驱动程序,即实现了我猜想的一组功能。

为什么两者都是必需的?谁能详细说明我对这两件事实际作用的粗略理解?

unixODBC 是 ODBC 的 'DriverManager'。在 Linux 或 *nix 系统上,您可以使用 unixODBC 连接到任何支持 ODBC 的数据库。这样做意味着您可以编写大量的数据库查询,您应该能够在不同的数据库之间使用这些查询。如果您不在 Unix 上,您将使用不同的驱动程序管理器,例如内置的 MS Office 驱动程序管理器。

为了使所有组件清晰:如果您使用的是一种语言,假设 Python,要连接到 SQL 服务器,您的连接可能来自 Python pyodbc(将 python 对象与 unixODBC 相互转换)到 unixODBC(管理驱动程序,例如 FreeTDS),再到 FreeTDS(将 unixODBC 对象与 Microsoft 支持的 TDS 协议相互转换)到 SQL 服务器.

unixODBC 网站 http://www.unixodbc.org/ 说:

An ODBC application makes ODBC calls to the DriverManager. The DriverManager carries out a number of tasks for the application such as:

  • ensuring the proper driver is loaded/unloaded
  • validation tasks
  • 3.5 to 3.0 to 2.0 call and data mapping

Most calls to the DriverManager get passed onto the loaded Driver to be further processed but that is of little concern to the application.

Some advantages to using an ODBC DriverManager include:

  • portable data access code
  • runtime binding to a Data Source
  • ability to easily change the Data Source

简而言之,是驱动程序管理器读取您的 DSN,查看配置的数据源,并决定连接的位置和方式。

根据您使用的数据库,您将需要不同的驱动程序。这段代码 'translates' 您使用 ODBC 向相关数据库管理系统的正确协议发出的请求。这是对于不同数据源需要不同的组件。在您的情况下,TDS 是 MS SQL Server 使用的协议。 FreeTDS 是该协议的免费软件实现。

另见维基百科https://en.wikipedia.org/wiki/Open_Database_Connectivity(重点保留):

ODBC accomplishes DBMS independence by using an ODBC driver as a translation layer between the application and the DBMS. The application uses ODBC functions through an ODBC driver manager with which it is linked, and the driver passes the query to the DBMS. An ODBC driver can be thought of as analogous to a printer driver or other driver, providing a standard set of functions for the application to use, and implementing DBMS-specific functionality. An application that can use ODBC is referred to as "ODBC-compliant". Any ODBC-compliant application can access any DBMS for which a driver is installed. Drivers exist for all major DBMSs, many other data sources like address book systems and Microsoft Excel, and even for text or CSV files.

FreeTDS 是 TDS 协议的实现,它处理一切,完全能够在没有 unixODBC 的情况下运行。

ODBC 是 FreeTDS 的包装器,提供了比 FreeTDS 的内部 API.

更好的文档记录的通用 API

As FreeTDS.org/faq.html 表示: FreeTDS 提供三个客户端库和一个内部库 (libtds)。我们通常鼓励人们使用其中一个客户端库,而不鼓励编写 libtds,因为后者在不断发展,更容易发生变化,文档较少,而且更难使用。

这两部分都不是必需的,只是有些人更喜欢使用包装器而不是学习新的 API 来做一些与他们在不同的 API 中已经知道的类似的事情。正如 FreeTDS 的常见问题解答所指出的,它们支持除 ODBC 之外的其他开放 API,并且它们的内部库完全能够自行处理所有连接。