Business Rules Scripting Example

Hello,
I am running very basic Delphi project on relativity server and I would like to implement some simple database queries, ie. ‘return row count’ or ‘return all names where client code is 1…’ type of thing but I have absolutely no idea how to accomplish that.

I worked out that I will need to write some JavaScript in Schema Modeler and then call that code from SpiderMonkeyScriptProvider (?), only no clue how to do that. I would appreciate if someone could write a step by step instruction what to do together with example javascript method or at least give some hints how to proceed from here as I found no articles on that subject in Wiki or ROTV or Google.

Cheers!

Hello,
You can’t use scripts for this putpose.
Create corresponded datatables in schema and use them on client side with TDAMemDataTable components.
These articles will be helpful for you:
http://wiki.remobjects.com/wiki/Relativity
http://wiki.remobjects.com/wiki/Writing_a_Relativity_Client_(Delphi)

Dear vovanl,

Thank you for your response. However I don’t see how either of these articles could be helpful in what I want to achieve. I already have a project running on Relativity, setup with domain, schema and data tables in the schema. I know how to view ALL the table content in a grid at run-time but what I don’t know is how to return ‘custom’ datasets, like those described in my original posts, ie.

-return count of records in a table
or
-return sum of field ‘count’ etc.

These are simplest SQL queries I want to send to my schema during runtime.
I think Dynamic Select/Dynamic Where and DA SQL are my answers only I can not work out how to implement it in my code/project (:

I will phrase my question this way:

I want to execute : SELECT SUM(COUNT) FROM TABLE
from my client app(IntraWeb) to Relativity schema- how do I do that (what components & code in which order please). An equivalent of what I am looking for here is using TADSQuery component in Delphi, filling it in with SQL statement(s) and then calling ‘ExecuteSQL’ upon the component’s SQL property.

Please don’t refer me to any of the articles on Wiki because I have read them all around 3x by now and I do not see how to do it.

Hello,
You can use SQLGetData remote method of DataService. Please use the following code:

function TClientForm.GetTableCount(aTableName:String):Integer;
var
  service:IDataAbstractService;
  aData:Binary;
  aTable:TDAMemDataTable;
  aStreamer:TDABin2DataStreamer;
begin
  Result := 0;
  service := TDataAbstractService_Proxy.Create('DataService', ClientDataModule.Message, ClientDataModule.ClientChannel) as IDataAbstractService;
  aData := service.SQLGetData(Format('SELECT COUNT(*) CNT FROM %s', [aTableName]), True, -1);
  aTable:=TDAMemDataTable.Create(nil);
  aStreamer:=TDABin2DataStreamer.Create(nil);
  try
    aTable.LogicalName := 'SQLGetDataTable';
    aTable.RemoteFetchEnabled := False;
    aStreamer.ReadDataset(aData, aTable, True);
    Result := aTable.FieldByName('CNT').AsInteger;
  finally
    FreeAndNil(aData);
    FreeAndNil(aTable);
    FreeAndNil(aStreamer);
    service := nil;
  end;
end;

.....


begin
  GetTableCount('CUSTOMERS');
end;

The current version of Relativity doesn’t support it.
Can you say us your login? We will send you a new compiled Relativity.

Thank you vovanl for your answer. I managed to do what I wanted by using TableRequestInfoV6 class. It does what I need it to, but I would think there will be a property on one of the components or a separate component itself to take sql queries. I suppose there is some underlying reason for why there isn’t such thing, ie. RO Team favours other approach for querying DB rather than SQL?
Here is code I’ve used (adapted from DA SQL demo):

procedure TfrmClient1.btnExecuteClick(Sender: TObject);
var
tri: TableRequestInfoV6;
triArr: array of TableRequestInfo;
begin
if Trim(eQuery.Text) = ‘’ then begin
WebApplication.ShowMessage(‘The query is empty. Please select one of the query templates or write your own.’);
exit;
end;

tri := TableRequestInfoV6.Create();
with tri do begin
Sql := eQuery.Text;
IncludeSchema := true;
MaxRecords := 1000;
end;

try
with frmRelativityClient do begin
tbl_anim.ClearRows(true);
dbgResults.Columns.Clear;
SetLength(triArr, 1);
triArr[0] := tri;
RemoteDataAdapter.Fill([tbl_anim], triArr);
end;
except
on E: Exception do WebApplication.ShowMessage('Error executing query: ’ + E.Message);
end;
end;

I will try your solution later vovanl, after I got that new Relativity. My login is ‘bagietka’

Hello,
You can also use your method.
We strongly recommend to use queries from the schema for reasons of security because an intruder can destroy your data on database server.
You can download a new version of Relativity here:
https://secure.remobjects.com/portal/downloads/personal.aspx

Hi
Trying to test this function , but having an error in this line :

service := TDataAbstractService_Proxy.Create('DataService', ClientDataModule.Message, ClientDataModule.ClientChannel) as IDataAbstractService;

does not contain the member named: ClientDataModule.Message and same here: ClientDataModule.ClientChannel

you should have channel and message in your client datamodule. have you created your project with DA wizard?

Hi Evgeny
Understand your point.
I have it from Briefcase example and there is no channel and message.

you can use another constructor of this class where you can specify TargetURL only:

constructor Create(const aUrl: string; aDefaultNameSpaces: string); overload; virtual;

it will be like:

service := TDataAbstractService_Proxy.Create('http://localhost:8099/bin') as IDataAbstractService;

Thank you.
Have it sorted.