This section presents the syntax of command statements for the Empress SQL Precompiler for C in the alphabetical order. Each SQL command line must begin with the keywords EXEC SQL. Each SQL command line must end with a semicolon (;). An SQL statement can extend over more than one line.
Indicates the start of the declaration section for variables that will be used in SQL commands in your program.
| Syntax |
EXEC SQL BEGIN DECLARE SECTION; |
| SQLCODE |
No meaning. |
| Notes |
|
| Example |
EXEC SQL BEGIN DECLARE SECTION; int i; short j; float f; char str [10]; EXEC SQL END DECLARE SECTION; |
Calls a procedure or evaluate an expression.
| Syntax |
EXEC SQL :var = [CALL] expr; | ||||
| SQLCODE |
| ||||
| Notes |
Aggregate functions and operators can not be called using this statement. |
Cancels the currently executing transaction.
| Syntax |
EXEC SQL CANCEL TRANSACTION; |
| SQLCODE |
No meaning. |
| Notes |
|
CLOSE CURSOR closes the named cursor after it has been opened for row manipulations.
| Syntax |
EXEC SQL CLOSE cursor_name; where:
| ||||
| SQLCODE |
| ||||
| Note | A cursor must be closed before it can be re-opened. |
Closes the named table.
| Syntax |
EXEC SQL CLOSE_TABLE [table {, table}]; |
| SQLCODE |
No meaning. |
| Note |
If no table name is specified in the CLOSE_TABLE command, all open tables will be closed. |
| Example 1 |
The following command will close all open tables: EXEC SQL CLOSE_TABLE; |
| Example 2 |
The following command will close only the named tables, loans and personnel: EXEC SQL CLOSE_TABLE loans, personnel; |
COMMIT TRANSACTION makes permanent the changes made to the database during the current transaction.
| Syntax |
EXEC SQL COMMIT TRANSACTION; |
| SQLCODE |
No meaning. |
| Note | COMMIT TRANSACTION commits all transactions over all databases. |
Changes the current database.
| Syntax |
EXEC SQL DATABASE IS database; |
| SQLCODE |
No meaning. |
| Notes |
|
The command:
EXEC SQL DATABASE IS "repairs";
will make the repairs database, located in the repairs directory, the default database.
The command:
EXEC SQL DATABASE IS :base;
will make the database whose name is stored in the program variable ":base" the default database.
Declares a cursor to be opened. This involves naming the cursor and associating a context with the name through a WHERE clause.
| Syntax |
EXEC SQL DECLARE cursor_name CURSOR | ||||||||
FOR SELECT [ |DISTINCT |] [attr {, attr}]
|UNIQUE |
| |||||||||
FROM table {, table}
| |||||||||
[where_clause] | |||||||||
[sort_clause] | |||||||||
| |||||||||
where:
| |||||||||
| SQLCODE |
No meaning. | ||||||||
| Notes |
| ||||||||
| Example |
The command:
EXEC SQL DECLARE c1 CURSOR FOR
SELECT FROM personnel, loans
WHERE personnel.name='Jones'
AND personnel.name = loans.name;
declares a cursor called c1 that acts on selected records from the personnel and loans table. The criterion for record selection is defined in the WHERE clause. This context will consist of personnel records where the name attribute is equal to Jones and personnel and loans records where the name attributes are equivalent. |
Deletes one or more rows of a table or view.
| Syntax |
| ||||||||||
| SQLCODE |
| ||||||||||
| Note |
| ||||||||||
| Example 1 |
The command: EXEC SQL DELETE FROM loans WHERE amount < 50; will delete from the loans table all records in which the attribute amount has a value less than 50. | ||||||||||
| Example 2 |
The command: EXEC SQL DELETE FROM loans WHERE CURRENT OF c; will delete the current record from the context associated with the cursor named 'c'. If no record is current, none will be deleted. |
Indicates the end of the declaration section for variables that will be used in SQL commands in your program.
| Syntax |
EXEC SQL END DECLARE SECTION; |
| SQLCODE |
No meaning. |
| Note |
Every BEGIN DECLARE SECTION must have a matching END DECLARE SECTION. |
Performs cleanup operations, but does not terminate the program.
| Syntax |
EXEC SQL EXIT; |
| SQLCODE |
No meaning. |
| Notes |
|
In multiple row manipulations, FETCH places the cursor on the next available row in the defined context, makes it the current row, retrieves the values for the named attributes and stores the values in the specified variables.
| Syntax |
EXEC SQL FETCH [|NEXT |[AGAIN][FROM]] cursor_name
|PRIOR|
attr {, attr} INTO variable {, variable};
| ||||||||
| SQLCODE |
| ||||||||
| SQLWARN1 |
| ||||||||
| Note |
If the next record in the context is not accessible (i.e., it is locked), it will be made the current record but the values of its attributes will not be read into the program variables. You can attempt to re-read these attributes with the FETCH_AGAIN command. | ||||||||
| Example |
The command:
EXEC SQL FETCH c1
name, credit_limit
INTO :name, :crelim;
will make the next available record in the context associated with the cursor named c1 the current record, retrieve the values for the attributes name and credit_limit, and store them in the program variables :name and :crelim. |
If a FETCH is unsuccessful, FETCH_AGAIN will attempt to re-read the current record as indicated by the cursor rather than the next available record.
| Syntax |
EXEC SQL FETCH_AGAIN cursor_name attr {, attr}
INTO variable {, variable};
| ||||||||
| SQLCODE |
| ||||||||
| SQLWARN1 |
| ||||||||
| Note |
FETCH_AGAIN does not affect the status of the current record. After a FETCH_AGAIN the current record remains the current record. | ||||||||
| Example |
The command:
EXEC SQL FETCH_AGAIN c1
name, credit_limit
INTO :name, :crelim;
will attempt to retrieve the values for the attributes name and credit_limit and store them into the program variables :name and :crelim from the current record in the context associated with the cursor named c1. |
SQLCA is the SQL Communications Area. It is used as a common area for the compiler and the user. You should have the INCLUDE SQLCA command as the first Precompiler statement in the program.
| Syntax |
EXEC SQL INCLUDE SQLCA |
| SQLCODE |
No meaning. |
| Note |
You should have an INCLUDE SQLCA statement as the first Precompiler statement of your program. |
Executes initialization procedures for Empress.
| Syntax |
EXEC SQL INIT; | ||
| SQLCODE |
| ||
| Notes |
|
Inserts a new row of attribute values into a table.
| Syntax |
EXEC SQL INSERT INTO table
(attr {, attr}) VALUES (value {, value});
where:
| ||||||
| SQLCODE |
| ||||||
| Notes |
| ||||||
| Example |
The command:
EXEC SQL INSERT INTO personnel
(name, number, credit_limit)
VALUES ("Mosca", 10, 1500);
will insert a new row into the personnel table setting the value of the attribute name to Mosca, the attribute number to 10 and the attribute credit_limit to 1500. |
Opens the named cursor to perform multiple row manipulations.
| Syntax |
EXEC SQL OPEN cursor_name; | ||||
| Notes |
| ||||
| SQLCODE |
|
Explicitly opens a table for operations.
| Syntax |
| |||||
| SQLCODE |
| |||||
| Note |
For every executed command, the Precompiler verifies that all of the required tables have been opened and, if so, that they have been opened in the correct mode (read, update or dirty read). If the tables are not open, they will be opened in a mode corresponding to the requirements of your SQL command. | |||||
| Example |
The command:
EXEC SQL OPEN_TABLE
loans FOR READ,
personnel FOR UPDATE;
will open the loans table for read operations and the personnel table for update operations. |
Retrieves one row of data from a table or view and stores it in the program variables specified.
| Syntax |
EXEC SQL SELECT attr {, attr} FROM table {, table}
INTO variable {, variable}
[where_clause];
| ||||||||
| SQLCODE |
| ||||||||
| SQLWARN1 |
| ||||||||
| Notes |
| ||||||||
| Example |
The command:
EXEC SQL SELECT name, date FROM personnel
INTO :var1, :var2 WHERE name='Jones';
will retrieve the values of the attributes name and date from the personnel table. The values will be taken from the first record that meets the conditions of the WHERE clause (i.e., that has the value Jones in the attribute name). They will then be stored in the program variables :var1 and :var2, respectively. |
Starts a transaction on the following command.
| Syntax |
| ||||
| SQLCODE |
| ||||
| Note |
Transactions may be started from within retrieval loops. |
Updates one or more records in the table specified with the values provided.
| Syntax |
EXEC SQL UPDATE table SET attr = value {, attr = value}
|where_clause |;
|WHERE CURRENT OF cursor_name|
| ||||||||||||
| SQLCODE |
| ||||||||||||
| Notes |
| ||||||||||||
| Example 1 |
The command:
EXEC SQL UPDATE personnel
SET credit_limit=100, date='19851119'
WHERE name='Jones';
will update the attributes credit_limit and date with the supplied values, for all of the records in the personnel table where the attribute name contains the value Jones. | ||||||||||||
| Example 2 |
The command:
EXEC SQL UPDATE personnel
SET credit_limit=100, date='19851119'
WHERE CURRENT OF c;
will update only the current record in the context associated with the cursor named c. |
A WHERE clause determines the set of records which satisfy the conditions in the clause. A WHERE clause is always used as an option with another SQL command.
A WHERE clause consists of boolean expressions; that is, expressions that evaluate to true or false. A complex WHERE clause may be built up using boolean expressions that are joined using AND and OR. Precedence in evaluating the parts of a complex WHERE clause is controlled by parentheses.
| Syntax |
| |||||||||||||
where boolean_expr is one of:
where operand is:
| ||||||||||||||
| SQLCODE |
No meaning. | |||||||||||||
| Notes |
|
WHENEVER allows you to define the course of action that will be taken when an error is encountered during the execution of your program.
| Syntax |
| |||||
| SQLCODE |
No meaning. | |||||
| Notes |
|