0

I have below piece of code to run a user defined function which will take up a variable created at triggering the trigger.

As there is no option to create a variable i used following technique(Declare variable in sqlite and use it) to create a variable and pass it on to my function.

But i get below error

Traceback (most recent call last):
  File "C:\sqlite\DBTesting2.py", line 18, in <module>
    END;""")
OperationalError: near "PRAGMA": syntax error

Following is my code for the trigger

cur.execute("""CREATE TRIGGER simpleTrigger1
                AFTER INSERT ON summary
                BEGIN
                    PRAGMA temp_store = 2;
                    CREATE TEMP TABLE _Variables(variablename, value);
                    INSERT INTO _Variables (variablename) VALUES ('data');
                    UPDATE _Variables SET value=cu.fetchone() WHERE variablename='data';
                    SELECT hellofunc(value) FROM _Variables WHERE variablename='data';
                    DROP TABLE _Variables;
                END;""")

Please help me with this. Is there anything I am missing?

Thanks in advance.

Shoaib Mohammed
  • 986
  • 2
  • 9
  • 17
  • 1
    See the [documentation](http://www.sqlite.org/lang_createtrigger.html). – CL. Jul 15 '17 at 13:36
  • I am new to SQLite, When creating a trigger after BEGIN keyword can I only use SELECT statement? Because when I try with any other keyword it's throwing me an error saying syntax error. But for SELECT it works fine. for example the below code works fine for me – Shoaib Mohammed Jul 15 '17 at 15:11
  • CREATE TRIGGER simpleTrigger29 AFTER INSERT ON summary BEGIN SELECT hellofunc(); END; – Shoaib Mohammed Jul 15 '17 at 15:12
  • The documentation is quite clear about which statements are allowed in a trigger body. – CL. Jul 15 '17 at 16:16

0 Answers0