on 06-12-2015 4:51 AM
Hello people who can create queries with XSDS properly!
I started using XSDS (so I'm in Hana SPS 09).. very interesting stuff.
Of course, I read all the few information sources on this topic:
So I have a table similar to the one below:
@Catalog.tableType: #COLUMN
Entity TAB001
{
key id_a: ty_id_a;
key field_b: Integer64;
key field_c: LocalTime;
key field_d: LocalTime;
field_e: ty_id_e not null; // association with non CDS table
field_f: LocalTime;
field_g: LocalTime;
field_h: Integer64;
field_i: global_types.ty_log_criacao;
};
Then, I created a query like the one below. It works fine.
function createEntity() {
var constructor;
constructor =
XSDS.$getEntity('my.package::cds.TAB0001');
if (!constructor) {
constructor = XSDS.$importEntity(
"my.package",
"cds.TAB001"
);
}
return constructor;
}
The function above is just a getter for the Entity constructor
function getDataUsingCDS(input){
var Agenda = createEntity();
var queryResult =
Agenda
.$query()
.$project({
id_a: "id",
field_b: "weekday",
field_c: "inicio",
field_d: "fim",
field_e: "pausa_inicio",
field_f: "pausa_fim"
})
.$where(Agenda.id_profal.$eq(input.id))
.$execute({$flat: true});
// for (var int = 0; int < queryResult.length; int++) {
// queryResult[int].id = agendasDoProfissional[int].id.toString(); // used to avoid id = {}
// queryResult[int].dia_da_semana = queryResult[int].weekday.toString(); // used to avoid field_b = {}
// }
return {
profissional: input,
agendas: queryResult
};
}
The code above is inside a xsjslib and I have a xsjs which calls this function and JSON.stringify its return.
My problem is: some attributes from the query result are actually objects and not simple values. Like the JSON below:
{
"profissional": {
"id": "2"
},
"agendas": [
{
"field_g": {},
"field_e": {},
"field_c": "0000-01-01T04:41:24.000Z",
"field_d": "0000-01-01T04:41:24.000Z",
"weekday": {},
"id": {}
},
{
"field_g": {},
"field_e": {},
"field_c": "0000-01-01T04:41:24.000Z",
"field_d": "0000-01-01T04:41:24.000Z",
"weekday": {},
"id": {}
},
For some unknown reasons, LocalTime fields don't have this problem. Inspecting these objects in the debugger it's possible to see they have methods like "toString()" which actually return DB column value but.. Do I have to do a conversion like the for statement above (commented)?
From my understanding $query() retrieves data and store on unmanaged (non persistent) objects.. reading all links above I would believe such objects would be simple key value pairs but it doesn't seems to be the case. Also, $select and $findAll methods have the very same problem.
Thanks!
Hi Fabio,
I think the behavior you are seeing is caused by the use of ctypes.Int64 in XSJS representing BigInt / Integer64 in the database. As in the XSJS API Reference (http://help.sap.de/hana/SAP_HANA_XS_JavaScript_Reference_en/$.db.ResultSet.html), e.g. getBigInt returns this special object and not a plain JavaScript value. By design, XSDS does nothing specific with it but propagates it as received from the DB API to the XSDS clients.
Unfortunately ctypes.Int64 is printed as {} by JSON.stringify. Therefore I think you would need to serialize (convert) this in a way similar as you described it.
Best regards
/Andreas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.