Script

Hello.
I would write a script in Commands->scripts,
but I would like to pass one or two parameters to that script via a client written in Delphi.

The script is similar to the one below.

How do I pass the parameters via command.execute?


log(“begin”);

var sql = ‘select field1,field2… from table where id_pk = :pid_pk order by fieldx’;
var params = { pId_pk : ‘116’ };
var result2 = lda.selectSQL(sql, params);

for (i = 0; i < result2.count; i++)
{
var row = result2[i];
log(row[1]+": "+ row[“field2”]);
lda.insert(“table2”, { date: new Date(), field1: row[1], field2: row[2] } );
lda.applyChanges();
}
log(“end”);


if I correctly understand you, it can be done like

RemoteCommand.Execute('DeleteRow',['ID'],[aID]);

see the TDARemoteCommand article for more details.

In Parameters I added an input IdTurma (type integer) - but in
script gives error.

log (idTurma); ERROR: IdTurma is not defined

Hello

How exactly do you try to access this parameter?
Also in which exactly event handler did you add your script?

Hello.

In the script I tried this way

Log(idTurma) Or Log(:idTurma) none worked …

in Delphi

syntax of beforeExecuteCommand is

beforeExecuteCommand(sql, commandName, parameterNames, parameterValues)
Called before an SQL command is executed.

    sql contains the SQL to execute, commandName the name of the command.
    parameterNames is an array of parameter names
    parameterValues is an array of object values

so you have received arrays of parameter names and values.

try to use something like

for (var i=0,len=parameterNames.length; i<len; i++)
{
  if (parameterNames[i] == "idTurma") { Log(parameterValues[i]); }
}

Hello.

Script only works on events available?

Can I make a function or method in the script, and call it as a store procedure?

EX: function sum (par1, par2)

And within the delphi call this function in the command.execute (‘sum’, par1, par2);

Scrip is available ONLY on events.
Yet you can define a stored procedure with empty statement and attach the script to it.

This is work…
But I had to create a SQL fake to work …
What interests me is just what’s inside the beforeexecutecommand

There are plans in the future to create methods in scripts ?

Another doubt, in this event can I receive the value of some variable in return? If so, have some examples.

I try example : "lda.update(“Workers”, { WorkerID: 122 }, { WorkerLastName: “Frankie” });"
But not work

lda.update(“matricula”,{id_matricula: idMatricula},{num_chamada: numChamadaNovo});

erro -> Fields collection for UPDATE command is empty

have you applied changes with lda.applyChanges(), like:

 lda.update("Customers",{ CustomerID: "ALFKI"}, {CompanyName: "updated"});
 lda.applyChanges();

?

Yes… but i receive this " Fields collection for UPDATE command is empty"

My code.

lda.update(“matricula”,{id_matricula: idMatricula},{num_chamada: numChamadaNovo});
lda.applyChanges();

hmm, odd.
try to create delta commands for matricula table inside Schema Modeller, validate that update command is OK and retest this case.

This is a command script, there is no delta

lda.update syntax is

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.

so it works only with tables.

can you describe what you wanted to reach with

lda.update(“matricula”,{id_matricula: idMatricula},{num_chamada: numChamadaNovo});

?

Delta UPDATE

Log