odbc and accessing database results by field

Discussion in 'Python' started by JZ, Oct 28, 2003.

  1. JZ

    JZ Guest

    import odbc
    conn = odbc.odbc('mydsn')
    c = conn.cursor()
    c.execute('SELECT TOP 10 field1, field2 FROM TABLE')
    rows = c.fetchall()
    c.close()
    conn.close()

    I am using MSSQL2000. My problem is:
    Instead of row[0], rows[1]
    I would like to use row['field1], row['field']
    Is it possible for odbc module?
    I cannot find any comprehensive documentation :(

    --
    JZ ICQ:6712522
    JZ, Oct 28, 2003
    #1
    1. Advertising

  2. "JZ" <> wrote in message
    news:...
    > import odbc
    > conn = odbc.odbc('mydsn')
    > c = conn.cursor()
    > c.execute('SELECT TOP 10 field1, field2 FROM TABLE')
    > rows = c.fetchall()
    > c.close()
    > conn.close()
    >
    > I am using MSSQL2000. My problem is:
    > Instead of row[0], rows[1]
    > I would like to use row['field1], row['field']
    > Is it possible for odbc module?
    > I cannot find any comprehensive documentation :(


    Well, I've been using oledb, but it should be fairly similar.

    I just wrote a small wrapper class for the ADODB.Recordset object, that when
    its Open() method is called, (as well as MoveNext, MovePrev, etc.) it copies
    the current field names and their values into self.__dict__, so I can access
    them via r.Field1, r.Field2, etc.

    Another route I've gone (since OS/400 allows field names like TEST#REC@,
    which python pukes on, is to over-ride __call__ to handle field data. (i.e.
    c('test') = somevalue, etc.).

    Anyways, a couple of ideas.
    George Kinney, Oct 29, 2003
    #2
    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. Monique Y. Mudama
    Replies:
    1
    Views:
    443
    Monique Y. Mudama
    Jun 28, 2005
  2. lovecreatesbeauty
    Replies:
    8
    Views:
    1,630
    Old Wolf
    Sep 12, 2005
  3. Wes Gamble
    Replies:
    1
    Views:
    153
    Gerardo Santana Gómez Garrido
    Apr 5, 2006
  4. Sound
    Replies:
    2
    Views:
    430
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    408
Loading...

Share This Page