Dear Rick,
I am implementing REST service into my web application and I am following your tutorial.
I have 2 questions:
if I do some query into the REST service and I have to return a cursor, where can I close it?
I cannot close it before the RETURN.
I tried to add Function Dispose() to the service and it closes cursors.
Is it the right way to close temporary tables?I passed a parameter to ask records of first December 2016 from a data field and the method returned a data like
"2016-11-30T23:00:00Z"
{
"idfunziona": "A0X2",
"dataprod": "2016-11-30T23:00:00Z",
"idprod": "005",
"idrecord": 337527
},
{
"idfunziona": "A0X2",
"dataprod": "2016-11-30T23:00:00Z",
"idprod": "005",
"idrecord": 337825
}
Please how to convert data string into first December 2016?
Thank you very much for support
If you return a cursor to the REST service for rendering as JSON with return cursor:ResultCursor
, you can't explicitly close the cursor. That's because the service needs to access the cursor after the request is done in your code in order to serialize it.
My recommendation is use the same cursor name always (like TQuery for example) and don't worry about the cursor staying open for one request. It'll be closed and overwritten in the next request.
You can also override the OnProcessComplete()
or in the Service OnAfterCallMethod(@lcResult)
method in the service class and close anything there, but this method is called for every method of the process class, so you'd have to selectively check for each request to figure out which cursor to close.
Using a reusable cursor is by far the easiest thing though - doing this leaves a single (or maybe a few) cursors open at any time which is not an issue. What you worry about is having lots and lots of cursors open all the time.
+++ Rick ---
Thank you Rick.
And what about the data value ("2016-11-30T23:00:00Z") returned from table instead of first December 2016?
How to extract (or convert) data values correctly?
Sincerely
With respect to the date, I suspect if you use Moment JS it will be fixed. I think it comes from the UTC offset.
realDataProd = moment(dataprod).format('YYYY-MM-DD')
Many thanks Harvey.
I see the Moment() however how I use it into a function like the following where I have to return formatted dates as YYYY-MM-DD?
Sincerely
********************
FUNCTION Test()
********************
SELECT DataProd ;
FROM MyTable ;
INTO CURSOR Query
RETURN "cursor:Query"
ENDFUNC
If you're using the West Wind client libraries for your JSON parsing it'll automatically convert dates back to dates.
For other clients external to your app - that'll be up to the consumers to handle. +++ Rick ---
Dear Rick,
as I said I am implementing REST service into my web application and I am following your tutorial Step by Step: Creating a JSON REST Service.
I followed the New Process Wizard to create a new REST service and a new scriptmap .rs on the development machine.
Please what about the server: do I have to create manually the new scriptmap on the server?
Sincerely