以下是我的SQLite查询
rem
当我从Python代码执行此查询时,它给出了以下错误
sql = '''CREATE TRIGGER autodelete AFTER INSERT ON syslog
WHEN (SELECT COUNT(*) FROM syslog) > '''+self.size_limit+'''
BEGIN
DELETE from syslog where time < ( select time from syslog limit -1 offset '''+str(self.co)+''');
INSERT INTO syslog (time,loglevel,logcode,logmessage) values
('''+datetime.now()+''',"Information","I1800","message");
END'''
发现
但是当我执行插入查询
时Coercing to Unicode: need string or buffer, **datetime.datetime**
这适用于self.cur.execute('INSERT INTO syslog (time, loglevel, logcode, logmessage) values (?, ?, ?, ?)', (datetime.now(), loglevel, logcode, logmessage))
,
但是当我执行触发器SQL时会出现datetime问题,它会显示
datetime.now()
为什么它只发生在第一个查询中,现在发生在第二个查询中(插入查询)
我还尝试了Unicode: need string or buffer, datetime.datetime found
和unicode(datetime.now())
但他们都没有工作。