Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: How do I make nullable types for Rest Services in Tokyo?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Sep 20, 2017 7:12 AM Last Post By: Mark Tiede
Mark Tiede

Posts: 19
Registered: 5/17/98
How do I make nullable types for Rest Services in Tokyo?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 19, 2017 12:23 PM
So I have nullable integer data in a database. I use an ADOQuery to pull the data from the database. I WANT to make a REST service that returns this nullable integer, but I can't see how to make a nullable integer in Delphi. I can do it in .Net, but not Delphi.

Amongst many things I tried, I tried to make my own type with a HasValue and Value properties, but when it comes down to the client in the RESTResponse, and try to bind it to a dbgrid using a RestDatasetAdapter, it doesn't know what to do with my data type.

So isn't there now a "nullable integer" in Delphi that I can somehow declare and have it be used with the adapter and a grid?

How is everyone else doing this? Are you just converting the integers to strings and losing strong types?
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: How do I make nullable types for Rest Services in Tokyo? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 19, 2017 11:03 PM   in response to: Mark Tiede in response to: Mark Tiede
Mark Tiede wrote:

So I have nullable integer data in a database. I use an ADOQuery to
pull the data from the database. I WANT to make a REST service that
returns this nullable integer, but I can't see how to make a nullable
integer in Delphi. I can do it in .Net, but not Delphi.

Amongst many things I tried, I tried to make my own type with a
HasValue and Value properties, but when it comes down to the client
in the RESTResponse, and try to bind it to a dbgrid using a
RestDatasetAdapter, it doesn't know what to do with my data type.

So isn't there now a "nullable integer" in Delphi that I can somehow
declare and have it be used with the adapter and a grid?

How is everyone else doing this? Are you just converting the
integers to strings and losing strong types?

Delphi has no direct equivalent to nullable types (yet). The classical
database access components either use an object wrapper for values
stored in database tables (TField & Cie) or the Variant type. I have no
experience with web services, but since everything is transmitted as
text for REST or SOAP services (since they are implemented on top of
the http(s) protocol) you may as well use a special marker string to
represent a NULL value for a database field.

--
Peter Below
TeamB
Mark Tiede

Posts: 19
Registered: 5/17/98
Re: How do I make nullable types for Rest Services in Tokyo? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 20, 2017 7:11 AM   in response to: Peter Below in response to: Peter Below
Peter,

Thanks, I was afraid of that. We (my coworker and I) tried making our own data types and also just serializing the TFields, but we are using a RestResponseDatasetAdapter to create a ClientDataset that is bound to a grid component and the adapter was not happy with either choice.

Then we just added another field that contains the "IsNull" for each field of interest and that got us further. However, we are finding that ONE of the 4 fields that we use this technique on is not being parsed properly by the adapter. We can see that the right data is in the json for the RESTResponse that is being used by the adapter, but the dataset that the adapter populates has the wrong value for the "IsNull" field (which subsequently causes other things to go wrong in our code that is looking at the "IsNull").
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02