Please enable JavaScript to view this site.

Codolex

Navigation: Activities > Database

Execute command

Scroll Prev Top Next More

The execute command helps with retrieving data from the database faster.

The activity makes it possible to run a command on the database directly without retrieving data.

This can be used to retrieve single fields of primitive data types.

 

Let's compare the method for retrieving a record count for example.

You could get the amount of records in a table by retrieving all records, and using the list operation activity.

 

ExecuteCommandExampleNot

 

In the case you only want to know the count, and not perform any other action with the records, this sollution would be performance heavy because it retrieves all records.

 

The other option is to execute a count action on the database with the Execute command activity.

 

ExecuteCommandExample

Activity properties

 

begin

var shipperscount: Integer;

var DatabaseQuery := CodolexFramework.DatabaseQueryProvider['Codolex']();

 DatabaseQuery.SQL.Text := 'SELECT COUNT(*) as shipperscount FROM shippers';

var Dataset := DatabaseQuery.Open;

 Dataset.First;

var Field := Dataset.FindField('shipperscount');

if Assigned(Field) then

   shipperscount := Field.AsInteger;

end;

 

Select a database, provide the command to execute, and define what the result field name and type will be.

The activity will look for this result field and put the value in a result variable.

If multiple records are returned from the command, the first record will be taken for the result.

© by GDK Software