#2 mORMot 1 » [SOLVED] RecordLoadJSON / DynArrayLoadJSON with reserved words » 2017-12-11 13:00:14

yankee
Replies: 2

Hi,
I'm using RecordLoadJSON / DynArrayLoadJSON with custom serialization
(TTextWriter.RegisterCustomJSONSerializerFromText)
and I'm facing a problem with a JSON object like this:

{
  "type": 1,
  "name": "myName"
}

the problem is that I cannot map it to this

type
  TDBRec_myRec = packed record
    type: Integer;    // <-- error! "type" is a reserved keyword
    name: RawUTF8;
  end;
const
  __TDBRec_myRec = 'type: Integer;  name: RawUTF8';

Is there some way to tell the serializer to map JSON "type" to some other record field?

Thank you very much.

#3 mORMot 1 » Parsing JSON fields in a TRawUTF8List » 2015-05-05 09:10:23

yankee
Replies: 1

Hi,
I'm a little confused about all JSON-related functions in SynCommons.

I'm using the mORMot JSon parser "alone" because I'm creating a REST client for a custom Server (that doesn't use mORMot).

I receive a JSON response like this:

{
  outputParam1:"value1",
  outputParam2:5,
  data: [
    {//object to be mapped to a TSQLRecord},
    {//object to be mapped to a TSQLRecord},
    ...
    {//object to be mapped to a TSQLRecord}
  ]
{

I stored it in a RawUTF8 string and succesfully got the data array automatically mapped using _JsonFast and TSQLTableJSON.CreateFromTables.
Now, outputParam fields are not mandatory, but if there are any I'd like to parse and put them as name-value pairs in a TRawUTF8List.

What is the best/fastest way to achieve that?
Thank you

#4 Re: mORMot 1 » Early binding TSQLTable » 2015-04-29 09:23:01

Thank you, this is exactly what I needed.

Analyzing the code in CreateAndFillPrepare I chose to separate

Create and FillPrepare because I already have the TSQLTableJSON object I used to parse the JSON,
and also because I need that object to have the rowcount.

Or is there a better way to get the RowCount?

#5 mORMot 1 » Early binding TSQLTable » 2015-04-27 08:11:06

yankee
Replies: 3

Hi,

I used some parts of this beautiful framework to implement a REST client for our custom server (NOT a mORMot Server).
This server exposes some services as JSON structures.
In short, i used
- TWinHTTP to invoke the services
-_JSONFast to parse the response
- TSQLTableJSON.CreateFromTables([TSQLMyResponseContentMappedRecord], '', MyJsonContent)  to map the response to a TSQLTable made of specific record structures.

So, now I have a MyTable: TSQLTableJSON whose rows can be mapped to TSQLMyResponseContentMappedRecord structures:

type
  TSQLMyResponseContentMappedRecord = class(TSQLRecord)
  private
    fMyFirstField: RawUTF8;
    fMySecondField: Integer;
  published
    property MyFirstField: RawUTF8 read fMyFirstField write fMyFirstField;
    property MySecondField: Integer read fMySecondField write fMySecondField;
  end;

I know I can read it this way, with Late Binding:

var
  CurrentRow: Variant;

while MyTable.Step(False, @CurrentRow) do
begin
  ...CurrentRow.MyFirstField...
  ...CurrentRow.MySecondField...
  ...etc...
end;

Is there a way to read the current row with EARLY binding, so that I'm sure that accessing a CurrentRow.WrongField yelds a compile-time error?

Thank you.

#6 Re: mORMot 1 » HTTP JSON Client for a non-mORMot server » 2015-04-08 13:51:07

Thank you AB,

maybe I was not very clear. The Server part has already been developed, and exposes its services via HTTP.
It handles DB connection and stored procedures on its own.
So I can make an HTTP request with the right parameters and have a JSON response containing data.

My problem is how to implement the CLIENT side, in Delphi:
- Getting the response JSON stream (OK, with Indy HTTP client)
- Parsing the JSON into a...? TSQLTableJSON? ...or what else? I'd like to map to a TSQLRecord or something well defined at compile time, if possible.

#7 mORMot 1 » HTTP JSON Client for a non-mORMot server » 2015-04-08 08:03:17

yankee
Replies: 3

Hi,
I'm trying to get the best from this fantastic mORMot framework but I'm not sure if/how I can push the envelope for my particular case:

I have to modify an existing Delphi7 Client/Server application that currently use ODAC components to connect to an Oracle DB server.
ALL the client DB stuff is made with Stored procedures, so NO CRUD, no direct SQL and just read-only responses.
My company chose to introduce a three-tier architecture and already developed a middleware that exposes the stored procedures as HTTP JSON requests/responses, just like mORMot.
But it's not a mORMot server.

Is there a way to use mORMot, other than the JSON parser, to obtain an efficient and easily scrollable sort of dataset (READ-ONLY)?

I see 3 points, here:
1) The HTTP client: I think I cannot unleash the power of TSQLRest classes because there is no such classes on the other side. No matter, I already implemented a multithread HTTPClient with Indy components;
2) The JSON parsing: I think I can use mORMot JSON parser here;
3) The uni-directional mapping of JSON content to Delphi data Structures;

I feel 2) and 3) can be combined in a powerful way, but I couldn't find that way yet. Or not?

Am I missing something?

Thank you in advance.

Board footer

Powered by FluxBB