From fatuheeva at yahoo.com Thu Feb 7 21:51:56 2008 From: fatuheeva at yahoo.com (Michael Castleton) Date: Thu, 7 Feb 2008 12:51:56 -0800 (PST) Subject: [DB-SIG] execute a query with psycopg2 Message-ID: <15343055.post@talk.nabble.com> Hello, I think I am missing something very simple. The following command works fine if there is no variable substitution: cur2.execute("SELECT date,lat1,lon1 FROM table WHERE eventid = 1001;") but when I try the following I get 'TypeError: unindexable object': events = [1001,1002,1003] for num in events: cur2.execute("SELECT date,lat1,lon1 FROM table WHERE eventid = %s",(num,)) I have tried all manor of variation I can think of - (%s,)(num,) or '%s', num or %(what)s,{what:(num,)} etc.. Any ideas on what I'm doing wrong? Thanks, Mike -- View this message in context: http://www.nabble.com/execute-a-query-with-psycopg2-tp15343055p15343055.html Sent from the Python - db-sig mailing list archive at Nabble.com. From cito at online.de Thu Feb 7 22:51:53 2008 From: cito at online.de (Christoph Zwerschke) Date: Thu, 07 Feb 2008 22:51:53 +0100 Subject: [DB-SIG] execute a query with psycopg2 In-Reply-To: <15343055.post@talk.nabble.com> References: <15343055.post@talk.nabble.com> Message-ID: <47AB7D79.8000406@online.de> Michael Castleton schrieb: > but when I try the following I get 'TypeError: unindexable object': > > events = [1001,1002,1003] > for num in events: > cur2.execute("SELECT date,lat1,lon1 FROM table WHERE eventid = %s",(num,)) > > I have tried all manor of variation I can think of - (%s,)(num,) or '%s', > num or %(what)s,{what:(num,)} etc.. > > Any ideas on what I'm doing wrong? psycopg2 uses paramstyle = pyformat, so %(what)s would be the right syntax. Also, since you are calling execute (not executemany), you must not use a sequence as parameters, but only one dict, like that: cur2.execute("SELECT ... WHERE eventid = %(num)s", dict(num=num)) -- Christoph From mwm at mired.org Thu Feb 7 22:20:16 2008 From: mwm at mired.org (Mike Meyer) Date: Thu, 7 Feb 2008 16:20:16 -0500 Subject: [DB-SIG] execute a query with psycopg2 In-Reply-To: <15343055.post@talk.nabble.com> References: <15343055.post@talk.nabble.com> Message-ID: <20080207162016.01d21bad@mbook-fbsd> On Thu, 7 Feb 2008 12:51:56 -0800 (PST) Michael Castleton wrote: > > Hello, > I think I am missing something very simple. The following command works fine > if there is no variable substitution: > cur2.execute("SELECT date,lat1,lon1 FROM table WHERE eventid = 1001;") > > but when I try the following I get 'TypeError: unindexable object': > > events = [1001,1002,1003] > for num in events: > cur2.execute("SELECT date,lat1,lon1 FROM table WHERE eventid = %s",(num,)) > > I have tried all manor of variation I can think of - (%s,)(num,) or '%s', > num or %(what)s,{what:(num,)} etc.. > > Any ideas on what I'm doing wrong? In generally, not reading http://catb.org/~esr/faqs/smart-questions.html (or maybe not recently). In particular, you're not telling us which version of python you're using, which database (and version) you're using, and which interface module you're using. The correct way to write your query depends on those. http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. From cito at online.de Thu Feb 7 23:49:09 2008 From: cito at online.de (Christoph Zwerschke) Date: Thu, 07 Feb 2008 23:49:09 +0100 Subject: [DB-SIG] execute a query with psycopg2 In-Reply-To: <20080207162016.01d21bad@mbook-fbsd> References: <15343055.post@talk.nabble.com> <20080207162016.01d21bad@mbook-fbsd> Message-ID: <47AB8AE5.5000301@online.de> > In particular, you're not telling us which version of python you're > using, which database (and version) you're using, and which interface > module you're using. The interface and hence the db was mentioned in the subject, but it's a good practice (though not mentioned in smart-questions.html) to repeat these in the body. And yes, version numbers matter if you suspect a bug. Also, here is a better place for asking psycopg specific questions: http://lists.initd.org/mailman/listinfo/psycopg -- Christoph From fatuheeva at yahoo.com Fri Feb 8 02:00:19 2008 From: fatuheeva at yahoo.com (Michael Castleton) Date: Thu, 7 Feb 2008 17:00:19 -0800 (PST) Subject: [DB-SIG] execute a query with psycopg2 In-Reply-To: <47AB7D79.8000406@online.de> References: <15343055.post@talk.nabble.com> <47AB7D79.8000406@online.de> Message-ID: <15347390.post@talk.nabble.com> Michael Castleton schrieb: > but when I try the following I get 'TypeError: unindexable object': > > events = [1001,1002,1003] > for num in events: > cur2.execute("SELECT date,lat1,lon1 FROM table WHERE eventid = %s",(num,)) > > I have tried all manor of variation I can think of - (%s,)(num,) or '%s', > num or %(what)s,{what:(num,)} etc.. > > Any ideas on what I'm doing wrong? psycopg2 uses paramstyle = pyformat, so %(what)s would be the right syntax. Also, since you are calling execute (not executemany), you must not use a sequence as parameters, but only one dict, like that: cur2.execute("SELECT ... WHERE eventid = %(num)s", dict(num=num)) -- Christoph First I apologize for not making my situation perfectly clear. I am running python 2.4, talking to a postgres v8? database with psycopg2. Second, I still don't have a good handle on paramstyle=pyformat but I was able to make the query work using: %(num)s", dict(num=num) Thanks for the help Christoph, Mike -- View this message in context: http://www.nabble.com/execute-a-query-with-psycopg2-tp15343055p15347390.html Sent from the Python - db-sig mailing list archive at Nabble.com. From sable at users.sourceforge.net Tue Feb 12 11:48:30 2008 From: sable at users.sourceforge.net (=?ISO-8859-1?Q?S=E9bastien_Sabl=E9?=) Date: Tue, 12 Feb 2008 11:48:30 +0100 Subject: [DB-SIG] Sybase module 0.39pre1 released Message-ID: <47B1797E.8090200@users.sourceforge.net> WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. ** This version is a pre-release not intended for production use ** The module is available here: http://downloads.sourceforge.net/python-sybase/python-sybase-0.39pre1.tar.gz The module home page is here: http://python-sybase.sourceforge.net/ MAJOR CHANGES SINCE 0.38: * Added type mapping as proposed in http://www.uniqsys.com/~carsten/typemap.html by Carsten Haese * Handle engineer notation of numbers in numeric * Added support for CS_DATE_TYPE * Added support for python Decimal objects in databuf * Possibility to use ct_cursor for some requests * Refactoring - merged Fetchers, CTCursor and CmdCursor in Cursor * Refactored _cancel_cmd * Added a prepare method to Cursor * Additional 'locale' argument to connect and Connection to set the locale of the connection thanks to patch by Harri Pasanen * Better compliance with DBAPI: returns None in nextset when no more set * Added conversion from string to int when assigning to a CS_INT_TYPE DataBuf BUGS CORRECTED SINCE 0.38: * Corrected documentation about CS_CONTEXT Objects thanks to bug report by Derek Harland (close tracker 1748109) * Corrected bug in close() if connection killed from outside thanks to patch by Derek Harland (close tracker 1746220) * Corrected bug if inherit from Sybase.Connection thanks to patch by Derek Harland (close tracker 1719789) * Optimization in fetchall - using fetchmany instead of fetchone to avoid locking time penalty, thanks to patch by Derek Harland (close tracker 1746908) * Corrections to compile with bcp-support against freetds thanks to patch by Klaus-Martin Hansche (close tracker 1724088) * Corrected documentation to compile with FreeTDS and Threads thanks to Derek Harland (close tracker 1709043) * Corrected bug in databuf_alloc: Sybase reports the wrong maxlength for numeric type - verified with Sybase 12.5 - thanks to patch provided by Phil Porter * Better detection of Sybase libraries * the C API to datetime only exists since python 2.4 - disable datetime with previous versions * Corrected python long handling (using CS_NUMERIC instead of CS_LONG which is unspecified) * Corrected various compilation warnings (some linked to python 2.5) The full ChangeLog is here: https://python-sybase.svn.sourceforge.net/svnroot/python-sybase/tags/r0_39pre1/ChangeLog From james at jamesh.id.au Wed Feb 27 05:00:22 2008 From: james at jamesh.id.au (James Henstridge) Date: Wed, 27 Feb 2008 13:00:22 +0900 Subject: [DB-SIG] two phase commit API (again) Message-ID: I dropped the ball a bit on this. I took the last round of feedback and integrated it into a new version of the specification. If people are happy with this, what is the next step? James. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: two-phase-commit-v3.txt Url: http://mail.python.org/pipermail/db-sig/attachments/20080227/541404aa/attachment.txt From mal at egenix.com Wed Feb 27 11:56:33 2008 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 27 Feb 2008 11:56:33 +0100 Subject: [DB-SIG] two phase commit API (again) In-Reply-To: References: Message-ID: <47C541E1.6040301@egenix.com> On 2008-02-27 05:00, James Henstridge wrote: > I dropped the ball a bit on this. > > I took the last round of feedback and integrated it into a new version > of the specification. If people are happy with this, what is the next > step? Looks good. If there are no further issues to discuss, then I'll add it to the DB-API spec as standard extension. Thanks, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 27 2008) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 From fog at initd.org Wed Feb 27 12:27:06 2008 From: fog at initd.org (Federico Di Gregorio) Date: Wed, 27 Feb 2008 12:27:06 +0100 Subject: [DB-SIG] two phase commit API (again) In-Reply-To: References: Message-ID: <1204111626.19735.9.camel@mila.office.dinunzioedigregorio> Il giorno mer, 27/02/2008 alle 13.00 +0900, James Henstridge ha scritto: > I took the last round of feedback and integrated it into a new version > of the specification. If people are happy with this, what is the next > step? Fine for me. -- Federico Di Gregorio http://people.initd.org/fog Debian GNU/Linux Developer fog at debian.org INIT.D Developer fog at initd.org Purtroppo i creazionisti non si sono ancora estinti. -- vodka -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Questa =?ISO-8859-1?Q?=E8?= una parte del messaggio firmata digitalmente Url : http://mail.python.org/pipermail/db-sig/attachments/20080227/2451a406/attachment.pgp