Problems with psycopg2
c james
cjames at callone.net
Mon May 5 08:31:35 EDT 2008
David Anderson wrote:
> The thing is this query works fine on the console through psql, but not
> in my code? can anyone explain me why?
>
> On Thu, May 1, 2008 at 9:31 PM, David Anderson <zerty.david at gmail.com
> <mailto:zerty.david at gmail.com>> wrote:
>
> Hi all
> I have this function:
> def checkName(self, name):
> cur = self.conn.cursor()
>
> sql = "SELECT * from patient WHERE fn_pat = '" + name + "'"
> cur.execute(sql)
> rows = cur.fetchall()
>
> if rows == "[]":
> self.insert()
>
> It seems to work fine, But I'm getting this exception:
> psycopg2.ProgrammingError: current transaction is aborted, commands
> ignored until end of transaction block
> at: cur.execute(sql)
>
> What's the problem?
> thx
>
> ps: fn_pat is the column of the db, name is the string passed in the
> function parameter
>
>
>
> ------------------------------------------------------------------------
>
> --
> http://mail.python.org/mailman/listinfo/python-list
Does `name` happen to have an apostrophe in it? You may want to look at
using bind variables.
cur.execute("SELECT * from patient WHERE fn_pat=%(name)s",
{'name': name})
http://wiki.python.org/moin/DbApiCheatSheet
http://mail.python.org/pipermail/python-list/2005-March/314154.html
More information about the Python-list
mailing list