mercredi 15 avril 2015

Syntax error in creating trigger in sqlite

The following code causes a syntax error in SQLite. I imagine this must be simple but I can't see it.


I have two tables, pages and items, linked through a text code. When this code in changed in pages table, I want it changed in items table too.


The SQLite version is quite old, 3.7.7.1, but I haven't seen such a problem in version history. This occurs on Windows, with PHP 5.3.1.



CREATE TABLE IF NOT EXISTS "efpage" ( "pageid" integer NOT NULL PRIMARY KEY, "psite" text NULL, "pgcode" text NULL );
CREATE TABLE IF NOT EXISTS "efitem" ( "itemid" integer NULL PRIMARY KEY , "isite" text NULL, "ititle" text NULL, "inpage" text NULL);

DROP TRIGGER IF EXISTS update_pagecode;
CREATE TRIGGER update_pagecode AFTER UPDATE OF pgcode ON efpage
BEGIN
UPDATE efitem SET inpage = new.pgcode WHERE inpage = old.pgcode;
END;


The resulting error is ERROR near "pgcode": syntax error.


Trying different things, I saw that the syntax error is after "old.pgcode;"


Aucun commentaire:

Enregistrer un commentaire