Does anyone know which if any db-api 2.0 drivers work with IronPython? If so, has anyone tried using it with SQLAlchemy, SQLObject or the Django ORM?
问题:
回答1:
I know this is a very late answer, but I only saw the question today -- so I am answering it today. http://sourceforge.net/projects/adodbapi contains a fully compliant db-api-2 module which works with IronPython. It is restricted to use in Windows, since it uses classic ADO, using COM calls, rather than ADO.NET. [I tried a true .NET version, but it worked very poorly. The fork for it is still there if anyone wants to follow up.] A fork of this module was adapted for a django extension for MS-SQL. I have pulled those adaptations back in to the main fork. I do not know whether anyone has tried using the result in django, yet, but it should work, provided one explicitly switches the paramstyle to "format".
import adodbapi as Database
Database.paramstyle = 'format'
回答2:
Here's some answers for sqlalchemy:
http://groups.google.com/group/sqlalchemy/browse_thread/thread/ea3ee246680c9d14?pli=1
At the end of the thread, someone tried a beta of IronPython in September last year and it was working.
Also here: SqlAlchemy discussion.
Support for jython, ironpython, others is much more of a drop-in as existing SQL compilation code can be reused.
回答3:
pypyodbc runs under IronPython and it's db-api 2.0 compliant. You can refer to this article to see how to enable SQLAlchemy under IronPython.
回答4:
I have been able to get sqlalchemy working with MSSQL 2008 on ironpython 2.7 by following the steps here (with one change): [https://code.google.com/p/pypyodbc/wiki/Enable_SQLAlchemy_on_IronPython][1]
I had to change the last line below in step 4. removing all except pypyodbc
Step 4: Modify IronPython 2.7\Lib\site-packages\sqlalchemy\dialects\mssql__init__.py, in the top import line, add pypyodbc after mxodbc, like this:
#from sqlalchemy.dialects.mssql import base, pyodbc, adodbapi, \
pymssql, zxjdbc, mxodbc, pypyodbc
from sqlalchemy.dialects.mssql import base, pypyodbc
Now you can use SQLAlchemy with below code:
import sqlalchemy
engine = sqlalchemy.create_engine('mssql+pypyodbc://MSSQL_DSN')
for row in engine.execute('select * from aTable'):
print (row)