Re: Python and Databases

Discussion in 'Python' started by Bradley D. Larson, Jun 27, 2003.

  1. I'm surprised this hasn't been brought up thus far.... I use it on multiple
    databases and multiple platforms. I can move applications from one platform to
    another without modifications.

    I have found the most practical (and portable) method of accessing databases is
    with the dbi/odbc that comes with python. Not as fast as direct access and it
    requires you to load and set up an ODBC data source for each DB server and Access
    DB but.... the benefits far outweigh the speed issues.

    I have migrated entire applications from one DB to another without with minimal
    code changes. As an application matures or the database grows I move the data to a
    more robust database server.

    I have situations where I am accessing four (4) different data base engines within
    the same program without having to remember the different syntax for each database
    driver... I access all of them in the same manner! That is probably the biggest
    benefit. Less training, fewer bugs, and better understanding across multiple
    developers.

    The following example would work for any of the four databases listed.


    import dbi, odbc

    fs_db = odbc.odbc('MSS-Flex Reports/mylogin/mypasswd') # Proprietary Fourth
    Shift Manufacturing DB

    mysql_db = odbc.odbc('mysql_odbc_db/mylogin/mypasswd') # web server, I don't
    even know the location

    postgres_db = odbc.odbc('postgres_odbc_db/mylogin/mypasswd') # my postgres
    server

    access_db = odbc.odbc('access_odbc_db') # one of our many MS Access databases
    that seem to proliferate.


    cur = postgres_db.cursor()

    sql = "select field1,field2, field3 from mytable where field1 = 'myname';"
    cur.execute(sql)
    list = cur.fetchone()

    if list:
    for f1,f2,f3 in list:
    print f1,f2,f3

    cur.close()
    cur = None

    postgres_db.commit()
    postgres_db.close()
    postgres_db = None




    Geraldo Lopes de souza wrote:

    > Hi,
    >
    > ... you have just one choice: the mxODBC package.
    > It looks like a great package , it worths the price, but with java for
    > example, I get more much more ( in library terms) for less.
    >
    > ... To increase this the python community needs a standard ODBC library in the
    > language.
    >
    > ... I know there is the DB API but we need ODBC.
    > ODBC is the standard way of communicating with databases, if you create a
    > database the first thing you need is an odbc driver to make the existing
    > applications to talk with your database.
    >
    >
    Bradley D. Larson, Jun 27, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken North
    Replies:
    0
    Views:
    588
    Ken North
    Jul 14, 2005
  2. Thomas Weholt

    Re: Any pure-python relational databases?

    Thomas Weholt, Jul 12, 2003, in forum: Python
    Replies:
    1
    Views:
    453
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Jul 13, 2003
  3. Dan Stromberg

    Databases and python

    Dan Stromberg, Feb 16, 2006, in forum: Python
    Replies:
    14
    Views:
    576
    Bryan Olson
    Feb 21, 2006
  4. Sebastian Bassi
    Replies:
    5
    Views:
    412
    John Bokma
    May 29, 2010
  5. Replies:
    1
    Views:
    322
    Nathan Rice
    Nov 10, 2011
Loading...

Share This Page