On 01/26/2012 05:02 PM, osimons wrote:
On Jan 26, 10:25 pm, Chris Nelson<chris.nel...@sixnet.com> wrote:
On Jan 24, 5:15 pm, Chris Nelson<chris.nel...@sixnet.com> wrote:
On 01/24/2012 05:07 PM, osimons wrote:
...
Is there a cleaner way?
Yes, manipulate the string to insert as many %s as there are items in
the users, then add users as args (or extend your existing args with
the users list to be replaced in same order). In Python:
>>> users = ["one", "two", "three"]
>>> sql = "SELECT * FROM table WHERE username in (%s)" %
','.join(('%s',) * len(users))
>>> print sql
'SELECT * FROM table WHERE username in (%s,%s,%s)'
>>> cursor.execute(sql, users)
Great. I got that one working. Now I'm down to a an INSERT with
integers *and* strings:
insert_cursor.execute("INSERT INTO %s " % self.table_name + \
"(ondate, username, availability) " \
"VALUES %s " % \
", ".join(["('%s', '%s', %d)" %
(t[0], t[1], t[2] and
1 or 0,)
for t in inserts]))
I don't think I can just put "%s %s %s" in there; I'm afraid that the DB
API will try to store '1' (not 1). Guess I'll try a couple of things....
--
Christopher Nelson, Software Engineering Manager
SIXNET - Solutions for Your Industrial Networking Challenges
331 Ushers Road, Ballston Lake, NY 12019
Tel: +1.518.877.5173, Fax: +1.518.877.8346 www.sixnet.com
--
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to trac-dev@googlegroups.com.
To unsubscribe from this group, send email to
trac-dev+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en.