On 2013-10-03 18:52, 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?
(Python 2.7 on Ubuntu )
Thanks in advance.
Alex
Sorry to have bothered the list;
I found the problems (there were two!)
Here's the corrected version in case it's of interest to anyone:
"""
def insert(self, DataBase=DataBase, Table=Table):
"""
Insert instance of ClassMate into <DataBase> <Table>.
"""
with lite.connect(DataBase) as con:
cur = con.cursor()
row = \
(self.first, self.last, self.partner,
self.address, self.phone, self.email, )
directive = \
"INSERT INTO %s VALUES (NULL, ?, ?, ?, ?, ?, ?)" \
% (Table, )
cur.execute(directive, row)
"""
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor