Re: pysqlite2 fetching from select different than pysqlite?
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)) -- http://mail.python.org/mailman/listinfo/python-list
Re: pysqlite2 fetching from select different than pysqlite?
Perfect. Thanks much! -kurt > > from pysqlite2 import dbapi2 as sqlite > > db = sqlite.connect (":memory:") > db.row_factory = sqlite.Row > > db.execute ("CREATE TABLE x (i INTEGER, code VARCHAR (10), name VARCHAR > (60))") > > for row in db.execute ("PRAGMA TABLE_INFO ('x')"): > print row['name'], row['type'] > > -- http://mail.python.org/mailman/listinfo/python-list
RE: pysqlite2 fetching from select different than pysqlite?
[EMAIL PROTECTED] | Sent: 27 July 2006 15:01 | To: python-list@python.org | Subject: Re: pysqlite2 fetching from select different than pysqlite? | | Thanks Tim! That works well. As a followup, is there a standard | compliant way to ask what fields are in the table? | | -kurt Assuming this is what you meant, look at: http://sqlite.org/pragma.html specifically at PRAGMA table_info So, in python: from pysqlite2 import dbapi2 as sqlite db = sqlite.connect (":memory:") db.row_factory = sqlite.Row db.execute ("CREATE TABLE x (i INTEGER, code VARCHAR (10), name VARCHAR (60))") for row in db.execute ("PRAGMA TABLE_INFO ('x')"): print row['name'], row['type'] 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: pysqlite2 fetching from select different than pysqlite?
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 -- http://mail.python.org/mailman/listinfo/python-list
RE: pysqlite2 fetching from select different than pysqlite?
[EMAIL PROTECTED] | 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 -- http://mail.python.org/mailman/listinfo/python-list