You are not logged in.
As I understand it, he wants the url passed to the HttpGet method to be encoded automatically.
But this would not be correct, because if the url is already encoded it will be encoded twice.
The correct thing is to leave the url encode for the application and not for the HttpGet and related methods.
Recommended versions are:
FPC SVN 45643 (3.2.0)
Lazarus SVN 63526 (2.0.10)
Google suggests the most used term.
But i think that both are correct.
In description itself mentions "out of synch".
Thanks @mpv.
I agree that the cookie cache must be disabled.
I would have problems in some requests if cookies were passed between requests.
Thanks for the improvements!
Just to confirm, about libcurl share interface. I check the code twice and the cookies are not being shared, correct?
It is important that this behavior does not change.
macfly wrote:As described in the documentation, it is not recommended to use late binding in Lazarus / FPC.
Do you have a self contained example that shows custom variants failing (preferrably not depending on mORMot)? I can't reproduce it with a simple example using TInvokableVariantType. If I have a simple example to reproduce it, I can fix it.
I'm not sure if we're talking about the same thing.
But here's an example where calling a function via late binding will fail in FPC.
var
ADoc: Variant;
...
TDocVariant.New(ADoc); //or ADoc := _Json('[]');
ADoc.Add('Some Text'); //<- hereGreat news!
Thanks ab for everything.
Lazarus + FPC to Win32 = All green 47,79s
Lazarus + FPC to Win64 = All green 38,50s
Delphi 10.3 to Win32 = All green 51,47s
Delphi 10.3 to Win64 = All green 46,17s
This is controlled by ResultAsJSONObject and ResultAsJSONObjectWithoutResult options.
In Doc:
https://synopse.info/files/html/Synopse … #TITLE_470
Thanks @okoba and @ab for these tests and improvements.
@okoba any particular reason for using the "aliases" for classes in V2?
Example TSQLRest instead of TRest.
I believe that when using the Daemon all processes must be running inside the daemon.
TSynBackgroundTimer allows you to perform tasks at defined intervals.
As described in the documentation, it is not recommended to use late binding in Lazarus / FPC.
Use TDocVariantData.
You can cast the Variant with TDocVariantData(V).Add ..., or use a TDocVariantData directly.
var
D : TDocVariantData;
V : Variant;
...
D.Init();
D.A_['id'].AddItem(1);
D.A['id'].AddItem(2);
writeln(D.ToJSON()); //'{"id":[1,2]}'
//using with
D.Init();
with D.A_['id']^ do
begin
AddItem(1);
AddItem(2);
end;
writeln(D.ToJSON()); //'{"id":[1,2]}'
//Casting the variant
V := _Json('{id:[]}');
TDocVariantData(V).A['id'].AddItem(1);
TDocVariantData(V).A['id'].AddItem(2);
writeln(VariantSaveJSON(V)); //'{"id":[1,2]}'I tested with the same text you put in the topic and there was no problem.
I saved the text in a file and loaded it into the field with:
ARecord.MyTextField := SynCommons.StringFromFile(ExtractFilePath(ParamStr(0)) + 'text.txt');
ADBRestServer.Insert(ARecord, True);
..retrive then
ADBRestServer.Update(ARecord); Both the insert and the update were successful.
Edit: tested with FPC + Lazarus.
There doesn't seem to be a size limit problem, because:
- This text is not so long.
- You mentioned that you've already saved bigger text without a problem.
- If you remove the "UIDCotacao" parameter, the error does not occur.
I will try to do a test here
Regarding the original question of the post, it seems that there is really no way to do this, since the parser only accepts "array of" simple or record types.
Yes, I thought he could create a custom serialization, but from the way he asked the question it seemed that he only wanted based on text definition.
I believe that via custom serialization is the only option.
And you don't need custom serialization, you can use plain text serialization with the dynamic array.
As I understand he cannot change the structure of JSON.
Via text definition seems that is not possible to obtain the same structure that he expects.
I will test this.
As the database is SQLite I need to check if using as external will not modify any existing behavior.
About of the subject of compatibility and reserved words.
Is there an option to auto escape the name of tables and columns in queries?
For example TSQLOrder will generate "Select ... From ORDER ...."
And will not be accepted without escape in table name.
...
I was just trying to say that reserved word shouldn't be a problem. Probably I just misunderstood something about it, don't mind.
My bad. I forgot to change "AType" in text definition, and thought that mORMot did not support reserved words in decoding.
I tested it now and it works perfectly.
Regarding the original question of the post, it seems that there is really no way to do this, since the parser only accepts "array of" simple or record types.
So "array of array of" will not work.
And "array of TDoubleDynArray" will not be accepted.
macfly wrote:If you cannot modify the json structure, then you will have another problem with the "type" property, which is a reserved word.
Excuse me if I misunderstood smth. Wouldn't &type work then?
It does not work for me. How does the text definition?
'type RawUtf8' shouldn't work?
If you cannot modify the json structure, then you will have another problem with the "type" property, which is a reserved word.
One option is to create a record to store coordinates.
type
TCoordinate = packed record
d1: Double;
d2: Double;
end;
TGeometry = packed record
coordinates: array of TCoordinate;
AType: RawUTF8;
end;
const
__TCoordinate = 'd1 double d2 double';
__TGeometry = 'coordinates array of TCoordinate AType RawUTF8';Register both:
TTextWriter.RegisterCustomJSONSerializerFromText([
TypeInfo(TCoordinate), __TCoordinate,
TypeInfo(TGeometry), __TGeometry
]); JSON produced:
{"coordinates":[{"d1":13.3568,"d2":52.6183},{"d1":0,"d2":52.5581}],"AType":"test"}'Another option is to create a TSQLRestRoutingREST to be used by the service and override the ExecuteSOAByInterface method to handle the error.
Using this approach, I can send a custom error and messagem on an interface-based service.
However, since you want to validate the type of data, it would be best to use method-based services.
Great choices.
The new formatting style is a plus that cannot be omitted. It helps a lot to read and understand.
I have a serious difficulty with if then begin along the same line.
Thanks @ab
I prefer RawUTF8, because it is easy to know the origin of the type.
When looking at the source there is no doubt that it is the type added by mORMot.
What if you protect this method with a lock ... unlock? Perhaps it is a better option.
Anyway I'm terrible at explaining but I hope that makes sense. It's a 1 line fix like before.
Perfectly understood.
The first fix had already worked for me, both in the test project, and in the real application.
This is also working, and it seems in fact the most logical place to put the waitfor.
I hope it also resolves for @mpv.
Update again ...
The fix is working in my real application.
My confusion occurred because with the workarround to remove the servers I was destroying them before the httpserver.
And I forgot to change the order after applying the fix.
But destroying in the correct order, the fix resolved.
FreeAndNil(AHttpServer);
FreeAndNil(AService1);
FreeAndNil(AService2);
...Unfortunately you are correct.
The fix worked with the test project I put in the first post (I checked again and it works).
But with the real application the same error occurs.
For now I will leave the workaround of removing the servers before finalizations of httserver.
So I don't have to modify the SynCrtSock.
AHTTPServer.Shutdown();
while AHTTPServer.DBServerCount > 0 do
AHTTPServer.RemoveServer(AHTTPServer.DBServer[0]); I don't use this feature on Windows, but I use Daemon on Linux.
I had problems, for obvious reasons, when using relative paths in the code (settings files), por example path of db.
The forked application could not find the files, because it was running in another context.
At the moment I still can't use Linux as the main OS.
With WLS2, this is on my list trying to install Ubuntu with GUI support as Windows Subsystem.
Edit:
After upgrading to WSL2, I was able to activate the graphical interface in Ubuntu, and installed FPC + Lazarus with fpcupdeluxe.
At least on my machine the performance was better than via VirtualBox.
For anyone interested:
https://docs.microsoft.com/en-us/window … tall-win10
https://dev.to/darksmile92/linux-on-win … a-rdp-522g
I want to try and solve this but whenever I install fpc+laz stable (fpcupdeluxe) on windows 10 I get this mega delay while debugging with gdb (each line step is 1+ sec delay). I think I solved it once but my main dev is on Linux so I can't remember. Do you guys have this problem?
Edit : For anyone else interested, it got better by going 32bit fpc+laz instead of 64-bit, also gdb from mingw compiler chain seems to have made a bit of difference.
Yes, I had this problem too.
Now I have the win32 version of Laz + FPC.
It gets better.
But sometimes it takes too long, seems that IDE freezes. But come back ... ![]()
Ok. thanks for the info.
Thanks @pvn0, @mpv, @ab for the fix.
@ab GetDBServerCount Shouldn't be protected by a lock .. unlock?
function TSQLHttpServer.GetDBServerCount: integer;
begin
result := length(fDBServers);
end; Some findings:
- As pointed by pvn occurs with httpApi only.
- It is not directly related to the logs, any routine that adds a small delay to EndCurrentThread, such as a writeln will cause the error.
- Maybe it's a race condition problem.
It is difficult to debug. Because the debug itself can prevent the race condition from occurring.
Hi @ab,
I noticed your low frequency on the forum.
I hope you are well.
Take your time, the important thing is to take care of your health.
I wish you well.
I sent a pull request with the workarround to remove the DBServers on Destroy.
Yes, it appears to be specific to the FPC.
Declaring before the same error occurs.
Declaring later avoids the error.
But in the documentation it does not mention a specific place to set the logs. Unless I haven't seen it.
In any case, I believe that removing the services in Destroy from TSQLHttpServer will not break the code and will solve the problem.
Edit: Declaring later also doesn't seem to solve it.
But I'm not sure where exactly you're referring to?
Forcing the addition of the double escape is wrong.
What is the client code to send the request?
There must be something wrong with the code that is not escaping.
Make a test request with the postman or with the Rest Debuger (free tool from Embarcadero).
Converting to variant is necessary if you want easy access to Json values.
Well, as you can see in your first post, the example you provided was missing the double escape. So it was suggested by @EMartin to include. What is right in this case.
If you are sure it is coming with the double escape then I don't know what it can be.
Or are you saying that CTxt.Call.InBody may be removing the double escape at some point?
In any case, I did a test here and it's ok.
See images:
Request sended (with postman)
https://ibb.co/TR3mLXs
Request received (in debug)
https://ibb.co/1Q0wJNq
The double scape must be done by the client.
In other words, in CTxt.Call^.InBody you should already receive with the double scapes.
In your post, you informed that it is arriving without the double scape, so it was suggested to apply the double scape.
...
// the client's application request body looks like this
// {"ToAddress":"someaddress.gmail.com", "Attachment":"c:\photos\photo1.bmp"}
Lazarus + FPC.
Cross compiled -> Win32 -> Win64.
If the logs are active, an exception occurs in fDBServers[0].Server.EndCurrentThread(Sender);
I believe this is due to fLog being seted from the first service added by TSQLHttpServer.Create, and then in Destroy he tries to use this that no longer exists.
constructor TSQLHttpServer.Create(...)..
if high(aServers)<0 then
fLog := TSQLLog else
fLog := aServers[0].LogClass; Workarround: Remove all registred services before server finalization:
AHTTPServer.Shutdown();
while AHTTPServer.DBServerCount > 0 do
AHTTPServer.RemoveServer(AHTTPServer.DBServer[0]);
FreeAndNil(AHTTPServer);For definitive correction, should the HTTPServer Destructor perform this removal?
Or should the logs be initialized otherwise in Create?
Sample project to reprocuce:
@damiand
Please see if this thread applies to your case:
Do not worry.
This was a question I had, but it was explained above.
Leave the default value ForceCacheUpdate = False and it should be OK.
Thanks @mpv
Solved by upgrading libcurl.
PS: Really weird the AV
Lazarus + FPC
Cross compiled Win32 -> Linux64 (CentOS)
I'm having strange behavior when making requests to https.
curl.easy_perform(fHandle) raise an exception.
Same application works fine for http requests.
Curl in comand line works fine for http and https requests
I activate coVerbose to see more info:
* About to connect() to httpbin.org port 443 (#0)
* Trying 52.3.32.149...
* Connected to httpbin.org (52.3.32.149) port 443 (#0)And after that:
An unhandled exception occurred at $00007F08E251ED00:
EAccessViolation: Access violation
$00007F08E251ED00Any tips on what it might be?
It does not seem to be related to a certificate because the Exception would not occur in this case.
And making the request with Curl on the command line is ok.
Thanks @Vitaly
Interesting this solution.
But in relation to the cache.
Will the framewok recognize these updates and update/clear the cache?
This instability in Delphi 7 occurs only when the unit is open?
Or the simple fact of including it in the uses already generates instability?
If you use cnpack there is an option to highlight the words that are in the cursor.
This makes the editor very slow on units with many lines.
There is an option in the cnpack settings to disable this in units with more than x lines. It can help ...
Furthermore, I fully agree to focus mORMo2 on FPC and newer versions of Delphi.
Good infos on this topic.
Subscribed.
...
Ofcourse you could go with a system that registers packaged stuff on a bpl, and automates loading it automatically when the bpl is used, but so far I've never needed it
Now I understand what you mean.
I use packages in an application (which does not use mORMot).
I use both forms, at runtime (for core) and dimamically (plugins).
But the core packages are loaded by the exe, not by bpl.
To create a modular (GUI) application packages are an excellent option without a doubt.
That's why, in my code, mORMot has been moved to dedicated BPL, which is loaded when needed.
When you say you load the mORMOt package when needed, are you saying that load the mormot package dynamically, and not as runtime pakage?