
November 6th, 2006, 08:55 PM
| | | sqlite error?
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 | 
November 6th, 2006, 09:25 PM
| | | Re: sqlite error?
>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) | 
November 6th, 2006, 09:25 PM
| | | Re: sqlite error?
John Salerno wrote: Quote:
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 | 
November 6th, 2006, 09:35 PM
| | | Re: sqlite error? thunderfoot@gmail.com wrote: Quote:
John Salerno wrote: Quote:
>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
>
| Thanks guys. I'll try this. I thought the ? stood for the whole tuple. | 
November 7th, 2006, 05:05 AM
| | | Re: sqlite error?
John Salerno wrote: Quote: Quote: Quote:
Am I using the ? placeholder wrong in this example?
>
>
t = ('hi', 'bye')
>
self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES ?", t)
>
| | | [snip] Quote:
>
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 | 
November 7th, 2006, 02:25 PM
| | | Re: sqlite error?
Frank Millman wrote: Quote:
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! :) |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|