This element allows you to execute SQL sentences that does not have a result
set. This is the case of inserts, updates, deletes or some kinds of stored procedures.
This property defines the in which database
in the sentence will be executed. The database is referenced by the alias
name previously configured with the DBSP Configuration application.
QUERYID
Define in Id the object identification
number that was assigned by the DBSP Builder to the SQL sentence that you
want to execute.
DOC
Define in document the page that will
be retreived after the execution of the SQL sentence. If this property is
not defined, the sentence will be executed as soon as it be interpreted.
MULTIVALUEPARAMS
This property is used for multiple execution
of SQL sentences. This feature could be used in order to insert or delete
multiple records in a single page. Define a comma
separated list of the fields that will match this criteria, for example:
FIRSTNAME, LASTNAME, AGE.
MULTIVALUERANGE
This property is used for multiple execution
of SQL sentences. Define here for what range, the SQL sentence will be executed.
For example, a valid value for this property could be 1..3. In this case
(and using the fields defined in the previous property), the SQL sentence
will be executed 3 times. In the first query execution, the values contained
in the controls FIRSTNAME1, LASTNAME1, AGE1 will be used in the query. In
the second execution the values contained in the controls FIRSTNAME2, LASTNAME2,
AGE2 will be used. Finally, in the third execution, the values FIRSTNAME3,
LASTNAME3, AGE3 will be used.
NOMASTERSOURCE
If the QRYEXEC tag is contained inside
a DATASET tag, the DATASET tag is ignored and no Master-Detail relationship
is created.
Applications
Use the QRYEXEC tag when you want to modify any information of a database by
executing an insert, update or delete statement.
The QRYEXEC element could be used in two different ways:
Mode A: Executing immediately
If you do not define the DOC property, the query will be executed as soon as it became interpreted. This is useful when we need to execute multiple statements in certain page.
In this mode, you set the property DOC to a certain document that you want to retrieve after the execution of the sentence. Here, the element will not execute the sentence at the moment of the interpretation. Instead, it will replace the element with an URL. Just when this URL is requested, then sentence is executed. This is very useful for defining multiple actions in a single page (for example: adding, updating and deleting information from a catalog, depending on the user selection).
<!-- This won't be immediatly executed. Instead, the QRYEXEC will be replaced by an URL > <form name="TheForm" method="post" action="<#QRYEXEC ALIAS=TEST QUERYID=14 DOC=Insert.dbsp/>">
Examples
Example 1. Insert data into a table
The following example shows how to create a user catalog where you can add information to the catalog.
SELECT TITLE
FROM DBSPEXAMPLES
WHERE EXAMPLEID = :EXAMPLEID
SQL Sentence QUERYID=19
UPDATE DBSPNEWS SET
TITLE = :TXTTITLE,
IMAGEFILE = :TXTIMAGEFILE,
INTRO = :TXTINTRO,
BODY = :TXTBODY,
NEWSDATE = "now",
ORDEN = :TXTORDEN
WHERE NEWSID = :ID
File: /QryExec/InsertExec.dbsp
dataset example
SQL Sentence QUERYID=46
SELECT TITLE
FROM DBSPEXAMPLES
WHERE EXAMPLEID = :EXAMPLEID
<!-- Notice that the action property of the form contains a QRYEXEC Tag with a DOC property set to this file. This means, that the query 14 will be executed and then this page will be retreived again. -->
SQL Sentence: ID=13
SELECT * FROM CONTACTS
SQL Sentence: ID=14
INSERT INTO CONTACTS (USERNAME, EMAIL)
VALUES
('<#CONTACTNAME>','<#EMAIL>')
When you use a multiple execution statement, the first field in the MULTIVALUEPARAMS list must not be null (in this case, the NAME field). Otherwise, the entire row is ignored and the statement does not execute for this particular row.
<!-- Notice that the action property of the form contains a QRYEXEC Tag with a DOC property set to this file. This means, that the query 14 will be executed for each row and then this page will be retreived again. -->
SQL Sentence: ID=13
SELECT * FROM CONTACTS
SQL Sentence: ID=14
INSERT INTO CONTACTS (USERNAME, EMAIL)
VALUES
('<#CONTACTNAME>','<#EMAIL>')