#1 2015-09-22 08:22:48

dolfin
Member
Registered: 2015-09-11
Posts: 22

Firebird db objects names capitalization issue

Hi, I use external firebird db as a data store and TSQLDATASET ConnectionProperties class to interact with it. Unfortunately all tables and there fields names are stored in the db in capitalize form. The problem is I get JSON object in capitalize form too, in spite of Delphi objects names are written in camel case. I begun my project using sqlite db(for sql lite everything works fine) and now I need to switch to firebird db and as Javascript is case sensitive I have to change a lot of code. I think the serialized object should have names as it is set in delphi and do not depend on db or driver. What is the best way to solve this issue?

Offline

#2 2015-09-22 08:58:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,242
Website

Re: Firebird db objects names capitalization issue

You could try to map the field names, giving explicitly uppercased names for the external database.

See http://synopse.info/files/html/Synopse% … l#TITL_120

Offline

#3 2016-03-16 13:42:20

dolfin
Member
Registered: 2015-09-11
Posts: 22

Re: Firebird db objects names capitalization issue

Hello!
I faced with new issue while getting JSON object response with fields in the upper case. Let me first describe my situation.
I tried to map fields as you suggest but with no luck(But still thank you for your idea, I used it for making table field's names more readable in the db). And unexpectedly I
discovered that if I add variant field to any model everything works as I need. The fields names are exectly as I set in the Model.
My model is:

type
  TProgramPlanDeleted = class(TSQLRecord)
    private
      FDeletedPlanId: TID;
      FCreateTime: TDateTime;
      FComment: Variant;
    published
      property DeletedPlanId: TID read FDeletedPlanId write FDeletedPlanId;
      property CreateTime: TDateTime read FCreateTime write FCreateTime;
      property Comment: Variant read FComment write FComment;
  end;

So without variant field "Comment" I get(http://local:8080/root/ProgramPlanDeleted/1):

{
  ID: 1,
  DELETEDPLANID: 2,
  CREATETIME: "2016-03-16"
}

And if I add variant field "Comment" I get:

{
  ID: 1,
  DeletedPlanId: 2,
  CreateTime: "2016-03-16",
  Comment: {
    a: 1
  }
}

So I resolved the issue by adding variant field to any model I use. But unfortunetly this worked only with version '1.18.1907'.

Today I updated my mormot to latest version and faced this issue again. For now in spite of variant field I always get such result:

{
  ID: 1,
  DELETEDPLANID: 2,
  CREATETIME: "2016-03-16"
}

I remind that this happens only when working with firebird db. I can't refuse from firebird nighther want to stay on old mormot  version. 
Could you please provide any help on this issue?

Offline

#4 2016-03-16 14:39:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,242
Website

Re: Firebird db objects names capitalization issue

Just try to add the rsoGetAsJsonNotAsString option to TSQLRestServer.

Offline

#5 2016-03-16 14:57:54

dolfin
Member
Registered: 2015-09-11
Posts: 22

Re: Firebird db objects names capitalization issue

Thank you very much!!! It works as magic!

Offline

#6 2016-03-16 16:40:01

dolfin
Member
Registered: 2015-09-11
Posts: 22

Re: Firebird db objects names capitalization issue

I played with TSQLRestServer options and faced with a few issues.
First of all I really want to say thank you for realization of soAddUpdateReturnsContent and rsoComputeFieldsBeforeWriteOnServerSide features but could you please clarify some details of its behavior:
1. Regarding rsoGetAsJsonNotAsString: if Model doesn't contain variant field the JSON response contains its fields in the uppercase. If model contains any variant field everything works fine. I think such behavior is a bit confusing.
2. Regarding soAddUpdateReturnsContent: The response always contains object fields in the upper case.
3. Regarding rsoComputeFieldsBeforeWriteOnServerSide: It works fine for fields TModTime / TCreateTime but if I perform PUT or POST request with only few fields (not with all fields of the model) then in "onBeforeWrite" function it is possible to modify only these fields. It is a bit inconvenient as for example I need to update only one field of the model (for example "Name") but on the server side I need to update another field "last_change_user_name" in "onBeforeWrite" function and for now I can’t do that.

Many thanks in advance!

Offline

Board footer

Powered by FluxBB