Is there any pywin32 odbc connector documentation available?

强颜欢笑 提交于 2020-01-03 04:01:53

问题


What is a good pywin32 odbc connector documentation and tutorial on the web?


回答1:


The only 'documentation' that I found was a unit test that was installed with the pywin32 package. It seems to give an overview of the general functionality. I found it here:

python dir\Lib\site-packages\win32\test\test_odbc.py

I should also point out that I believe it is implements the Python Database API Specification v1.0, which is documented here:

http://www.python.org/dev/peps/pep-0248/

Note that there is also V2.0 of this specification (see PEP-2049)

On a side note, I've been trying to use pywin32 odbc, but I've had problems with intermittent crashing with the ODBC driver I'm using. I've recently moved to pyodbc and my issues were resolved.




回答2:


Alternatives:

  • mxODBC by egenix.com (if you need ODBC)
  • pyODBC
  • sqlalchemy and DB-API 2.0 modules (which isn't ODBC) but it's maybe better alternative



回答3:


The answer is: 'there isn't one'. However, here is an example that shows how to open a connection and issue a query, and how to get column metadata from the result set. The DB API 2.0 specification can be found in PEP 249.

import dbi, odbc

SQL2005_CS=TEMPLATE="""\
Driver={SQL Native Client};
Server=%(sql_server)s;
Database=%(sql_db)s;
Trusted_Connection=yes;
"""

CONN_PARAMS = {'sql_server': 'foo',
               'sql_db': 'bar'}

query = "select foo from bar"

db = odbc.odbc(SQL2005_CS_TEMPLATE % CONN_PARAMS)
c = db.cursor()
c.execute (query)
rs = c.fetchall()  # see also fetchone() and fetchmany()
# looping over the results
for r in rs:
    print r

#print the name of column 0 of the result set
print c.description[0][0]

#print the type, length, precision etc of column 1.
print c.description[1][1:5]

db.close()


来源:https://stackoverflow.com/questions/768250/is-there-any-pywin32-odbc-connector-documentation-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!