...
To configure DDBAPI, you need to define the database connection in the BL_Config.xml file using the FIXEdge\DatabaseConnection element:
|
The configuration for DDBAPI is found in the FIXEdge\DatabaseConnection element of your BL_Config.xml file. Here's a breakdown of the configuration options:
...
The executeSQL function is a JS binding that transfers control from the JS environment to the C++ runtime to execute SQL queries.
Example:
|
Parameters:
connection (string, required): Name of the database connection, must match DatabaseConnection.Name.
query (string, required): SQL statement to execute.
params (array, required): Query parameters to pass to the server (int, double, or string).
extraParams (object, optional): Additional settings to control the query's result and behavior.
result (JS object): Returned object with query results.
...
Example 1: Selecting a single value
|
affectedRowCount: Number of affected rows (used for modification queries).
data: Array of result rows; each row is an array of the selected data.
Example 2: Inserting multiple rows
|
Example 3: Deleting rows and selecting a value
|
MARS Query Result Mode
For queries that return multiple row sets with data modifications (Multiple Active Result Sets - MARS), the result is structured as an array of result objects:
Example 1: Multiple select statements
|
Example 2: Mixed DML and select statements
|
Extra Query Parameters
The extraParams parameter accepts an object with optional properties to customize the query behavior and result format:
...
If set to true, this parameter includes column names in the result objects. If a column name is unavailable, the column index is used instead.
Example:
|
When multiple columns are queried:
|
includeResultsMetadata (boolean)
Setting this parameter to true includes type information for each column in the result object.
Example:
|
When both associativeResults and includeResultsMetadata are enabled, the metadata includes column names as well:
|
timing (boolean)
Setting this parameter to true adds a "time" property to the result object. The value represents the query execution time in the format "$(number_of_hours)h.$(number_of_minutes)m.$(number_of_second)s.$(second_fraction)".
Example:
|
The measured time includes parameter preparation, transfer, server-side processing, receiving, and parsing of the results.
...
Single Array of Strings: Applies conversion directly to the query result in sequence.
Array of Arrays of Strings: Useful for Multi-Active Result Sets (MARS). If the MARS count is less than the number of arrays, the last array in resultTemplate is applied to remaining results.
Example:
|
|
resultTemplate supports the following type literals, case insensitive, as provided by https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values :
resultTemplate Value | Target JS Type |
---|---|
BigInt | BigInt with int64_t backend |
Number | Number with double backend |
String | String with std::string backend |
Null, Undefined | Read as is, no additional conversion applied |
Basic Use Cases
To use DDBAPI, your BL_Config.xml file should define a JavaScript execution action in one of its rules, like so:
|
Receiving Data from the Database
To fetch data from the database, you prepare a query and execute it. Here's an example of how to execute a DBMS query and print the result:
|
Query result:
|
This code snippet demonstrates the following:
...
To store data in the database, you can employ the DBMS query language as follows:
|
Query result:
|
This code snippet demonstrates the following:
...
When sending data from JavaScript to SQL and vice versa, the following type mappings are applied:
SQL type | JS → SQL (parameter) | SQL → JS (result) | Comment |
---|---|---|---|
tinyint, smallint, int, bigint | String: deserialize, Int: 1-to-1, Double: convert | Int: 1-to-1 Others - convert as is | |
bit | String: "true", "false" are converted, all others - failure Int: 0, 1 are converted, all others - failure Double: 0 - false, >0 - true, all other - failure | Always converted to: Others: convert to "0"/"1", 0.0/1.0 | |
decimal, numeric, money, smallmoney | String: ODBC-side conversion. Double: fail if extraParams.useStrictDecimal | String: "123.456" | |
float,real | String: deserialize, Int: convert, Double: 1-to-1. | Double: 1-to-1. | |
date, time, datetime2, datetimeoffset, datetime smalldatetime | String: try converting from FIX date, if succeeds fill the ODBC:DATE_TIME struct; if fails pass by to ODBC as string. Int: Try to interpret as JSDateEntity, if failed treat as unix time. Pass to ODBC:DATE_TIME struct in both cases. Double: Convert to unix time and pass to ODBC:DATE_TIME struct. | If no conversion requested, returns and int, representing a JSDateEntity. String: Convert to FIX date format Int: Convert to Unix timestamp. Double: Convert to Unix timestamp. | Several useful JS bindings for manipulating JSDateEntity objects are: dateToString, getDateField, createDate, getCurrentDate, (get | set | change)(Year | Month | ... | Sec|MSec|NSec) |
char, varchar, nchar, nvarchar | String: 1-to-1, Int: serialize double: serialize | String: 1-to-1 Others - convert as is | |
text, ntext | Not supported as these types are obsolete/deprecated. | ||
binary, varbinary, image | String: passed as is, Int: passed as binary uint64_t* buffer, Double: passed as binary double* buffer. | String: example: 0xdeadbeef -> "DEADBEEF" Others - convert as is | |
cursor, geography, geometry, hierarchyid, json, rowversion, sql_variant, table, uniqueidentifier, xml | All: passed as is | All: read as is | |
Arrays of values | Not implemented |