execute

Execute SQL statement and return update able resultSet with one or more lines.

or can execute insert/update or delete command or can execute procedures

 

resultSet=SQLStatement.execute(sqlCommand [,ParameterObject])

 

This command can execute every SQL command

select and procedure calls return a resultSet  object

insert, update and delete return only the sql code

 

The different to select command is, that it can return more then one row.

It can return a copy of table and you can write the changes in resultSet object back to database.

 

In optional second parameter from type "Object" you can define additional Properties. See ParameterObject.

 

Example

 
r=SQLStatement.execute("select \"ItemName\" from \"OITM\" where \"ItemCode\"='RM' ");

or

r.SQLStatement.execute({select "ItemCode","ItemName" from "OITM" where "ItemCode" = 'RM' "},

         {updateTable="OITM",primaryKey="ItemCode"});

 

Working with arguments:

Arguments are defined with double point

let a="RM";
let resultObject=SQLStatement.execute(
   {select "FrgnName","ItemName" from "OITM" where "ItemCode"=:a;}
);
alert(resultObject.FrgnName[1]+" "+resultObject.ItemName[1]);

 
function calls  are allowed: ... "ItemCode"=:myFunction(a);
point notations are allowed: ... "ItemCode"=:a.upperCase();

Formulas in bracket allowed: ... "ItemCode"=:('XX'+a.left(30))

 

select *

a select * from x is very slow.

The system allow to read all fields and create a select [all field names] command

select (fieldfrom=[table]) ...

this replace the placeholder with all fields form related Table

 

Example

result=SQLStatement.execute({select (fieldfrom=OITM) from "OITM" where "ItemCode"='RM'});

 

Parameter Object

This present an object, in which additional arguments can be defined.

Property

Function

updateTable

allow to create a update able resultSet object

{updateTable="OITM"}
(only for select commands)

primaryKey

define the primary key

for update table the primary key is mandatory

Example:

primaryKey="ItemCode"
primaryKey="belnr_id,belpos_id,pos_id"

noUpdate

Define the fields, for which you don't want the update possibility

example

myResult=SQLStatement.execute(
{select "ItemCode","ItemName",'' as MyField from "OITM" where "ItemCode"='RM'},
{updateTable="OITM",primaryKey="ItemCode",noUodate="itemcode,myfield"}
);

noError

ignore errors: noerror:true

 

Example: Scan SQL result (example: List ItemCode + ItemName)

let result=SQLStatement.execute('select "ItemCode","ItemName" from "OITM" ');
let text="";
for (i in result)  

 text += result.itemcode[i]+" "+result.ItemName[i]+"\r\n";
alert(text);