[2.5.1] Converting string to int?

G

Gilles Ganault

Hello

I'm using the APSW wrapper to SQLite, and I'm stuck at how to pass
data from a dictionary to the database which expects an integer:

#array filled by reading a two-column text file as input
for (isbn,carton) in data.items():
#TypeError: int argument required
sql = "INSERT INTO books (isbn,carton) VALUES ('%s',%u)" %
(isbn,carton)

#Incorrect number of bindings supplied. The current statement uses
0 and there are 2 supplied. Current offset is 0
sql = "INSERT INTO books (isbn,carton) VALUES ('%s',%u)" %
(isbn,int(carton))

cursor.execute(sql,(isbn,carton))
==========

What is the right way to turn items from a dictionary into an integer
so as to match the column definition in the database?

Thank you.
 
G

Gilles Ganault

I'm using the APSW wrapper to SQLite, and I'm stuck at how to pass
data from a dictionary to the database which expects an integer:

Found it: Apparently, this wrapper uses a different placeholder and
takes care of conversion if needed:

cursor.execute("INSERT INTO books (isbn,carton) VALUES (?,?)",
(isbn,carton))

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top