Generic ODBC connection (4D anyone?)

257 views
Skip to first unread message

James

unread,
Feb 19, 2010, 2:17:23 PM2/19/10
to sqlalchemy
Anyone heard of 4D? Probably not, but I would love to work with
SQLAlchemy and this database.

How hard is it to write a new dialect?

Anyone had luck using generic odbc (ie not mysql moduled to pyodbc) to
connect to various "unsupported" databases?

I've tried a couple connection strings, the biggest problem is 4D
doesn't have a "database" name.

# connect to the actual database
from sqlalchemy import create_engine
#using DSN
engine = create_engine('mysql+pyodbc://4D_v11_Dev/DEFAULT_SCHEMA')
#using URL
engine = create_engine('mysql://user:pa...@127.0.0.1', module='pyodbc')
#another dialect with DSN => ERROR: AttributeError: 'str' object has
no attribute 'paramstyle'
engine = create_engine('mssql://4D_v11_Dev', module='pyodbc')
# yet another try
engine = create_engine('mysql+pyodbc://4D_v11_Dev')
# show me output
engine.echo = True

None of those work, I have some stack traces, but the gist is this:
# when used without a database name
sqlalchemy.exc.DBAPIError: (Error) ('08004', '[08004] Server rejected
the connection:\nFailed to parse statement.\r (1301)
(SQLExecDirectW)') 'SELECT DATABASE()' ()

# when I try to specify a name
sqlalchemy.exc.DBAPIError: (Error) ('00000', '[00000] [iODBC][Driver
Manager]dlopen({MySQL}, 6): image not found (0) (SQLDriverConnectW)')
None None

But connection directly via pyodbc does work
import pyodbc
cnxn = pyodbc.connect("DSN=4D_v11_Dev;UID=user;PWD=pass")
cursor = cnxn.cursor()
cursor.execute('select * from ODBCTest')
a=cursor.fetchall()
print 'pyodbc',a

Michael Bayer

unread,
Feb 19, 2010, 2:47:56 PM2/19/10
to sqlal...@googlegroups.com

On Feb 19, 2010, at 2:17 PM, James wrote:

> Anyone heard of 4D? Probably not, but I would love to work with
> SQLAlchemy and this database.
>
> How hard is it to write a new dialect?

by all reports, including some new ones gained today at pycon, it is extremely easy. provided your database is relational.

>
> Anyone had luck using generic odbc (ie not mysql moduled to pyodbc) to
> connect to various "unsupported" databases?

step 1, get pyodbc to connect to your database. that may be easy or may involve contacting the pyodbc author for fixes.

step 2, create a .py file that imports the PyODBC connector as a mixin to "class YourDialect()", the same way as any other dialect, and make any changes to the "create_connect_args" method as necessary in your subclass.

step 3, establish a setup.py for your application which establishes your library as a setuptools entrypoint for "sqlalchemy.dialects". the name you give it is what you'd call upon in create_engine(). I'd suggest a name like "4d+pyodbc".

> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>

Prachi Jain

unread,
Sep 13, 2021, 2:31:35 PM9/13/21
to sqlalchemy
Hi,

I am wondering if you were able to write the 4D dialect? I am in a similar predicament and will appreciate if you can help me in any way to write a dialect for 4D.

Thanks,
Prachi
Reply all
Reply to author
Forward
0 new messages