You are not logged in.
Pages: 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)
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...
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 ?
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
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
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 ?
Declaring JSON outside the procedure solved the problem. Is this expected ?
@mpv : doesn't helps.
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;
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 !
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 ?
Thank you both of you for your comments.
I'll surely take arnaud's path
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
This will be clean and lean...
Wondefull... Looks like you never sleep Arnaud !
I'll test this tomorrow ... Thank you !
That would be a great addition and make Authentication "common" to the whole framework
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 ?
Easy like A.B.C.
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 !
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'
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 )
@ab : that was my problem ! Thank you
I'm using the lastest one 5.5.12
'CharLength' options is available on Oracle and Firebird only.
Yes, I'm using the latest version...
I've also an "cosmetic" issue with TTime Fields that are displayed as TDateTime Fields
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;
Hello AB,
On unit SynDBUniDAC, you need to remove line 238 :
fSpecificOptions.Values['CharLength'] := '2';
Unidac PostgreSQL doesn't support this specific option.
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 ?
All right... I'll check the documentation and I'll try to go this way !
Hello,
I'm totally noob with anything related to ORM so this topic could be "Off-Topic"
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
Pages: 1