#1 mORMot 1 » JSON Deserialization question » 2016-07-18 16:14:09

swierzbicki
Replies: 1

Hello,

I've a issue with TConfiguration class that failed to deserialize.

{$M+}
type
 TConnectionInfos = class(TPersistent)
  private
    FHost: String;
    FPassword: String;
    FPort: string;
    FUsername:String;
 public
   function IsAlive: Boolean;
  published
    property Username:String read FUsername write FUsername;
    property Password:String read FPassword write FPassword;
    property Host:String read FHost write FHost;
    property Port:string read FPort write FPort;
end;
{$M-}

{$M+}
type
 TDBConnectionInfos = class(TConnectionInfos)
 private
   FDatabase: String;
   FProvider: String;
   FQuotedChar: String;
 published
   property Database: String read FDatabase write FDatabase;
   property Provider:String read FProvider write FProvider;
   property QuotedChar: String read FQuotedChar write FQuotedChar;
 end;
{$M-}

{$M+}
type
  { TConfiguration }
  TConfiguration = class(TPersistent)
  private
    class var FSingleton: TConfiguration;
  private
    FLocal: TDBConnectionInfos;
    FRemote: TDBConnectionInfos;
    constructor Init;
    procedure SetLocal(const Value: TDBConnectionInfos);
    procedure SetRemote(const Value: TDBConnectionInfos);
  public
    class function Instance: TConfiguration;
    class destructor DestroyClass;
  published
    property Local: TDBConnectionInfos read FLocal write SetLocal;
    property Remote: TDBConnectionInfos read FRemote write SetRemote;
  end;
{$M-}

TJSONSerializer.RegisterClassForJSON([TConnectionInfos,TDBConnectionInfos,TConfiguration]);

Bellow is the result of a serialization :

{"Local":{"Database":"D:\\Test.DB","Provider":"SQLite","QuotedChar":"","Username":"","Password":"","Host":"","Port":""},"Remote":{"Database":"dd","Provider":"PG","QuotedChar":"\"","Username":"test","Password":"@@","Host":"localhost","Port":"5432"}}

But JSONToNewObject fails to create a new object.

My class inherit from TPersistent, I have added all my classes to RegisterClassForJSON !
What am I missing ?

Ps : my code must works under wince (fpc 3) and android (delphi xe berlin)

#2 Re: mORMot 1 » mORMot Framework cannot be compiled under FPC / Wince platform ! » 2016-07-12 16:13:08

I've a "big" problem, I need to register some of my class (I use a lot of TObjectlist) but  TJSONSerializer is part of Mormot unit that cannot be compiled under Wince platform...

#3 Re: mORMot 1 » mORMot Framework cannot be compiled under FPC / Wince platform ! » 2016-07-12 09:23:40

SynCrossPlattform units are fine.
There is a small issue on the SynCrossPlattformREST unit :

Compiler is seeing an error here :
fOwner.OnLog := {$ifdef FPC}@{$endif}LogToRemoteServerText;

I guess your are using {$MODE Delphi}. Shouldn't {$ifdef FPC}@{$endif} be removed ?

#4 mORMot 1 » mORMot Framework cannot be compiled under FPC / Wince platform ! » 2016-07-04 12:09:50

swierzbicki
Replies: 4

Hello,

Looks like mORMot wasn't designed to be compiled under FPC / Wince platform.
Has anyone successfully modified the sources to make it compatible with WINCE ?

Thank you

#5 Re: mORMot 1 » Access violation when calling JsonToObject » 2016-01-28 12:59:17

I'm working with the trunk version (did a GIT clone this morning).
I'm using Delphi XE 10 Seattle Update 1. Issue on both x32 and x64

#6 Re: mORMot 1 » JSon class Serialization help » 2016-01-28 12:23:48

I guess I'm close to get this working.
My problem was that fields where public instead of published and thus not visible...

  public
    property id: Double read FId write FId;
  published
    property admin: Boolean read FAdmin write FAdmin;
    property fdId: Double read FFdId write FFdId;
    property name: RawUTF8 read FName write FName;
    property societes: TRawUTF8DynArray read FSocietes write FSocietes;
    property User: RawUTF8 read FUser write FUser;

