Add statement for a relational database

You can use the EGL add statement to add a row to a relational database table. The content can come from an external type, handler, or record; or from a set of simple values.

Syntax



Syntax diagram for the add statement with SQL

addStatement
A single SQL INSERT statement, which is not required to end with a semicolon but can. The format is as shown for entity.

You can use a prepared statement in place of #sql{addStatement}.

entity
Name of the entity, which is a variable based on an External type, Handler type, or Record type. The values in that entity are used in the corresponding SQL INSERT statement. If you do not specify the SQL statement, the following default is used:
INSERT INTO tableName (column_1, column_2... column_n)
       VALUES (?, ?, ?)       

The value of tableName is the value of the Table annotation that is set on the entity type. If that annotation is missing from the type definition, the value of tableName is the type name.

The order of the column fields in the statement reflects the order of the fields in the type definition. Each question mark in the VALUES clause is replaced with the corresponding value in the entity.

A column entry such as column_1 is a name; specifically, the value of the Column annotation for a field in the type definition. If that annotation is missing from the field in the type definition, the name in the statement is the name of the field in the type definition.

simpleValue
A value of an EGL simple type that is compatible with the corresponding database column. The list of simple values is set into the values clause to match the list of column entries.

If you are adding simple values instead of an entity, you must specify an SQL INSERT statement. The statement format is as shown for entity.

SQLDataSource
A variable of type SQLDataSource. The variable includes connection details or references an EGL deployment descriptor entry that provides access to the connection details.

If you issue a prepared statement, the variable is optional and is ignored if present.

// you can use an entity such as record named myPayment
add myPayment to ds;

// alternatively, you can use a set of simple values 
// and specify the SQL INSERT statement.
add 6, "Services", 12.00, myPayment.due_date to ds with #sql{
   insert into Payment
      (category, description, amount, due_date)
   values
      (?, ? , ?, ?)
   };

Compatibility

Table 1. Compatibility
Target Issue
Java No issues
JavaScript Database access is not supported in JavaScript.