From: Alastair G. Hogge <agh@tpg.com.au>
To: pgsql-interfaces@postgresql.org
Subject: Problems with my string and pgdb and .execute()
Date: Sun, 17 Aug 2003 19:25:50 +1000
Message-ID: <200308171925.50615.agh@tpg.com.au> (raw)
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()
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: agh@tpg.com.au
Subject: Re: Problems with my string and pgdb and .execute()
In-Reply-To: <200308171925.50615.agh@tpg.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox