[Tutor] sqlite3 place holder problem

Alex Kleider akleider at sonic.net
Fri Oct 4 03:52:52 CEST 2013


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?
(Python 2.7 on Ubuntu )

Thanks in advance.
Alex


More information about the Tutor mailing list