Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 6th, 2006, 08:55 PM
John Salerno
Guest
 
Posts: n/a
Default 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
  #2  
Old November 6th, 2006, 09:25 PM
BartlebyScrivener
Guest
 
Posts: n/a
Default 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)

  #3  
Old November 6th, 2006, 09:25 PM
thunderfoot@gmail.com
Guest
 
Posts: n/a
Default 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

  #4  
Old November 6th, 2006, 09:35 PM
John Salerno
Guest
 
Posts: n/a
Default 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.
  #5  
Old November 7th, 2006, 05:05 AM
Frank Millman
Guest
 
Posts: n/a
Default 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

  #6  
Old November 7th, 2006, 02:25 PM
John Salerno
Guest
 
Posts: n/a
Default 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! :)
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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.
Post your question now . . .
It's fast and it's free

Popular Articles