The only issue (and big one) remaining is the impossibility to use my id property (and not mormot internal ID)
I'm fetching my JSON string from an REST service developed with JAVA. I don't have my hands on it. How can I set "id" and how to get "id" in lowercase when getting TSQLRecord JSon string ?

#7 Re: mORMot 1 » Access violation when calling JsonToObject » 2016-01-28 12:05:50

Declaring JSON outside the procedure solved the problem. Is this expected ?

#9 mORMot 1 » Access violation when calling JsonToObject » 2016-01-28 10:50:24

swierzbicki
Replies: 6

Hello,

I'm getting an Access violation when calling JsonToObject.
Exception raise at Unit SynCommons, at function GetJSONField(P: PUTF8Char; out PDest: PUTF8Char; wasString: PBoolean=nil; EndOfObject: PUTF8Char=nil): PUTF8Char;
Line 43205 :         D^ := P^; // 3 stages pipelined process of unescaped chars

Code is really basic :

  TCRMUser = class(TPersistent)
  private
    FAdmin: Boolean;
    FFdId: Double;
    FId: Double;
    FName: RawUTF8;
    FSocietes: TArray<RawUTF8>;
    FUser: RawUTF8;
    // public

  published
    property admin: Boolean read FAdmin write FAdmin;
    property fdId: Double read FFdId write FFdId;
    property id: Double read FId write FId;
    property name: RawUTF8 read FName write FName;
    property societes: TArray<RawUTF8> read FSocietes write FSocietes;
    property User: RawUTF8 read FUser write FUser;
  end;
var
  CRMUser: TCRMUser;
  JSON: RawUTF8;
  IsValidJson: Boolean;
begin
  TJSONSerializer.RegisterClassForJSON([TCRMUser]);
  CRMUser := TCRMUser.Create;
  try
    JSON := '{"admin":false,"fdId":37,"id":17,"name":"Jean-Pierre LeGros","societes":["DODO","DROUAULT"],"User":"jplegros"}';
    JSONToObject(CRMUser, PUTF8Char(JSON), IsValidJson);
    with Memo1 do
    begin
      clear;
      Lines.Add(CRMUser.User);
    end;
  finally
    CRMUser.Free;
  end;
end;

#10 Re: mORMot 1 » JSon class Serialization help » 2016-01-28 10:43:15

So far :

- all String type with RawUTF8 type.
- all extended type replaced with double type.

I did some debugging and found that TSQLRecordFill.AddMap never map as it looks like the column name isn't a valid field !

#11 mORMot 1 » JSon class Serialization help » 2016-01-28 08:22:09

swierzbicki
Replies: 4

Hello,

I need some help with JSon class serialization.
I need to consume data from a Glassfish REST server.

I'm getting such JSon string from one REST GET resource :

{"admin":false,"fdId":37,"id":17,"name":"Jean-Pierre LeGros","societes":["MANGER_SA","BOIRE_SAS"],"user":"jplegros"}

This is how I've created the class :

TUser = class(TSQLRecord)
  private
    FAdmin: Boolean;
    FFdId: Extended;
    FId: Extended;
    FName: String;
    FSocietes: TArray<String>;
    FUser: String;

  public
    property admin: Boolean read FAdmin write FAdmin;
    property fdId: Extended read FFdId write FFdId;
    property id: Extended read FId write FId;
    property name: String read FName write FName;
    property societes: TArray<String> read FSocietes write FSocietes;
    property User: String read FUser write FUser;
  end;

This code return an empty class. ( TUser is has one empty record when modifying the JSon string : '[' + JSON + ']' )

var
  User: TUser;
  JSON : RawUTF8;
begin
  JSON := {"admin":false,"fdId":37,"id":17,"name":"Jean-Pierre LeGros","societes":["MANGER_SA","BOIRE_SAS"],"user":"jplegros"};
  User:= TUser.CreateAndFillPrepare(JSON);
  try
    while User.FillOne do
      begin
        Memo1.Lines.Add('Id : ' + User.id.ToString);
        Memo1.Lines.Add('User Name: ' + User.name);
      end;
  finally
    User.Free;
  end;
