diff --git a/manifest b/manifest index 1ac8dc61d7..7147949eb3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sMakefile.in\sthat\swas\sforgotten\swith\scheckin\s#562\s(CVS\s563) -D 2002-05-15T08:43:10 +C In\sthe\s"lang.html"\sdocumentation\sfile,\sput\sthe\sCREATE\sTRIGGER\sand\sDROP\sTRIGGER\nsections\sin\salphabetical\sorder.\s(CVS\s564) +D 2002-05-15T11:43:16 F Makefile.in 6291a33b87d2a395aafd7646ee1ed562c6f2c28c F Makefile.template 89e373b2dad0321df00400fa968dc14b61a03296 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0 @@ -127,14 +127,14 @@ F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c F www/faq.tcl 45bdb18b75ac3aa1befec42985fb892413aac0bb F www/formatchng.tcl 2ce21ff30663fad6618198fe747ce675df577590 F www/index.tcl d0c52fbf031d0a3ee6d9d77aa669d5a4b24b6130 -F www/lang.tcl a22cf9eff51e65ec5aa39b1efb5b7952d800ac06 +F www/lang.tcl be7a241fe3dbb145ff25fe951c3d8ad16b543a1f F www/mingw.tcl f1c7c0a7f53387dd9bb4f8c7e8571b7561510ebc F www/opcode.tcl bdec8ef9f100dbd87bbef8976c54b88e43fd8ccc F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 -P 794bf67b6b36fce8854d5daff12f21dbb943240c -R 08d6d280437ddbf6c3512d0683d6a10e -U danielk1977 -Z 654e041ad87e42741720cd7b74aa49a7 +P 29b8330ca6bfe32c499a045189683100f2b15246 +R a27803f7b286e7959f11eb8469f192e0 +U drh +Z a84814eb63e1343d44fc3775f1b09115 diff --git a/manifest.uuid b/manifest.uuid index 437b294a49..3e72d400eb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -29b8330ca6bfe32c499a045189683100f2b15246 \ No newline at end of file +d1d8642b57bd0765ade730248012d58b0859c12c \ No newline at end of file diff --git a/www/lang.tcl b/www/lang.tcl index 83b4a56dcf..a99d387ae4 100644 --- a/www/lang.tcl +++ b/www/lang.tcl @@ -1,7 +1,7 @@ # # Run this Tcl script to generate the sqlite.html file. # -set rcsid {$Id: lang.tcl,v 1.34 2002/05/15 08:30:15 danielk1977 Exp $} +set rcsid {$Id: lang.tcl,v 1.35 2002/05/15 11:43:16 drh Exp $} puts { @@ -345,6 +345,118 @@ CREATE TABLE statement is synthesized and store in sqlite_master in place of the original command.

} +Section {CREATE TRIGGER} createtrigger + +Syntax {sql-statement} { +CREATE TRIGGER [ BEFORE | AFTER ] + ON + +} + +Syntax {database-event} { +DELETE | +INSERT | +UPDATE | +UPDATE OF +} + +Syntax {trigger-action} { +[ FOR EACH ROW ] [ WHEN ] +BEGIN + ; [ ; ]* +END +} + +Syntax {trigger-step} { + | | + | +} + +puts { +

The CREATE TRIGGER statement is used to add triggers to the +database schema. Triggers are database operations (the trigger-action) +that are automatically performed when a specified database event (the +database-event) occurs.

+ +

A trigger may be specified to fire whenever a DELETE, INSERT or UPDATE of a +particular database table occurs, or whenever an UPDATE of one or more +specified columns of a table are updated.

+ +

At this time SQLite supports only FOR EACH ROW triggers, not FOR EACH +STATEMENT triggers. Hence explicitly specifying FOR EACH ROW is optional. FOR +EACH ROW implies that the SQL statements specified as trigger-steps +may be executed (depending on the WHEN clause) for each database row being +inserted, updated or deleted by the statement causing the trigger to fire.

+ +

Both the WHEN clause and the trigger-steps may access elements of +the row being inserted, deleted or updated using references of the form +"NEW.column-name" and "OLD.column-name", where +column-name is the name of a column from the table that the trigger +is associated with. OLD and NEW references may only be used in triggers on +trigger-events for which they are relevant, as follows:

+ + + + + + + + + + + + + + +
INSERTNEW references are valid
UPDATENEW and OLD references are valid
DELETEOLD references are valid
+

+ +

If a WHEN clause is supplied, the SQL statements specified as trigger-steps are only executed for rows for which the WHEN clause is true. If no WHEN clause is supplied, the SQL statements are executed for all rows.

+ +

The specified trigger-time determines when the trigger-steps +will be executed relative to the insertion, modification or removal of the +associated row.

+ +

An ON CONFLICT clause may be specified as part of an UPDATE or INSERT +trigger-step. However if an ON CONFLICT clause is specified as part of +the statement causing the trigger to fire, then this conflict handling +policy is used instead.

+ +

Triggers are automatically dropped when the table that they are +associated with is dropped.

+ +

Triggers may be created on views, as well as ordinary tables. If one or +more INSERT, DELETE or UPDATE triggers are defined on a view, then it is not +an error to execute an INSERT, DELETE or UPDATE statement on the view, +respectively. Thereafter, executing an INSERT, DELETE or UPDATE on the view +causes the associated triggers to fire. The real tables underlying the view +are not modified (except possibly explicitly, by a trigger program).

+ +

Example:

+ +

Assuming that customer records are stored in the "customers" table, and +that order records are stored in the "orders" table, the following trigger +ensures that all associated orders are redirected when a customer changes +his or her address:

+} +Example { +CREATE TRIGGER update_customer_address UPDATE OF address ON customers + BEGIN + UPDATE orders SET address = new.address WHERE customer_name = old.name; + END; +} +puts { +

With this trigger installed, executing the statement:

+} +Example { +UPDATE customers SET address = '1 Main St.' WHERE name = 'Jack Jones'; +} +puts { +

causes the following to be automatically executed:

+} +Example { +UPDATE orders SET address = '1 Main St.' WHERE customer_name = 'Jack Jones'; +} Section {CREATE VIEW} {createview} @@ -398,6 +510,15 @@ Syntax {sql-command} { DROP TABLE } +Section {DROP TRIGGER} droptrigger +Syntax {sql-statement} { +DROP TRIGGER +} +puts { +

Used to drop a trigger from the database schema. Note that triggers + are automatically dropped when the associated table is dropped.

+} + puts {

The DROP TABLE statement consists of the keywords "DROP TABLE" followed by the name of the table. The table named is completely removed from @@ -1091,129 +1212,6 @@ the database backend and VACUUM has become a no-op.

} -Section {CREATE TRIGGER} createtrigger - -Syntax {sql-statement} { -CREATE TRIGGER [ BEFORE | AFTER ] - - -} - -Syntax {database-event} { -DELETE | -INSERT | -UPDATE | -UPDATE OF -ON -} - -Syntax {trigger-action} { -[ FOR EACH ROW ] [ WHEN ] -BEGIN - ; [ ; ]* -END -} - -Syntax {trigger-step} { - | | - | -} - -puts { -

The CREATE TRIGGER statement is used to add triggers to the -database schema. Triggers are database operations (the trigger-action) -that are automatically performed when a specified database event (the -database-event) occurs.

- -

A trigger may be specified to fire whenever a DELETE, INSERT or UPDATE of a -particular database table occurs, or whenever an UPDATE of one or more -specified columns of a table are updated.

- -

At this time SQLite supports only FOR EACH ROW triggers, not FOR EACH -STATEMENT triggers. Hence explicitly specifying FOR EACH ROW is optional. FOR -EACH ROW implies that the SQL statements specified as trigger-steps -may be executed (depending on the WHEN clause) for each database row being -inserted, updated or deleted by the statement causing the trigger to fire.

- -

Both the WHEN clause and the trigger-steps may access elements of -the row being inserted, deleted or updated using references of the form -"NEW.column-name" and "OLD.column-name", where -column-name is the name of a column from the table that the trigger -is associated with. OLD and NEW references may only be used in triggers on -trigger-events for which they are relevant, as follows:

- - - - - - - - - - - - - - -
INSERTNEW references are valid
UPDATENEW and OLD references are valid
DELETEOLD references are valid
-

- -

If a WHEN clause is supplied, the SQL statements specified as trigger-steps are only executed for rows for which the WHEN clause is true. If no WHEN clause is supplied, the SQL statements are executed for all rows.

- -

The specified trigger-time determines when the trigger-steps -will be executed relative to the insertion, modification or removal of the -associated row.

- -

An ON CONFLICT clause may be specified as part of an UPDATE or INSERT -trigger-step. However if an ON CONFLICT clause is specified as part of -the statement causing the trigger to fire, then this conflict handling -policy is used instead.

- -

Triggers are automatically dropped when the table that they are -associated with is dropped.

- -

Triggers may be created on views, as well as ordinary tables. If one or -more INSERT, DELETE or UPDATE triggers are defined on a view, then it is not -an error to execute an INSERT, DELETE or UPDATE statement on the view, -respectively. Thereafter, executing an INSERT, DELETE or UPDATE on the view -causes the associated triggers to fire. The real tables underlying the view -are not modified (except possibly explicitly, by a trigger program).

- -

Example:

- -

Assuming that customer records are stored in the "customers" table, and -that order records are stored in the "orders" table, the following trigger -ensures that all associated orders are redirected when a customer changes -his or her address:

-} -Example { -CREATE TRIGGER update_customer_address UPDATE OF address ON customers - BEGIN - UPDATE orders SET address = new.address WHERE customer_name = old.name; - END; -} -puts { -

With this trigger installed, executing the statement:

-} -Example { -UPDATE customers SET address = '1 Main St.' WHERE name = 'Jack Jones'; -} -puts { -

causes the following to be automatically executed:

-} -Example { -UPDATE orders SET address = '1 Main St.' WHERE customer_name = 'Jack Jones'; -} - -Section {DROP TRIGGER} droptrigger -Syntax {sql-statement} { -DROP TRIGGER -} -puts { -

Used to drop a trigger from the database schema. Note that triggers - are automatically dropped when the associated table is dropped.

-} - puts {