RE: pysqlite2 fetching from select different than pysqlite?

Discussion in 'Python' started by Tim Golden, Jul 27, 2006.

  1. Tim Golden

    Tim Golden Guest

    []

    | I have some old pysqlite 1.x code that uses a pattern like this:
    |
    | cu.execute('SELECT weight FROM weights WHERE samplename="foo")
    | row = cu.fetchone()
    | weight=row['weight']
    |
    | It seems like lookups by name are no longer supported in
    | pysqlite2.

    According to this:

    http://initd.org/pub/software/pysqlite/doc/usage-guide.html#accessing-co
    lumns-by-name-instead-of-by-index

    you have to specify a .row_factory before running the select

    TJG

    ________________________________________________________________________
    This e-mail has been scanned for all viruses by Star. The
    service is powered by MessageLabs. For more information on a proactive
    anti-virus service working around the clock, around the globe, visit:
    http://www.star.net.uk
    ________________________________________________________________________
     
    Tim Golden, Jul 27, 2006
    #1
    1. Advertising

  2. Tim Golden

    Guest

    Thanks Tim! That works well. As a followup, is there a standard
    compliant way to ask what fields are in the table?

    -kurt

    Tim Golden wrote:

    > | I have some old pysqlite 1.x code that uses a pattern like this:
    > |
    > | cu.execute('SELECT weight FROM weights WHERE samplename="foo")
    > | row = cu.fetchone()
    > | weight=row['weight']
    > |


    >
    > http://initd.org/pub/software/pysqlite/doc/usage-guide.html#accessing-co
    > lumns-by-name-instead-of-by-index
    >
    > you have to specify a .row_factory before running the select
    >
    > TJG
     
    , Jul 27, 2006
    #2
    1. Advertising

  3. On 27 Jul 2006 07:00:53 -0700, declaimed the following
    in comp.lang.python:

    > Thanks Tim! That works well. As a followup, is there a standard
    > compliant way to ask what fields are in the table?
    >

    cursor.description -- after an .execute() has selected data.
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Jul 27, 2006
    #3
  4. Tim Golden

    Guest

    Dennis Lee Bieber wrote:

    > cursor.description -- after an .execute() has selected data.


    Thanks Dennis, The desciription works, but gives some funky results,
    but with python it is not a big deal.

    cu.description

    (('activity_id', None, None, None, None, None, None),
    ('case_id', None, None, None, None, None, None),
    ('incident_dt', None, None, None, None, None, None),
    ('activity_type', None, None, None, None, None, None),
    ('vessel_id', None, None, None, None, None, None),
    ('waterway_name', None, None, None, None, None, None),
    ('event_type', None, None, None, None, None, None),
    ('event_class', None, None, None, None, None, None),
    ('event_subclass', None, None, None, None, None, None),
    ('activity_role', None, None, None, None, None, None),
    ('damage_status', None, None, None, None, None, None),
    ('latitude', None, None, None, None, None, None),
    ('longitude', None, None, None, None, None, None))
     
    , Jul 27, 2006
    #4
  5. On 27 Jul 2006 14:04:28 -0700, declaimed the following
    in comp.lang.python:

    >
    > Dennis Lee Bieber wrote:
    >
    > > cursor.description -- after an .execute() has selected data.

    >
    > Thanks Dennis, The desciription works, but gives some funky results,
    > but with python it is not a big deal.
    >

    Read the db-api PEP... It defines that seven pieces of information
    should be returned for each column; two of which are supposed to be
    required, the rest can be "None"... But since SQLite doesn't do data
    typing, even the "required" type field is a "None".

    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Jul 28, 2006
    #5
    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. F. GEIGER
    Replies:
    1
    Views:
    639
    Gerhard Haering
    May 19, 2005
  2. F. GEIGER
    Replies:
    2
    Views:
    541
    F. GEIGER
    May 21, 2005
  3. Replies:
    0
    Views:
    269
  4. Tim Golden
    Replies:
    1
    Views:
    326
  5. Gerhard Häring
    Replies:
    3
    Views:
    381
    Gerhard Häring
    Mar 13, 2008
Loading...

Share This Page