end;

What is wrong in my code ?

#12 Re: mORMot 1 » Is this possible with mORMot ? » 2015-09-17 11:11:02

Thank you both of you for your comments.
I'll surely take arnaud's path

#13 mORMot 1 » Is this possible with mORMot ? » 2015-09-15 18:45:58

swierzbicki
Replies: 3

Hello Arnaud,

I have Wince (Lazarus) / Android (Delphi 10) scanners. Scanned data are stored into a local SQLite database. A background thread is running and looking for "Validated" records. Theses records once validated are  sent to an remote PostgreSQL server.
This is well working but I really want to rewrite this using mormot framework.

Does mORMot have such features ? I mean, am I able to "synchronize" both databases the way I'm doing right now ?

Thank you.

Regards,

Stéphane

#15 Re: mORMot 1 » Authenticate example with HTTP remote access (SynDB) » 2014-11-25 20:38:32

Wondefull... Looks like you never sleep Arnaud !
I'll test this tomorrow ... Thank you !

#16 Re: mORMot 1 » Authenticate example with HTTP remote access (SynDB) » 2014-11-25 18:40:00

That would be a great addition and make Authentication "common" to the whole framework

#17 Re: mORMot 1 » Authenticate example with HTTP remote access (SynDB) » 2014-11-25 17:41:35

Thanks, this is well working now :-)

Is there any way to add or remove access to a specific table ? Does TSQLAuthUser and TSQLAuthGroup works with an TSQLDBServerHttpApi ?

#18 Re: mORMot 1 » Authenticate example with HTTP remote access (SynDB) » 2014-11-24 20:18:34

Easy like A.B.C. wink
I'm no more in front my computer but if I remember well, I had EAccessViolation when calling

HttpServer.Protocol.Authenticate.AuthenticateUser('toto2','pipo2');

I'll test this again and report here....

Anyway thank you !

#19 Re: mORMot 1 » Authenticate example with HTTP remote access (SynDB) » 2014-11-24 18:11:08

By default, you will have the binary data transmitted compressed and encrypted over HTTP.
There is nothing to do: this is enabled by default. Disabling it would not make the process faster - certainly the contrary.

Ok, that's enough for my purpose

In shorts: the remote users are NOT the DB users.

That's fine.

The remote TSQLDBSocketConnectionProperties() instances should use a name + password credentials pair which have been registered on the server, using AuthenticateUser/DisauthenticateUser methods of TSQLDBServerAbstract.Protocol.Authenticate.
In fact, there is a first couple of name + password optionally set at TSQLDBServerAbstract.Create(), but the main entry point is TSQLDBServerAbstract.Prototocol.Authenticate.

That is the whole point: authentication is needed when no username and password are passed to TSQLDBServerHttpApi.Create method.
I still have questions : How to add multiple users ? Can this be done from an external source ? (I guess that these information are volatile)

How to set/use AuthenticateUser/DisauthenticateUser methods ?, I've tried this basic code :

Server Side

  Props := TSQLDBUniDACConnectionProperties.Create(
  TSQLDBUniDACConnectionProperties.URI(dPostgreSQL,'localhost'),
  'database', 'User', 'Password');
  HttpServer := TSQLDBServerHttpApi.Create(Props,'root','8080');

  SynAuthentication := TSynAuthentication.Create('toto','pipo'); 
  HttpServer.Protocol.Authenticate := SynAuthentication;

Client side

  fProps := TSQLDBWinHTTPConnectionProperties.Create('localhost:8080', 'root',
    'toto', 'pipo');

But it failed with an authentication error message ! :  'Invalid Credentials - check User and Password'

#20 mORMot 1 » Authenticate example with HTTP remote access (SynDB) » 2014-11-24 16:03:23

swierzbicki
Replies: 12

Hello,

Is there any sample on authentication with HTTP remote access ?
I also like to use any available encryption over HTTP. I don't know where to start (and yes, I've read the documentation wink )

