[Tutor] sqlite3 place holder problem

bob gailer bgailer at gmail.com
Fri Oct 4 04:07:24 CEST 2013


On 10/3/2013 9:52 PM, Alex Kleider wrote:
> The following class method
> """
>
>     def insert(self, DataBase=DataBase, Table=Table):
>         """
>         Insert instance of ClassMate into <DataBase> <Table>.
>         """
>         with sqlite3.connect(DataBase) as con:
>             cur = con.cursor()
>             row = \
>             ('NULL', self.first, self.last, self.partner,
>             self.address, self.phone, self.email, )
>             directive = "INSERT INTO %s VALUES ?;" % (Table, )
>             cur.execute(directive, row)
> """
> gives the following error:
>
> """
> Traceback (most recent call last):
>   File "./v_temp.py", line 155, in <module>
>     go_on.insert()
>   File "./v_temp.py", line 70, in insert
>     cur.execute(directive, row)
> sqlite3.OperationalError: near "?": syntax error
> """
> (explanation: 'go_on' is an instance of my class in the __main__)
>
> It was working fine when I was using string formatting but I can't 
> seem to get the syntax right using the qmark method which the 
> documentation suggests is the better way to do it.
>
> Can anyone spot what should be changed?
Try: directive = "INSERT INTO %s VALUES (?,?,?,?,?,?,?);" % (Table, )
> (Python 2.7 on Ubuntu )
>
> Thanks in advance.
> Alex
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list