Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > sqlite error?

Reply
Thread Tools

sqlite error?

 
 
John Salerno
Guest
Posts: n/a
 
      11-06-2006
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
 
Reply With Quote
 
 
 
 
BartlebyScrivener
Guest
Posts: n/a
 
      11-06-2006
>> 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)

 
Reply With Quote
 
 
 
 
thunderfoot@gmail.com
Guest
Posts: n/a
 
      11-06-2006

John Salerno wrote:
> 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

 
Reply With Quote
 
John Salerno
Guest
Posts: n/a
 
      11-06-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> John Salerno wrote:
>> 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.
 
Reply With Quote
 
Frank Millman
Guest
Posts: n/a
 
      11-07-2006

John Salerno wrote:
> >> Am I using the ? placeholder wrong in this example?
> >>
> >>
> >> t = ('hi', 'bye')
> >>
> >> self.connection.execute("INSERT INTO Personal (firstName, lastName)
> >> VALUES ?", t)
> >>

[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

 
Reply With Quote
 
John Salerno
Guest
Posts: n/a
 
      11-07-2006
Frank Millman wrote:

> 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!
 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ruby sqlite/gem error: Could not load sqlite adapter jhs408@gmail.com Ruby 4 04-18-2009 12:53 AM
Installing sqlite-ruby when sqlite is in non-standard location Carl Youngblood Ruby 1 04-09-2005 03:32 AM
SQLite or other "DB in a file" for Java? Andrew Fabbro Java 2 06-19-2004 06:11 PM
Sqlite rj Java 0 08-16-2003 10:59 PM
Re: Java JDBC to SQLite =?ISO-8859-1?Q?Andree_Gro=DFe?= Java 0 08-15-2003 12:57 PM



Advertisments