JDBC actions
Select query
The action will execute an SQL query that can return multiple results.
It has limitations on the query and is suited only for SELECT
-type queries.
You can use clause variables with specific data types in an SQL query.
Internally, we use prepared statements, so all incoming data is validated against SQL injection.
A connection had to be established from JavaScript to the SQL data types.
Consequently, when working with prepared statements, it is necessary to append :type
to each variable in the prepared statement.
Prepared statement variables' names could contain any characters between a-z or A-Z , a digit, and an underscore ([a-zA-Z0-9_]).
|
For instance, consider the following SQL statement:
SELECT
FROM users
WHERE userid = @id AND language = @lang
In this case, add :type to each @parameter. Consequently, your SQL query should be modified as follows:
SELECT
FROM users
WHERE userid = @id:number AND language = @lang:string
The following types are supported:
-
String
-
Number
-
Bigint
-
Boolean
-
Float
-
Date
The Emit Behavior drop-down contains the following possible options:
- Fetch all
-
A single message with an array of results containing all the objects (rows) will be emitted.
- Emit Individually
-
Multiple messages (one message per one row) will be emitted.
- Expect Single
-
A single message with one result row will be emitted. If more than one row is returned, an error will be thrown. A boolean input Allow Zero Results (defaults to
false
) appears at input metadata. Iffalse
, an error will be thrown; else, the empty object will be emitted.
Execute query action
Action to execute a custom SQL query from the provided request string.
SQL requests will be executed according to the chosen database JDBC specification. |
The execution result returns as an array of objects. If the request contains multiple SQL statements, they will execute inside one transaction. If one of the statements fails, the transaction will be rolled back.
Insert action
The action will execute an INSERT
command into the table from the Table drop-down list with the values specified in the body.
Configuration fields
- Enable Rebound
-
If
Yes
, in case of deadlocks, rebound a message using the Sailor rebound mechanism. The number of rebound can be specified via environment variable (only the product team can make the configuration update).
Input fields
This action contains only one configuration field, Table, which has a drop-down list with available table names.
Delete row by primary key action
This action will execute a delete query from a Table drop-down field.
The only usable criteria is PRIMARY KEY
.
The action returns the count of affected rows.
The checkbox Don’t Throw Error on an Empty Result allows emitting an empty response; otherwise, you will get an error on an empty response.
Execute stored procedure action
This action calls a stored procedure from the selected DB Schema
and Stored procedure
name.
Input fields
- DB Schema
-
A schema that contains a procedure to call. Must be selected from the drop-down list before the Stored procedure name.
- Stored procedure
-
A name of a procedure to call, can be selected from the drop-down list.
Metadata generates automatically using IN & IN OUT
procedure parameters for input and OUT & IN OUT
procedure parameters for output.
As array fields, this action now supports ONLY:
-
CURSOR (as SQL type).
-
REF CURSOR (as ORACLE type) The result for this type of fields would be returned as an array of JSON objects.
This action does not process the MSSQL @RETURN_VALUE
.
-
In the MySQL component, 'DATABASE' is equivalent to 'SCHEMA' by definition. Therefore, the DB SCHEMA drop-down is empty for MySQL.
-
MSSQL DB stored procedures have only
IN
andINOUT
fields.
Example use case
For Oracle DB procedure:
create PROCEDURE "INSERT_EMPLOYEE"(
i_emp_id IN EMPLOYEE.EMPID%TYPE,
i_name IN EMPLOYEE.EMPNAME%TYPE,
i_department IN EMPLOYEE.DEPARTMENT%TYPE)
IS
BEGIN
INSERT INTO EMPLOYEE (EMPID, EMPNAME, DEPARTMENT)
VALUES (i_emp_id, i_name, i_department);
END;
Component generates the next metadata:
Upsert row by primary key action
The action will execute a SELECT
command from a Tables drop-down field, and as search criteria, only PRIMARY KEY
can be used.
It will execute an INSERT command by PRIMARY KEY
with specified fields if the result does not found; else, the action will execute an UPDATE
command by PRIMARY KEY
with specified fields.
The action returns only one result row (as a primary key is unique).
-
Select a table from the Table drop-down list:
-
Specify input (userid field is, in our case, a Primary key) data and click “Continue”. You can also enable the rebound mechanism if needed.
-
Retrieve a sample result, click “Continue” and finish component configuration.
Input fields
- Enable Rebound
-
If this is
Yes
, in case of deadlocks, rebound a message using the Sailor rebound mechanism. The number of rebound can be specified via environment variable (only the product team can make the configuration update).
As an input metadata, you will get all fields of the selected table.
PRIMARY KEY
is a required field, and other input fields are optional.
Create or update record action (deprecated)
This action exists in the JDBC component only for backward compatibility. Please use Upsert row by primary key action instead.