Problems with my string and pgdb and .execute()

From: "Alastair G(dot) Hogge" <agh(at)tpg(dot)com(dot)au>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Problems with my string and pgdb and .execute()
Date: 2003-08-17 09:25:50
Message-ID: 200308171925.50615.agh@tpg.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hello all,

I'm trying desperately to get my code working.

I use Python to retrieve information from a HTML form (CGI). I then want to
store this info in my PostgreSQL database. So first I get the info in the
form keys and concate them to a string.

As I understand it, the .execute funtion of pgdb likes the format
('one','two') so I make a string to represent that. But when I try to store
the info I get the following from the cur.execute("INSERT INTO house VALUES
(%s)" % (final_qu)) line in my code.
TypeError: not all arguments converted during string formatting,

So my code:
#!/usr/local/bin/python

import cgi
import time
import pgdb

# Begin
form = cgi.FieldStorage() # Grab the data from web page form

qu = str("")
for name in form.keys():
qu += "'" + str((form[name].value)) + "',"

# At this stage qu would be something like "('one','hello','test','1232')
tail = "'" + str(time.strftime("%Y-%m-%d")) + "','" +
str(time.strftime("%H:%M:%S")) + "'"
final_qu = SeAnRe.Action("'Submit',", tail, qu)

db = pgdb.connect(dsn=_dbsource, user=_dbuser, database=_dbname)
cur = db.cursor()
cur.execute("INSERT INTO house VALUES (%s)" % (final_qu))
db.commit()
cur.close()
db.close()

Browse pgsql-interfaces by date

  From Date Subject
Next Message Peter.Rupp 2003-08-18 14:44:11 Help with retrieving large results sets and memory usage.
Previous Message Tilo Schwarz 2003-08-14 21:55:12 ECPG Problem (Bug?)