Triggers on sqlite
Trying to create directory/files tree in sqlite with java, I tried to adapt this article :
http://www.developerfusion.com/article/4633/tree-structures-in-aspnet-and-sql-server/2/
to jdbc and sqlite.
I created this table as the article suggests:
CREATE TABLE IF NOT EXISTS dfTree (id INTEGER,
parentId INTEGER, name VARCHAR(20),
depth INTEGER, lineage VARCHAR(100))
However, when I try to create the following trigger :
CREATE TRIGGER dfTree_InsertTrigger ON dfTree
FOR INSERT AS
UPDATE child
-- set the depth of this "child" to be the
-- depth of the parent, plus one.
SET depth = ISNULL(parent.depth + 1,0),
-- the lineage is simply the lineage of the parent,
-- plus the child's ID (and appropriate '/' characters
lineage = ISNULL(parent.lineage,'/') + LTrim(Str(child.id)) + '/'
-- we can't update the "inserted" table directly,
-- so we find the corresponding child in the
-- "real" table
FROM dfTree child INNER JOIN inserted i ON i.id=child.id
-- now, we attempt to find the parent of this
-- "child" - but it might not exist, so these
-- values may well be NULL
LEFT OUTER JOIN dfTree parent ON child.parentId=parent.id
开发者_如何学运维
I get an sql exception.
Is this trigger not compatible with sqlite?
精彩评论