Run custom SQL to fetch scalar value from RO/DA service

I want to add functionality to easily fetch scalar data from a service using custom SQL.
I implemented a client side function:

public static T GetScalarValueWithCustomSQL<T>(IDataAbstractService service,string sql) where T:new()
    {
      RemObjects.SDK.Types.Binary tabledata=service.SQLGetData(sql,true /*false*/, -1);
      var dataTable=DB2RemObjectsUtil.GetDataTableFromROBinary(tabledata, null);
    <... return column 0 of row 0>
}

However deserializing the Binary to a DataTable fails

  1. If I run SQLGetData aIncludeSchema=False then I get error ‘Cannot find schema for table in stream received from server: SQLResult’

  2. With aIncludeSchema=true the streamer.ReadDataTable function throws error ‘DataColunn needs a name’ (unless I explicitely name my aggregate column)
    Can this be prevented?

FYI: I call ReadDataTable with argument applySchema=true (which is required I presume)

Hi,

usage SQLGetData is dangerous because it calls SQL as is w/o checking. We have replaced direct calls methods with DA SQL functionality:

DataTable lTable = new DataTable();
lDataAdapter.FillWithDASql(lTable, "select ...", null);

OK, I can try this
How do I get a DataAdapter from an interface to a DataAbstractService

p.s. in my case now it is a local service reference

Hi,

IDataAbstractService doesn’t contain reference to DataAdapter.
We have Local Data Adapter for using on server-side.
usage is almost the same as with Remote Data Adapters

Actually I tried your suggestion first but I got stuck when none of the LocalDataAdapter constructors took the IDataAbstractService interface I had.

How do I create a LocalDataAdapter for an IDataAbstractService (without creating extra instances)

Hi,

You can just pass DataAbstractService instance to constructor like

fLDA := new LocalDataAdapter(self);

or set LDA.ServiceInstance property:

fLDA.ServiceInstance := self;

In C# .NET this does not compile.
The types are different IDataAbstractLocalServiceAccess & IDataAbstractService

error CS1503: Argument 1: cannot convert from ‘RemObjects.DataAbstract.Server.IDataAbstractService’ to ‘System.ComponentModel.IContainer’

error CS0266: Cannot implicitly convert type ‘RemObjects.DataAbstract.Server.IDataAbstractService’ to ‘RemObjects.DataAbstract.Server.IDataAbstractLocalServiceAccess’. An explicit conversion exists (are you missing a cast?)

Hi,

Local Data Adapter is used on server-side and Remote Data Adapters is used on client-side.

have you mixed them?

pls review DASQL sample. it demonstrates usage of DA SQL on client-side.