Brian Jones
2010-01-26 14:13:21 UTC
Hi all,
So, again, I'm trying to do a simple execute(), and I'm running into
really unexpected errors. I have, of course, tried perhaps 5 different
ways of putting the query together by now, and the error has not
changed.
Here's what I *currently* have in place in my code:
sql = """INSERT INTO urls VALUES (%d, %d, %s, %s)"""
params = [int(self.user_id), int(self.site_id), self.url_type
, self.url]
self.cursor.execute(sql,params)
Of course, that's after trying simpler forms of the same thing.
Namely, when I started this was all one line of code, and I didn't do
explicit casts.
self.cursor.execute("""INSERT INTO urls VALUES (%d, %d, %s, %s)""" %
(self.user_id, self.site_id, self.url_type , self.url))
The error I'm getting is:
TypeError: %d format: a number is required, not str
Explicit casting to int does not make this go away. Also, I tested by
printing out "type(i) for i in params", and it prints out the types
that I expect things to be, and the types I think I'm passing to the
query, in the proper order.
Does anyone see anything obvious that I might have goofed up?
Thanks,
brian
So, again, I'm trying to do a simple execute(), and I'm running into
really unexpected errors. I have, of course, tried perhaps 5 different
ways of putting the query together by now, and the error has not
changed.
Here's what I *currently* have in place in my code:
sql = """INSERT INTO urls VALUES (%d, %d, %s, %s)"""
params = [int(self.user_id), int(self.site_id), self.url_type
, self.url]
self.cursor.execute(sql,params)
Of course, that's after trying simpler forms of the same thing.
Namely, when I started this was all one line of code, and I didn't do
explicit casts.
self.cursor.execute("""INSERT INTO urls VALUES (%d, %d, %s, %s)""" %
(self.user_id, self.site_id, self.url_type , self.url))
The error I'm getting is:
TypeError: %d format: a number is required, not str
Explicit casting to int does not make this go away. Also, I tested by
printing out "type(i) for i in params", and it prints out the types
that I expect things to be, and the types I think I'm passing to the
query, in the proper order.
Does anyone see anything obvious that I might have goofed up?
Thanks,
brian
--
Brian K. Jones
Python Magazine http://www.pythonmagazine.com
My Blog http://www.protocolostomy.com
Brian K. Jones
Python Magazine http://www.pythonmagazine.com
My Blog http://www.protocolostomy.com