stupid Python/database connection

Dennis Lee Bieber wlfraed at ix.netcom.com
Mon Nov 25 14:45:25 EST 2002


animeshk fed this fish to the penguins on Monday 25 November 2002 09:18 
am:

> This is a really stupid question, I know.
> 
> I am trying to write an app that might connect to an Interbase
> database or an Oracle database, depending on a configuration file.
> 
> I have seen some Python code for interfacing with a database, and it
> seems to depend on the import statement.  import some-lib-or-another
> to access one kind of database, import some-other-lib-or-another to
> access another kind of database.  After the import, it's a matter of
> calling that database type's "connect" statement.
> 
> So . . . how can the decision of what-database-to-use be defferred to
> runtime?  When writing, say, a BDE app in Delphi, it would be a simple
> matter of what alias to use.  How is this done in Python?
>
        Well, if possible, you could require an ODBC data source to be created 
for either database, and just use the generic Python ODBC module.

        Or (untested -- and you have to restrict your usage to the common 
elements):

#read config

if dbtype == "Oracle":
        import OracleSpecificDBModule
        myDB = OracleSpecificDBModule
elif dbtype == "Interbase":
        import InterbaseSpecificDBModule
        myDB = InterbaseSpecificDBModule


myCon = myDB.connect(...)
 
> Thanks!

-- 
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




More information about the Python-list mailing list