#22 Re: mORMot 1 » Modification needed on SynDBUniDAC » 2014-11-20 10:08:53

I'm using the lastest one 5.5.12
'CharLength' options is available on Oracle and Firebird only.

#23 Re: mORMot 1 » ToDataset produce corrupted data » 2014-11-20 10:04:34

Yes, I'm using the latest version...


I've also an "cosmetic" issue with TTime Fields that are displayed as TDateTime Fields

#24 mORMot 1 » ToDataset produce corrupted data » 2014-11-20 09:24:18

swierzbicki
Replies: 3

Hello AB,

I'm getting weird issue with ToDataset function where produced dataset is corrupted.
Server is connected to a postgresql database using UniDAC library.

When using ToDataset function, string data is corrupted and fields have values from other fields

Here is my server code

  
    Var
    Props: TSQLDBConnectionProperties;
    HttpServer: TSQLDBServerAbstract;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Props := TSQLDBUniDACConnectionProperties.Create(
  TSQLDBUniDACConnectionProperties.URI(dPostgreSQL,'localhost'),
  'db', 'STEPH', 'me');
  HttpServer := TSQLDBServerHttpApi.Create(Props,'root','8080','user','pass' );
end;

Here is my client code

 
    Var
    fProps: TSQLDBConnectionProperties;


procedure TForm2.chkFromSQLClick(Sender: TObject);
var
  proxy: TSQLDBConnectionProperties;
  stmt: TSQLDBStatement;
  Timer: TPrecisionTimer;
begin
  ds1.DataSet.Free;
  Timer.Start;
  proxy := fProps;
  try
    proxy := TSQLDBWinHTTPConnectionProperties.Create('localhost:8080', 'root',
      'user', 'pass');

    stmt := proxy.NewThreadSafeStatement;
    try
      // stmt.Execute('select * from users where "User""=?',['STEPH']);
      stmt.Execute('select * from utilisateurs', true);
      if chkViaTClientDataSet.Checked then
        ds1.DataSet := ToClientDataSet(self, stmt)
      else
        ds1.DataSet := ToDataSet(self, stmt);
    finally
      stmt.Free;
    end;
  finally
    if proxy <> fProps then
      proxy.Free;
  end;
  lblTiming.Caption := 'Processed in ' + Ansi7ToString(Timer.Stop);
end;

#25 mORMot 1 » Modification needed on SynDBUniDAC » 2014-11-20 09:11:31

swierzbicki
Replies: 3

Hello AB,

On unit SynDBUniDAC, you need to remove line 238 :

    fSpecificOptions.Values['CharLength'] := '2';

Unidac PostgreSQL doesn't support this specific option.

#26 Re: mORMot 1 » HTTP remote access for SynDB SQL execution » 2014-11-19 17:46:48

Hello,

I've followed your blog's instruction but I can't get my client connecting on local server !
I've registered my URL thanks to sample 04 - HTTP Client - Server

I'm getting this exception :

Exception 'first chance' à $7553812F. Classe d'exception ESQLDBRemote avec un message 'TSQLDBWinHTTPConnectionProperties.ProcessMessage: Error 503 from http://localhost:8080/'. Processus Client.exe (2948)

Am I missing something ?

#27 Re: mORMot 1 » Is this the right tool for the right job ? » 2014-11-19 13:04:16

All right... I'll check the documentation and I'll try to go this way !

#28 mORMot 1 » Is this the right tool for the right job ? » 2014-11-19 07:37:23

swierzbicki
Replies: 2

Hello,

I'm totally noob with anything related to ORM so this topic could be "Off-Topic" smile

I need to develop a basic application that will print barcodes given a specific order.
I want my application to access an remote service. After a secured authentication, my user will give an Order ID and relevant data will be fetched into the application local SQlite Database.

Remote service will either connect an ODBC database or an PostgreSQL database. UNIDAC library is used.

Is mORMot the right tool for this job ? or am I using an hammer to kill a fly ?

Thank you

Board footer

Powered by FluxBB