Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: pysqlite2 fetching from select different than pysqlite?

Reply
Thread Tools

RE: pysqlite2 fetching from select different than pysqlite?

 
 
Tim Golden
Guest
Posts: n/a
 
      07-27-2006
[]

| 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/pysqli...l#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
__________________________________________________ ______________________
 
Reply With Quote
 
 
 
 
schwehr@gmail.com
Guest
Posts: n/a
 
      07-27-2006
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/pysqli...l#accessing-co
> lumns-by-name-instead-of-by-index
>
> you have to specify a .row_factory before running the select
>
> TJG


 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      07-27-2006
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: web-)
HTTP://www.bestiaria.com/
 
Reply With Quote
 
schwehr@gmail.com
Guest
Posts: n/a
 
      07-27-2006

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))

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      07-28-2006
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: web-)
HTTP://www.bestiaria.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: pysqlite2 fetching from select different than pysqlite? Tim Golden Python 1 07-27-2006 02:44 PM
pysqlite2 fetching from select different than pysqlite? schwehr@gmail.com Python 0 07-27-2006 12:05 PM
pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are -1 supplied. F. GEIGER Python 3 05-18-2005 03:46 PM
Include pysqlite2 into Python 2.5? Gerhard Haering Python 11 10-24-2004 01:28 AM
Re: Include pysqlite2 into Python 2.5? Simon Brunning Python 4 10-22-2004 09:29 AM



Advertisments