[DB-SIG] Examples on how to use mxODBC?

M.-A. Lemburg mal at lemburg.com
Fri Oct 24 03:30:15 EDT 2003


Goldthwaite, Joe wrote:
> Hello again,
> 
> I was using a jgoldtest at bar-s.com email address since that is what is
> configured on my python development machine.  I forgot that bar-s has a
> device that appends an annoying "Property of Bar-S Foods.." message at the
> end of all outgoing email.  To get around it, I had to subscribe to a
> service that allows SSL connections.  What a pain.
> 
> Thanks for the responses from Marc-Andre and Andy Todd.  Between the two of
> you, I got it working.  I've actually done a lot of reading.  I've gone
> through the Marc's links and the mxODBC manual (which I see has your Marc's
> name in the front :)).  I've also got The Python Cookbook, Programming
> Python, Learning Python, Python in a Nutshell, and the Python How To Program
> on-line training course.  With all that, I'm pretty sure I know exactly how
> it's supposed to work.  I know I need to create a connection object with the
> right parameters. I just couldn't seem to come up with a combination that
> works.  I had tried this;
> 
> 	from mx import ODBC
> 	connection = ODBC.Connect("BarsFinRpts")
> 
> And a large number of variations but I couldn't find the object that owns
> the connect method.  Andy Todd provided the last piece;
> 
> 	connection = ODBC.Windows.connect("BarsFinRpts")
> 
> That did it.  I was missing the Windows object between the ODBC and the
> connect().  I knew it was simple.  How are you supposed to find this sort of
> thing?  I've gotten used to Visual Studio where you type object. and get a
> list of the properties and methods.  Does Python have anything similar?

Most Python IDEs do, but Windows in this case is a sub-package of
the mx.ODBC package. It is not easily possible to scan for submodules
or -packages in Python due to the many ways this can be done.

The fact that the above works is due to the LazyModule object
we use in mx.ODBC.__init__. Normally, you'd have to write:

from mx.ODBC.Windows import DriverConnect
conn = DriverConnect('DSN=mydsn;UID=myuid;PWD=mypwd')

to get a connection to the database.

> I've tried using the dir() function to explore the namespace but when I try
> dir('ODBC') I don't see the Windows object listed.  I've also tried the Wing
> IDE but it just seems to show the generic namespace not the specific methods
> of the current object.  It also doesn't seem to have any function help
> available.
> 
> At this point, figuring out HOW to figure out this sort of problem would
> probably be the best help.

The mxODBC documentation talks about subpackages and also gives
an example, but you're right, it's mostly focussed on describing
the details and is missing a tutorial style introduction.

> Thanks again!  I really appreciate the time you guys took to reply.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source  (#1, Oct 24 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::




More information about the DB-SIG mailing list