BhAT-MAN D
BhAT-MAN D

Reputation: 51

SQLITE 3 How to Insert include a Custom Function inside a trigger clause Python

I'm trying to include a custom function inside a trigger clause in sqlite using python , I'm able to call the custom function when i just call the custom function , however i'm trying to include the custom function inside a trigger clause

This is my custom function creation

 self.conn.create_function("autocsvok", 1, self.syslog_autocsv)

This is my callback python function

def syslog_autocsv(self,value):
    print value

I'm able to call the callback function on

   sql2='select autocsvok("ss")'
   self.cur.execute(sql2)

This gives me output

   ss

However , Now I try to include the custom function inside a trigger clause

sql3='''CREATE TRIGGER liiasssaa BEFORE INSERT ON syslog BEGIN
            select autocsvok("55") 
            END'''
self.cur.execute(sql3)
print self.cur.fetchone()[0]

This gives me the following error

File "syslog.py", line 105, in syslog_createfunction
self.cur.execute(sql1)
sqlite3.OperationalError: near "END": syntax error

Kindly Help me :)

Upvotes: 3

Views: 992

Answers (1)

mobiusklein
mobiusklein

Reputation: 1423

See the section of grammar between BEGIN and END https://www.sqlite.org/lang_createtrigger.html

The expression must be terminated with a semicolon. Your trigger's select is not terminated by a semicolon.

Upvotes: 3

Related Questions