Marco Bambini wrote:
> From the official documentation:
> You cannot DELETE, INSERT, or UPDATE a view. Views are read-only in SQLite.
> However, in many cases you can use an INSTEAD OF trigger on the view to 
> accomplish the same thing.
>
> Can someone clarifies this point?
> Seems like it is possible to write into a view but I do not understand what 
> if the correct way to perform the operation.

The trigger must change the view's base table(s) appropriately:

sqlite> CREATE TABLE pets(name, owner);
sqlite> CREATE VIEW my_pets AS SELECT name FROM pets WHERE owner='me';
sqlite> INSERT INTO my_pets VALUES('Fluffy');
Error: cannot modify my_pets because it is a view
sqlite> CREATE TRIGGER my_pets_insert
        INSTEAD OF INSERT ON my_pets
        BEGIN
          INSERT INTO pets(name, owner) VALUES(NEW.name, 'me');
        END;
sqlite> INSERT INTO my_pets VALUES('Fluffy');
sqlite> SELECT * FROM my_pets;
Fluffy


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to