sqlite error?

J

John Salerno

Am I using the ? placeholder wrong in this example?


t = ('hi', 'bye')

self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES ?", t)



Traceback (most recent call last):
File "C:\Python25\myscripts\labdb\dbapp.py", line 93, in OnSaveRecord
self.save_to_database(textfield_values)
File "C:\Python25\myscripts\labdb\dbapp.py", line 97, in save_to_database
self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES ?", t)
sqlite3.OperationalError: near "?": syntax error
 
B

BartlebyScrivener

self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES ?", t)

John,

I'm no expert, but try

self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES ?, ?", t)
 
T

thunderfoot

John said:
Am I using the ? placeholder wrong in this example?


t = ('hi', 'bye')

self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES ?", t)



Traceback (most recent call last):
File "C:\Python25\myscripts\labdb\dbapp.py", line 93, in OnSaveRecord
self.save_to_database(textfield_values)
File "C:\Python25\myscripts\labdb\dbapp.py", line 97, in save_to_database
self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES ?", t)
sqlite3.OperationalError: near "?": syntax error

I believe you're missing the parens around your VALUES to insert. Also,
you need 1 placeholder per argument inserted, not just one for the
entire argument list. Try:

self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES (?, ?)", t)

HTH
 
J

John Salerno

I believe you're missing the parens around your VALUES to insert. Also,
you need 1 placeholder per argument inserted, not just one for the
entire argument list. Try:

self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES (?, ?)", t)

HTH

Thanks guys. I'll try this. I thought the ? stood for the whole tuple.
 
F

Frank Millman

John said:
[snip]

Thanks guys. I'll try this. I thought the ? stood for the whole tuple.

Definitely not. You could have a sql command like this -

cur.execute("UPDATE table SET col1 = ?, col2 = ? WHERE col3 = ? AND
col4 = ?",(1,2,3,4))

The parameters could be scattered throughout the command. Therefore the
substitution is one-for-one from left to right using the values in the
tuple.

Frank Millman
 
J

John Salerno

Frank said:
Definitely not. You could have a sql command like this -

cur.execute("UPDATE table SET col1 = ?, col2 = ? WHERE col3 = ? AND
col4 = ?",(1,2,3,4))

The parameters could be scattered throughout the command. Therefore the
substitution is one-for-one from left to right using the values in the
tuple.

Thanks! The example I was looking at in the docs didn't use parentheses,
but I also didn't connect that with the fact that it was only using a
one-tuple! :)
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,225
Latest member
Top Crypto Podcasts

Latest Threads

Top