IronPython db-api 2.0

十年热恋 提交于 2019-12-06 05:17:39

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'

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.

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.

Testautomation

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