LocalDataAdapter Object
The LocalDataAdapter Object provides access to the current service to fetch data from it. This object can be accessed from the server only through the global lda variable.
The code snippet below shows how the lda object can be used:
function afterProcessDeltaChange(delta, change, wasRefreshed) {
lda.insert("History", { Date: new Date(), RowID: change['ID'], UserID: session['UserID'] } );
lda.applyChanges();
}
Properties
deltas
Represents an array (both by index and name) of all active deltas. Any calls to insert/update/delete will place new entries in the deltas property; these can be send to the database by calling applyChanges
or thrown away by calling discardChanges
.
Functions
insert(table, data)
Inserts a new row in table "table", the data should be a javascript inline object with a key:value
pair for each field.
update(table, oldvalues, newvalues)
Updates a row in the table "table". The "oldvalues" parameter can be the same as the "newvalues" parameter if the primary key hasn't changed. Both values have to be javascript objects with key:value
pairs.
remove(table, data)
Removes a row in table "table". The data has to match the primary key of the row to delete and has to be a javascript object with key:value
pairs for all fields in the primary key.
Example:
lda.remove('CustomTable', {Id:CustomValue});
lda.applyChanges();
discardChanges()
Drops all current changes and empties the deltas property.
Note: If you forgot to apply or discard changes the following log message will be shown: "Script Warning:
applyChanges()
Sends the changes to the database, if successful, it will empty the deltas property, else, it will throw an exception.
Note: If you forgot to apply or discard changes the following log message will be shown: "Script Warning:
selectSQL(sql, parameters)
Executes the DA SQL request with optional parameters. parameters
should be a complex object with property names matching the request parameter names.
Returns a SelectResult Object.
Example:
var result1 = lda.selectSQL('SELECT * FROM customers');
var sql = 'SELECT * FROM customers WHERE id=:pCustomerId';
var params = { pCustomerId : '3217032B-47DB-400A-9A6E-012CBDF1E1E5' };
var result2 = lda.selectSQL(sql, params);
Please note that the selectSQL function is used only in the .NET part as Delphi doesn't support the DA SQL feature.
selectWhere(table, fields, where, parameters)
Requests data from the Schema Table. The following data request parameters are used:
table
- requested table namefields
- array containing names of the requested table fieldswhere
- request conditions expressed via a WhereExpression objectparameters
- a complex object with property names matching the request parameter names
Returns a SelectResult Object.
Example:
var where = WhereBuilder.createBinary(WhereBuilder.createField('Id'), WhereBuilder.createParameter('Id', 'String', 50), 'Equal');
var users = lda.selectWhere('Customers', [ 'Id', 'Name' ], where, { Id: '{3217032b-47db-400a-9a6e-012cbdf1e1e5}' });
log(users.count);
execute(commandName, parameters)
Executes the Schema Command with provided name. The parameters
object is used to provide command parameter values.
Returns an object with properties containing out schema command parameters. The integer Schema Command execution result is represented as result
property of the result object.
Example:
var result = lda.execute('CustomSchemaCommand', { EntityId: '{3217032b-47db-400a-9a6e-012cbdf1e1e5}', EntityName: 'TestValue' } );
log(JSON.stringify(result));