简体   繁体   中英

pyodbc vs ADO via COM for Python scripts

For many years, my company has used the win32com module and ADO to connect to databases via ODBC in Python scripts. I do not like ADO because it is ancient and because COM is inherently slow and because it tends to throw one particular exception for which there is no workaround I've ever found. We use ODBC because we cannot assume that our customers have any particular database system (although most of them use PostgreSQL). We have a class that wraps ADO and provides access to most (maybe all) of the functionality in ADO. I am at a point where I could recommend a complete changeover to pyodbc. Before I do that, I'm curious: are there advantages to ADO via win32com? Does it have more capability than pyodbc?

are there advantages to ADO via win32com? Does it have more capability than pyodbc?

Practically speaking, and specifically with regard to ODBC, not really. ADODB would have the advantage of being able to use an OLEDB provider for a database that had an OLEDB provider but not an ODBC driver, but that would be a rare occurrence. (The only such database I can recall is "SQL Server Compact Edition", which was discontinued long ago.)

As mentioned in the comments to the question, pyodbc would have the advantage of avoiding extra layers of middleware when communicating with the database, ie,

your Python app ↔ pyodbc ↔ ODBC Driver Manager ↔ ODBC Driver ↔ database

vs.

your Python app ↔ win32com ↔ ADODB ↔ OLEDB provider for ODBC ↔ ODBC Driver Manager ↔ ODBC Driver ↔ database

As also mentioned, win32com/ADODB is a Windows-only technology, whereas a pyodbc solution could also be deployed on Linux or Mac if the appropriate ODBC drivers were available for those platforms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM