#2 mORMot 1 » ReHash in mormot.db.sql.zeos with PUREMORMOT2 enabled » 2022-01-23 10:19:52

L_VV
Replies: 2

Good afternoon,

When the {$define PUREMORMOT2} is enabled, the mormot.db.sql.zeos unit is not compiled because of TDynArrayHashed.ReHash is not defined.

If we replace fColumn.ReHash call with fColumn.ForceReHash in procedure ExecutePrepared in line 1140, then this unit is compiled successfully.

#3 Re: mORMot 1 » mormot.db.sql.odbc is not compiled with $define PUREMORMOT2 » 2021-05-26 20:16:30

After latest commit all compiled successfully, thank you!

#4 Re: mORMot 1 » mormot.db.sql.odbc is not compiled with $define PUREMORMOT2 » 2021-05-26 15:53:24

Sorry, but I don't see a new version of the mormot.db.sql.odbc unit in the trunk...

I updated to the trunk, but the error still here.

#5 mORMot 1 » mormot.db.sql.odbc is not compiled with $define PUREMORMOT2 » 2021-05-26 09:09:12

L_VV
Replies: 9

Good afternoon!

For a long time I did not update my copy of the mORMot2, today I updated it to the trunk.

With the $define PUREMORMOT2 enabled, the mormot2 package is not compiled:

mormot.db.sql.odbc.pas(1213,8) Error: Identifier not found "TODBCConnectionProperties"
mormot.db.sql.odbc.pas(1216,30) Error: Identifier not found "TODBCConnectionProperties"

This occurs in the lines below:

    if TODBCConnectionProperties(Connection.Properties).SqlStatementTimeoutSec > 0 then
      ODBC.Check(nil, self,
        ODBC.SetStmtAttrA(fStatement, SQL_ATTR_QUERY_TIMEOUT,
          SqlPointer(PtrUInt(TODBCConnectionProperties(Connection.Properties).SqlStatementTimeoutSec)),
          SQL_IS_INTEGER),
        SQL_HANDLE_STMT, fStatement);

This is due to $ifndef PUREMORMOT2 condition check in the type declaration:

{$ifndef PUREMORMOT2}
// backward compatibility types redirections

type
  TODBCConnectionProperties = TSqlDBOdbcConnectionProperties;
  TODBCConnection = TSqlDBOdbcConnection;
  TODBCStatement = TSqlDBOdbcStatement;

{$endif PUREMORMOT2}

If I disable $define PUREMORMOT2, then the mormot2 package is compiled successfully.

#6 mORMot 1 » Could you add commit/rollback calls to the log, as in StartTransaction » 2021-04-10 18:05:20

L_VV
Replies: 0

Good evening,

Arnaud, could you add commit/rollback calls to the log, similar to StartTransaction?


unit mormot.db.sql.zeos

procedure TSqlDBZeosConnection.Commit;
var
  log: ISynLog;
begin
  log := SynDBLog.Enter(self, 'Commit');
  ...

 

procedure TSqlDBZeosConnection.Rollback;
var
  log: ISynLog;
begin
  log := SynDBLog.Enter(self, 'Rollback');
  ...

#7 Re: mORMot 1 » AV after handling exception in intf.-based service when using TSynLog » 2021-03-31 09:34:29

Good morning!

After today's update of mORMot2 to the trunk version, yesterday's second exception no longer occurs on the Lazarus / FPC trunk smile

Thank you very mach!

#8 Re: mORMot 1 » AV after handling exception in intf.-based service when using TSynLog » 2021-03-30 21:13:38

I checked this test example on Lazarus/FPC stable.

Yes, indeed, on this version the second exception does not occurs.
Then we can probably skip this error.

Thank you!

#9 Re: mORMot 1 » AV after handling exception in intf.-based service when using TSynLog » 2021-03-30 18:58:11

Yes, I was also uncomfortable to upload files to google.disk  smile

I created a repository for tests with a project from this topic:

https://github.com/L-VV/fpc_tests.git 

#10 mORMot 1 » AV after handling exception in intf.-based service when using TSynLog » 2021-03-30 14:00:07

L_VV
Replies: 5

I came across an error when using TSynLog and handling exception in the service:

There is a simple Lazarus/FPC console application under Linux, which implements interface-based rest service with one method.


If I add to the application to work with TSynLog

TSynLog.Family.Level := LOG_STACKTRACE + [sllInfo, sllServer];

and if an exception occurs in the service method processing the customer's request, then after correct handling of the exception, another exception (AV) will occur in the astrings.inc file.

If I comment out this line, the second exception does not occurs.


I created the simple reproducible test for this error, but I can not find a reason:
https://drive.google.com/file/d/1wtZEVJ … sp=sharing

Maybe I incorrectly use TSynLog?
But I just took this line from some example, and it works, the log is created.
And for some reason the described problem occurs.

#11 Re: mORMot 1 » New Statics for mORMot » 2021-03-30 08:25:55

All compiled successfully, thank you!

#12 Re: mORMot 1 » Is it possible to change code around OnServiceCreateInstance call? » 2021-03-30 08:24:52

Good morning, Arnaud!

Thanks a lot, this feature works great smile

#13 mORMot 1 » Is it possible to change code around OnServiceCreateInstance call? » 2021-03-29 23:34:51

L_VV
Replies: 2

Arnaud, please take a look - is it possible add increase and decrease a RefCount of the created object before and after calling the OnServiceCreateInstance handler (mormot.soa.server unit, at the end of the TServiceFactoryServer.CreateInstance() method)?

from

  if Assigned(fRestServer.OnServiceCreateInstance) then
    fRestServer.OnServiceCreateInstance(self, result);

  if AndIncreaseRefCount then
    IInterface(result)._AddRef; // allow passing self to sub-methods

to

  IInterface(result)._AddRef;
  if Assigned(fRestServer.OnServiceCreateInstance) then
    fRestServer.OnServiceCreateInstance(self, result);
  dec(TInjectableObjectRest(result).fRefCount);

  if AndIncreaseRefCount then
    IInterface(result)._AddRef; // allow passing self to sub-methods

The difference in the lines 1 and 4 of this code block.

The problem is that when calling an OnServiceCreateInstance handler, the following happens:
- the instance of the created object passed to this method with a RefCount equal to 0;
- when trying in the OnServiceCreateInstance handler to check whether the passed object is implemented the specified interface (like "if supports (instance, isomeinterface, intfvar) then ..."), the object's RefCount increases by 1 and becomes equal to 1;
- when exiting from OnServiceCreateInstance handler, the object's RefCount decreases by 1 and becomes equal to 0;
- the object is destroyed;
- then in the last line of the TServiceFactoryServer.CreateInstance() method (IInterface (result) ._ addref) occurs AV, because the object is already destroyed.


If increase the object's RefCount by 1 before entering into the OnServiceCreateInstance handler, then the object will pass into the OnServiceCreateInStance handler with a RefCount equal to 1, then it will increase to 2, and then it will decrease to 1, and at the end the object will not be released.
After returning from OnServiceCreateInstance handler, the object's RefCount will be decreased to the initial value.

If in the OnServiceCreateInstance handler there will be no operations that change the value of the object's RefCount, then everything must also be good.


That is, I do not want to explicitly specify an object class, as in the example to the OnServiceCreateInstance (code is slightly changed):

procedure TAppSrvCore.RestSrvDB_OnCreateInstance(Sender: TServiceFactory; Instance: TInterfacedObject);
begin
  if TServiceFactoryServer(Sender).ImplementationClass = TSomeService then
    begin
      ...
      TSomeService(Instance).DBConnection := Connection;
    end;
end;

Instead, I want to use an interface that all the classes of services will implement, and in the OnServiceCreateInstance handler I will check whether the created object implements this interface:

procedure TAppSrvCore.RestSrvDB_OnCreateInstance(Sender: TServiceFactory; Instance: TInterfacedObject);
var
  intf: ISomeService;
begin
  if Supports(Instance, ISomeService, intf) then <-- inc RefCount
    begin
      ...
      intf.SetConnection(Connection);
    end;
end;  <-- dec RefCount

I tried to change the code in this way, and such approach is worked for me.

Maybe I did not consider something and this is something unsafe or incorrect?
Or is it in general a bad idea?

#14 Re: mORMot 1 » New Statics for mORMot » 2021-03-29 21:09:00

And I just installed again libdeflate-dev.

After changing the file name in mORMot to libdeflatepas.a, everything is also compiled without problems.

Great!

#15 Re: mORMot 1 » New Statics for mORMot » 2021-03-29 20:52:30

AOG wrote:

I guess L_VV compiles with FPC trunk.
https://synopse.info/forum/viewtopic.ph … 542#p34542

Exactly, I compiled in the Lazarus / FPC trunk.


After replacement

    if not Assigned(OnMatch) or
       (not Assigned(KeyCompare) and
        not Assigned(ValueCompare)) then
      exit;

to

    if not Assigned(OnMatch) or
        (not (Assigned(KeyCompare) or
        Assigned(ValueCompare))) then
      exit;

everything was compiled successfully.

Thank you very much, AOG!
And where can I read, what change in fpc was done?

Arnaud, could it be possible to change this block in the mORMot2 trunk?

#16 Re: mORMot 1 » New Statics for mORMot » 2021-03-29 15:55:34

I updated mORMot2 to the current trunk, downloaded the latest static libraries, opened the mormot2 package in Lazarus IDE, and tried to compile it.
mormot.core.json unit does not compile with an error:
Wrong number of parameters specified for call to "<Procedure Variable>"


function TSynDictionary.ForEach(const OnMatch: TOnSynDictionary;
  KeyCompare, ValueCompare: TDynArraySortCompare; const aKey, aValue;
  Opaque: pointer): integer;
var
  k, v: PAnsiChar;
  i, n, ks, vs: PtrInt;
begin
  fSafe.Lock;
  try
    result := 0;
    if not Assigned(OnMatch) or
       (not Assigned(KeyCompare) and          <---
        not Assigned(ValueCompare)) then      <---
      exit;
mormot.core.json.pas(9345,32) Error: Wrong number of parameters specified for call to "<Procedure Variable>"
mormot.core.json.pas(9346,34) Error: Wrong number of parameters specified for call to "<Procedure Variable>"

#18 Re: mORMot 1 » New Statics for mORMot » 2021-03-29 09:35:13

Good afternoon!

ab wrote:

Are you sure your project options point to our folder /static/x86_64-linux for its dependencies?

My project contains the mormot2 package in the requirements.
In the mormot2' package options, the path to the libraries (_FL) is specified as follow:
../../static/$(TargetCPU)-$(TargetOS)


ab wrote:

@L_VV
I don't see how a *.a library may be used for the system at runtime.
This is a dev library, used only when compiling/linking a project.
On debian, it is e.g. the https://packages.debian.org/sid/libdeflate-dev package which includes it IIRC

Yes, you, of course, right - the libdeflate-dev package is not used at runtime.
I did not quite correctly wrote - I installed it when I builded a some application.
I can delete it, but if it needs to be needed again, it will have to be installed again.
In general, a small problem.

I checked it - after removing libdeflate-dev, indeed, mORMot2 compiled successfully.
After re-installing libdeflate-dev, mORMot2 again stopped compiled.
As a result, I deleted libdeflate-dev, as long as it is needed again.

However, it is still not clear why Lazarus/fpc is looking for all such libraries in the system, if the library already found in the directory, specified in the package options.
But since libdeflate-dev is not needed constantly, we can assume that everything is fine, and on most systems this error will not occurs.

#19 Re: mORMot 1 » New Statics for mORMot » 2021-03-28 17:39:19

ab wrote:

I am not able to reproduce it here with FPC 3.2.0 - not trunk.

I just checked on my stable version of Lazarus/fpc (2.0.12 / 3.2.0).
When I doing "Run / Clean up and Build..." occurs exactly the same error.


ab wrote:

We provide our own libdeflate.a version in the static/x86_64-linux folder.
Perhaps there is a conflict on your machine with the libdeflate.a installed on the system path using apt.

Yes, it is clear that this is due to the conflict with the system library.
It is not clear how to fix it.
I can not remove libdeflate system library, it is used by the OS itself.


To reproducing the error, it is enough to create a new console application in the Lazarus, and add to "uses", for example, the "mormot.orm.core" unit.
After that, we need to do "Run / Clean Up and Build ...", and if the designated libraries conflict is in the system, we will get the such error.
I tried to add the "mormot.core.base" unit to "uses", but in this case the error does not occur - likely libdeflate is not used in this case.

#20 Re: mORMot 1 » New Statics for mORMot » 2021-03-28 12:03:01

Good afternoon,

Today I updated mORMot2 to the latest trunk version and downloaded new static libraries.
After that, when I open in Lazarus a project using mORMot2, and do "Clean up and Build...", two link errors occurrs:

multiple definition of `libdeflate_malloc'
multiple definition of `libdeflate_free'
Verbose: Linking /home/data/projects/TestAppSrv/appsrv.console

Warning: linker: /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libdeflate.a(utils.o): in function `libdeflate_malloc':
Error: (.text+0x30): multiple definition of `libdeflate_malloc'; /home/data/projects/TestAppSrv/dependencies/fpc_components/3rd_party/mORMot2/packages/lazarus/lib/x86_64-linux/mormot.lib.z.o:/home/data/projects/TestAppSrv/dependencies/fpc_components/3rd_party/mORMot2/packages/lazarus//../../src/lib/mormot.lib.z.pas:928: first defined here

Warning: linker: /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libdeflate.a(utils.o): in function `libdeflate_free':
Error: (.text+0x40): multiple definition of `libdeflate_free'; /home/data/projects/TestAppSrv/dependencies/fpc_components/3rd_party/mORMot2/packages/lazarus/lib/x86_64-linux/mormot.lib.z.o:/home/data/projects/TestAppSrv/dependencies/fpc_components/3rd_party/mORMot2/packages/lazarus//../../src/lib/mormot.lib.z.pas:934: first defined here

appsrv.console.lpr(174,1) Error: Error while linking
appsrv.console.lpr(174,1) Verbose: There were 1 errors compiling module, stopping
Verbose: Compilation aborted
Verbose: /opt/fpcupdeluxe/lazarus_trunk/fpc/bin/x86_64-linux/ppcx64 returned an error exitcode

As a result, mORMot2 is not compiled: (


OS: SMP Debian 5.10.19-1 (2021-03-02) x86_64 GNU/Linux
Lazarus/fpc: 2.1.0 / 3.3.1 (trunk)
locate libdeflate.a
/usr/lib/x86_64-linux-gnu/libdeflate.a

#21 Re: mORMot 1 » FPC: cannot compile mORMot2 and ZeosLib when using each other » 2021-03-07 12:58:57

Arnaud, now everything compiles without errors smile

Through FPCupDeluxe, Lazarus is successfully updated to the trunk version.

The full "Clean Up and Build" is also executed without errors, even with an open project using mORMot2.

Thank you very much!

#22 Re: mORMot 1 » FPC: cannot compile mORMot2 and ZeosLib when using each other » 2021-03-06 23:00:51

Good Morning!

I just wanted to update Lazarus / FPC through FPCUPDeluxe, but got the same error, as I showed early.
Repeated attempt was also completed with the same error:
/lib/zdbc/x86_64-linux/mormot.core.datetime.ppu:mormot.core.datetime.pas(13,101) Fatal: (10022) Can't find unit mormot.core.datetime used by mormot.core.text

fpcupdeluxe: info: LazarusNativeInstaller (GetModule: Lazarus): Lazarus was at revision: 64666
fpcupdeluxe: info: LazarusNativeInstaller (GetModule: Lazarus): Lazarus is now at revision: 64760
fpcupdeluxe: info: Lazarus native builder: Detected source version Lazarus: 2.1.0
fpcupdeluxe: info: Lazarus native builder: Using FPC compiler with version: 3.3.1
fpcupdeluxe: Start of compile error summary.
/lib/zdbc/x86_64-linux/mormot.core.datetime.ppu:mormot.core.datetime.pas(13,101) Fatal: (10022) Can't find unit mormot.core.datetime used by mormot.core.text
(10028) Recompiling mormot.core.datetime, checksum changed for ./lib/zdbc/x86_64-linux/mormot.core.text.ppu
fpcupdeluxe: Start of compile error summary.
Fatal: (1018) Compilation aborted
./lib/zdbc/x86_64-linux/mormot.core.datetime.ppu:mormot.core.datetime.pas(13,101) Fatal: (10022) Can't find unit mormot.core.datetime used by mormot.core.text
fpcupdeluxe: Start of compile error summary.
Error: /opt/fpcupdeluxe/lazarus_trunk/fpc/bin/x86_64-linux/ppcx64 returned an error exitcode
fpcupdeluxe: Start of compile error summary.
Error: (lazarus) Compile package zcomponent 8.0: stopped with exit code 1

I used last trunk versions of the mORMot2 and ZeosLib.

The update was completed successfully only after I temporarily disabled the MORMOT2 define in the ZeosLib.



After the update Lazarus/FPC, I enabled the MORMOT2 define again, and tried to compile sequentially ZeosLib and mORMot2.

The zcomponent package compiled successfully, but when compiling the mormot2 package there was a strange error:
mormot.soa.core.pas(1302,40) Error: Compilation raised exception internally
Error: An unhandled exception occurred at $000000000076E5B8:
Error: EAccessViolation: Access violation

...
mormot.rest.core.pas(3352,63) Hint: Variable "ContentType" of a managed type does not seem to be initialized
mormot.rest.core.pas(3363,13) Note: Call to subroutine "function IdemPChar(p:PUtf8Char;up:PChar):Boolean;" marked as inline is not inlined
mormot.rest.core.pas(3376,13) Note: Call to subroutine "function IdemPChar(p:PUtf8Char;up:PChar):Boolean;" marked as inline is not inlined
mormot.rest.core.pas(3988,26) Hint: Local variable "newOffset" of a managed type does not seem to be initialized
mormot.rest.core.pas(47,3) Hint: Unit "mormot.core.search" not used in mormot.rest.core
Verbose: Compiling /home/data/projects/TaskMachine/dependencies/fpc_components/3rd_party/mORMot2/src/soa/mormot.soa.core.pas
mormot.soa.core.pas(1302,40) Error: Compilation raised exception internally
Error: An unhandled exception occurred at $000000000076E5B8:
Error: EAccessViolation: Access violation
Verbose: Compilation aborted
Debug:   $000000000076E5B8
Debug: 
Verbose: /opt/fpcupdeluxe/lazarus_trunk/fpc/bin/x86_64-linux/ppcx64 returned an error exitcode

After the second try to compile the mormot2 package, another error occurred:
mormot.soa.core.pas(1302,39) Error: Incompatible type for arg no. 1: Got "TServiceContainer", expected "Options"

Verbose: Compiling mormot2.pas
Verbose: Compiling /home/data/projects/TaskMachine/dependencies/fpc_components/3rd_party/mORMot2/src/soa/mormot.soa.core.pas
mormot.soa.core.pas(1302,39) Error: Incompatible type for arg no. 1: Got "TServiceContainer", expected "Options"
mormot.rest.core.pas(1994,17) Hint: Found declaration: ServicesRelease(Options);
mormot.soa.core.pas(1394,20) Hint: Variable "bits" does not seem to be initialized
mormot.soa.core.pas(1404,44) Hint: Local variable "method" of a managed type does not seem to be initialized
mormot.soa.core.pas(1510,21) Hint: Variable "Services" of a managed type does not seem to be initialized
mormot.soa.core.pas(1522,18) Hint: Variable "Names" of a managed type does not seem to be initialized
mormot.soa.core.pas(1537,47) Hint: Local variable "temp" does not seem to be initialized
mormot.soa.core.pas(1782,25) Hint: Local variable "nfo" of a managed type does not seem to be initialized
mormot.soa.core.pas(1834,0) Verbose: There were 1 errors compiling module, stopping
Verbose: Compilation aborted
Verbose: /opt/fpcupdeluxe/lazarus_trunk/fpc/bin/x86_64-linux/ppcx64 returned an error exitcode

It looks like this issue is not related to the problem under discussion, but it is occurred when recompiling the mormot2 package.


Full "Clean Up and Build" in the Lazarus with an open project using Mormot2 leads to the same error as before (Can't find unit mormot.core.datetime used by mormot.core.text).
With a new empty project "Clean Up and Build" is successful.

It's all so inconveniencly...

Arnaud, may be you will have time to look at the possibility of removing dependency between mormot.core.datetime and mormot.core.text?

#23 Re: mORMot 1 » FPC: cannot compile mORMot2 and ZeosLib when using each other » 2021-03-04 08:17:16

Arnaud, I tried more variants.

It turned out that if you close the current project, and create a new project, then "Clean Up and Build" is performed correctly.


If the current project is re-open, and run "Clean up and Build", then when compiling an error from my previous message occurs.

In dependencies, the project has the mormot2 package.
In addition, there are uses mormot.xxx.yy in the project files.

Apparently, because of this, an error appears.
In fact, triple circular references appears - mormot2 uses zeoslib; zeosLib uses mormot2; the Lazarus project uses mormot2.

But we can't get rid of uses mormot.xxx.yyy in the project, because for this mormot2 was included in the project.


Arnaud, maybe it could be in mORMot2 to do for ZeosLib a certain wrapper unit that will include both mormot.core.datetime and mormot.core.text?

Then ZeosLib in it uses can specify this unit instead of mormot.core.datetime and mormot.core.text, and possibly cyclic dependency will disappear, because in addition to ZeosLib, no one will use this module, and error "mormot.core.datetime.pas(120,34) Fatal: Can't find unit mormot.core.datetime used by mormot.core.text" will disappear too?

Or maybe there is some other solution.

#24 mORMot 1 » FPC: cannot compile mORMot2 and ZeosLib when using each other » 2021-03-03 23:34:30

L_VV
Replies: 6

Good Morning!

I can't compile both mormot2 and zeoslib package at the same time, in the case when in the mormot2.lpk 'NOSYNDBZEOS' is _undefined_, and in the zeoslib/src/Zeos.inc 'MORMOT2' is _defined_.
Those mORMot2 wants to use ZeosLib, and vice versa, ZeosLib wants to use mORMot2.
zcomponent package added into the mormot2 package.

When compiling the zdbc package, the ZDbcIntfs unit requires the mormot.core.base unit.
I add into the zdbc package the mormot.core.base.pas file and the mormot2/src/core directory.

Next, the same happens with the unit mormot.db.core.
I add into the zdbc package the mormot.db.core.pas file and the mormot2/src/db directory.

zdbc package is compiled successfully.


Next I compile the mormot2 package.
mormot.db.sql.zeos unit requires the Zeos.inc file.
I add into the package mormot2 (Options / Compiler Options / Paths / Include Files) the zeoslib/src directory.
After that, the mormot2 package is compiled successfully.


It seems that everything is fine, but when I trying to do in Lazarus "Run / Clean Up and Build ...", I get the error:

"mormot.core.datetime.pas(120,34) Fatal: Can't find unit mormot.core.datetime used by mormot.core.text"

Verbose: Compiling zcomponent.pas
Verbose: Compiling /home/data/projects/TestApp/dependencies/fpc_components/3rd_party/zeoslib/src/component/ZAbstractConnection.pas
Verbose: PPU Loading ./lib/zdbc/x86_64-linux/mormot.core.datetime.ppu
Verbose: PPU Source: mormot.core.datetime.pas not found
Verbose: PPU Source: ../mormot.defines.inc not available
Warning: Recompiling mormot.core.datetime, checksum changed for ./lib/zdbc/x86_64-linux/mormot.core.text.ppu
mormot.core.datetime.pas(120,34) Fatal: Can't find unit mormot.core.datetime used by mormot.core.text
Verbose: Compilation aborted
Verbose: /opt/fpcupdeluxe/lazarus_trunk/fpc/bin/x86_64-linux/ppcx64 returned an error exitcode

I can not understand how to fix this situation.
Perhaps the problem in circular references between Mormot2 and Zeoslib packages.
I have surpassed many ways, but I haven't succeeded yet.
This error appears constantly when run "Clean up and Build".

And since the Lazarus IDE rebuild occurs when installing any new component, it is critical...

#25 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-03-01 12:06:06

Can't figure out why SYSTEMINLINE, defined in .../fpcsrc.rtl/inc/systemh.inc:

{ Using inlining for small system functions/wrappers }
{$inline on}
{$define SYSTEMINLINE}

works in this file (for example, on this line the word 'inline' is in bold black, i.e. enabled),
and in other files it doesn't work?:

Function  Lo(B: Byte):Byte;{$ifdef SYSTEMINLINE}inline;{$endif}


For example, in a freshly created project I write:

  {$ifdef SYSTEMINLINE}
    writeln('SYSTEMINLINE defined');
  {$endif}

and here the line "writeln('SYSTEMINLINE defined');"
highlighted in pale color, i.e. SYSTEMINLINE is not defined, and this line is not executed.

Perhaps the environment somehow influences?
CPU: AMD Ryzen 7 2700X
OS: Debian 5.10.13-1 (2021-02-06) x86_64 GNU/Linux


Maybe someone else knows why the SYSTEMINLINE, defined in the .inc file, does not work?

#26 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-03-01 09:06:38

EgonHugeist wrote:

According the WITH_INLINE define: It's defined in ZeosLazarus.Inc for FPC see:

{$IFDEF SYSTEMINLINE} //global FPC define
  {$DEFINE WITH_INLINE}           // compiler supports inline methodes
{$ENDIF}

seems the global define proposed by FPC-core seems to be unavailable? Can you confirm it?


It’s strange. In the file .../fpcsrc/rtl/inc/systemh.inc
there are lines:

{ Using inlining for small system functions/wrappers }
{$inline on}
{$define SYSTEMINLINE}

But at the same time, opening the file .../zeoslib/src/ZeosLazarus.inc

{$IFDEF SYSTEMINLINE} //global FPC define
  {$DEFINE WITH_INLINE}           // compiler supports inline methodes
{$ENDIF}

I see the line {$DEFINE WITH_INLINE} in a pale color, i.e. as if SYSTEMINLINE is not defined.

I'll see this in more details later.

#27 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-03-01 08:25:25

Oh, sorry, with last versions of mORMot2 and Zeos all works fine.

Thank you!

#28 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-03-01 08:19:50

Arnaud, yesterday I wrote that after the last commit in git, my test rest service stopped working.
It started returning error 400 - bad request.
After replacing the mormot.rest.core.pas file with its previous version, the error gone.

As I can see, the sequence of calling destructors has changed:

old:

FreeAndNil(fRun);
FreeAndNil(fServices);
for cmd := Low(cmd) to high(cmd) do
  FreeAndNil(fAcquireExecution[cmd]); // calls fOrmInstance.OnEndThread

new:

for cmd := Low(cmd) to high(cmd) do
  FreeAndNil(fAcquireExecution[cmd]); // calls fOrmInstance.OnEndThread
FreeAndNil(fServices);
FreeAndNil(fRun); // after fAcquireExecution+fServices

With the new sequence of destructors, the method (GetUsr) declared in the interface is not called:

  IUsrService = interface(IInvokable)
    ['{64CDE670-5D34-4050-B0E6-36A21F0C21CE}']
    function GetUsr(const ID: RawUTF8; out Usr: TUsrDto): TCQRSResult;
  end;

#29 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-02-28 19:16:26

ab wrote:

I tried to include all @Michael proposals in this new commit:
https://github.com/synopse/mORMot2/comm … 0af2cacc39

Arnaud, the current trunk version of mORMot2 returns error 400 - bad request.

If I go back to a previous version of mormot.rest.core, everything works fine.

#30 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-02-28 11:58:57

Yes, after I forcibly enabled the WITH_INLINE define, Zeos compiled successfully,
only about 30 warnings were issued that the functions was not inline:

mormot.core.datetime.pas(1027,13) Note: Call to subroutine "function Iso8601ToDateTimePUtf8Char(P:PUtf8Char;L:LongInt=`0`):Double;" marked as inline is not inlined
mormot.core.datetime.pas(1294,9) Note: Call to subroutine "function VariantToUtf8(const V:Variant;var Text:UTF8String):Boolean;" marked as inline is not inlined
mormot.core.datetime.pas(1323,7) Note: Call to subroutine "procedure TSynSystemTime.Clear;" marked as inline is not inlined
mormot.core.datetime.pas(1693,5) Note: Call to subroutine "function UInt2DigitsToShortFast(Value:Byte):ShortString[4];" marked as inline is not inlined
mormot.core.datetime.pas(1694,5) Note: Call to subroutine "function UInt4DigitsToShort(Value:LongWord):ShortString[4];" marked as inline is not inlined
mormot.core.datetime.pas(1875,33) Note: Call to subroutine "function UInt3DigitsToShort(Value:LongWord):ShortString[4];" marked as inline is not inlined

#31 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-02-28 10:57:59

Looked at the Zeos.inc file
It turns out that in order for Zeos to compile, you need to include the WITH_INLINE definition in addition to MORMOT2?

{$IFDEF MORMOT2}
mormot.db.core, mormot.core.datetime, {$IFDEF WITH_INLINE}mormot.core.text,
mormot.core.base,{$ENDIF}
{$ELSE MORMOT2} {$IFDEF USE_SYNCOMMONS}
SynCommons, SynTable,
{$ENDIF USE_SYNCOMMONS} {$ENDIF MORMOT2}

Then the following lines will compile normally:

then JSONWriter.AddJSONEscape(P, ZDbcUtils.GetAbsorbedTrailingSpacesLen(P, {$IFDEF MORMOT2}mormot.core.base{$ELSE}SynCommons{$ENDIF}.StrLen(P)))

then {$IFDEF WITH_COLUMNS_TO_JSON}{$IFDEF MORMOT2}mormot.core.text{$ELSE}SynCommons{$ENDIF}.{$ENDIF}HexToBin(Buffer+2, @Result.D1, SizeOf(TGUID))

Under fpc I see that define (WITH_INLINE) is not defined...

#32 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-02-28 10:27:57

EgonHugeist wrote:

According the defines:
You can NOT mix the USE_SYNCOMMONS and the MORMOT2 define.

This is clear. But as I wrote, I tried to enable only the MORMOT2 define, and Zeos couldn't compile.
Therefore, just to test compilation, I have included USE_SYNCOMMONS as well.
The errors still remained, I showed them in the previous message.


Now, after updating the Zeos to the current trunk, if I enable the MORMOT2 define, other compilation errors occur, e.g.:

unit ZDbcPostgreSqlResultSet:

then JSONWriter.AddJSONEscape(P, ZDbcUtils.GetAbsorbedTrailingSpacesLen(P, {$IFDEF MORMOT2}mormot.core.base{$ELSE}SynCommons{$ENDIF}.StrLen(P)))
ZDbcPostgreSqlResultSet.pas(798,134) Error: Identifier not found "base"
ZDbcPostgreSqlResultSet.pas(909,134) Error: Identifier not found "base"

then {$IFDEF WITH_COLUMNS_TO_JSON}{$IFDEF MORMOT2}mormot.core.text{$ELSE}SynCommons{$ENDIF}.{$ENDIF}HexToBin(Buffer+2, @Result.D1, SizeOf(TGUID))
ZDbcPostgreSqlResultSet.pas(1949,71) Error: Identifier not found "text"


const PGOidLopOpenMode: Array[TZLobStreamMode] of Integer = (INV_READ or INV_WRITE, INV_WRITE, INV_READ or INV_WRITE);
ZDbcPostgreSqlResultSet.pas(2870,83) Error: Illegal expression
ZDbcPostgreSqlResultSet.pas(2870,117) Error: Illegal expression

Maybe this is due to the units names with dots in functions calls under fpc?
Although on an fpc trunk this should work...

then JSONWriter.AddJSONEscape(P, ZDbcUtils.GetAbsorbedTrailingSpacesLen(P, SynCommons.StrLen(P))) ==> was changed to:
then JSONWriter.AddJSONEscape(P, ZDbcUtils.GetAbsorbedTrailingSpacesLen(P, {$IFDEF MORMOT2}mormot.core.base{$ELSE}SynCommons{$ENDIF}.StrLen(P)))

then {$IFDEF USE_SYNCOMMONS}SynCommons.{$ENDIF}HexToBin(Buffer+2, @Result.D1, SizeOf(TGUID)) ==> was changed to:
then {$IFDEF WITH_COLUMNS_TO_JSON}{$IFDEF MORMOT2}mormot.core.text{$ELSE}SynCommons{$ENDIF}.{$ENDIF}HexToBin(Buffer+2, @Result.D1, SizeOf(TGUID))

Perhaps the same could be in other units affected.


Also the unit mormot.db.sql.zeos uses unit ZURL, but it is missing in the package ZComponent, so I added it manually.

#33 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-02-27 22:37:48

ab wrote:

So in mORMot there is FirstDbcIndex = 1 but in Zeos, GENERIC_INDEX expects 0-based indexes...

Why is GENERIC_INDEX defined?
AFAICT in Zeos.inc this GENERIC_INDEX is NOT defined by default.

Did you change something?
Our code expects the default undefined GENERIC_INDEX.


No, I did not changed anything.
Just cloned a fresh Zeos copy from git, and Zeos.inc contains:

{.$DEFINE ZEOS_TEST_ONLY}
{$DEFINE GENERIC_INDEX}       <== defined
{.$DEFINE DISABLE_ZPARAM}
//common compilation directives
{$DEFINE ZEOS72UP}
{$DEFINE ZEOS73UP}
{$DEFINE ZEOS80UP}
...
{.$DEFINE USE_SYNCOMMONS} //enable JSON content support by using SynCommons.pas from Synopse project v1.18
{.$DEFINE MORMOT2} //enable JSON content support by using mormot.db.core.pas from Synopse project v2+
...
ab wrote:

I just committed something which "may" fix your problem.

Thank you, Arnaud, this fix worked smile
Stuff with ZeoIndex = {$ ifdef GENERIC_INDEX} 0 {$ else} 1 {$ endif}; will always allow such code to work correctly.
I tried run my test app with last trunk of mORMot2, no exceptions anymore smile


============
Also I tried to enable define MORMOT2 in Zeos.
But if I not enable define USE_SYNCOMMONS togeher with MORMOT2, then the unit ZDbcResultSet is not compiled because of that condition:

{$IFDEF USE_SYNCOMMONS}
const
  JSONBool: array[Boolean] of ShortString = ('false', 'true');
{$ENDIF USE_SYNCOMMONS}

Maybe both of these definitions should be used in the condition at once?
{$IFDEF MORMOT2} or {$IFDEF USE_SYNCOMMONS}

============
After that the compiler found a few incompatible types in ZDbcODBCResultSet.pas (and may be in other files), e.g.

JSONWriter.AddCurr64(ODBCNumeric2Curr(fColDataPtr)); -- Error: Incompatible type for arg no. 1: Got "Currency", expected "PInt64"
JSONWriter.Add(PGUID(fColDataPtr)^); -- Error: Incompatible type for arg no. 1: Got "TGuid", expected "PGuid"

and some identifiers not found, e.g.:

JSONWriter.AddNoJSONEscape(@JSON_SQLDATE_MAGIC_QUOTE_VAR,4) -- Error: Identifier not found "JSON_SQLDATE_MAGIC_QUOTE_VAR"

JSON_SQLDATE_MAGIC_QUOTE_VAR is declared in SynCommon from mORMot version 1, but in mORMot2 it's not defined.
And if I have only mORMot2 installed, than the app is not compiled.

And even I have mORMot v1 installed and added to search path in Zeos package,
but at the same time USE_SYNCOMMONS is not defined, than corresponding units are not available for Zeos:

  {$IFDEF MORMOT2}
  mormot.db.core, mormot.core.datetime,
  {$ELSE MORMOT2} {$IFDEF USE_SYNCOMMONS}
  SynCommons, SynTable,
  {$ENDIF USE_SYNCOMMONS} {$ENDIF MORMOT2}

============

So I had to turn off both of these defines for now...

#34 Re: mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-02-27 15:58:48

It is difficult to tell right away which of the two libraries the issue is in.

On the one hand, an exception occurs in ZeosLib, but on the other hand, an invalid column index = 1 is passed to the TZAbstractResultSetMetadata.GetColumnLabel () function from the TSqlDBZEOSStatement.ExecutePrepared() function of the mormot.db.sql.zeos unit.

The query 'select current_timestamp from rdb$database' returns one column whose index in the TStringList must be 0.
This query initiated by mORMot, not Zeos:

mormot.db.sql:  line 6562 - TSqlDBConnection.Connect()
                line 6572 - fServerTimestampAtConnection := ServerDateTime;

                line 6658 - TSqlDBConnection.GetServerDateTime: TDateTime;
                line 6667 - with Execute(fSqlGetServerTimestamp, []) do

                line 3098 - fSqlGetServerTimestamp := DB_SERVERTIME[db];
                line  400 - DB_SERVERTIME: array[TSqlDBDefinition] of RawUtf8 = (
                            ..., 'select current_timestamp from rdb$database', ...);


As we can see, TSqlDBZEOSStatement.ExecutePrepared() calls fResultInfo.GetColumnLabel() with parameter = 1:
                                   ...
mormot.db.sql.zeos:    line 1144 - fResultInfo := fResultSet.GetMetadata;
                                   n := fResultInfo.GetColumnCount;
                                   fColumn.Capacity := n;
                                   for i := 0 to n - 1 do
                                     begin
                       line 1149 -     name := fResultInfo.GetColumnLabel(i + FirstDbcIndex);
                                                                          ^^^^^^^^^^^^^^^^^
                                       HERE i = 0, FirstDbcIndex = 1,
                                       THEREAFTER IN TZAbstractResultSetMetadata.GetColumnLabel()
                                       PASSED VALUE = 1
                                       ...
                                     end;


ZDbcResultSetMetadata: line  641 - TZAbstractResultSetMetadata.GetColumnLabel(ColumnIndex: Integer): string;
                       line  692 -   if FColumnsLabelsCS = nil then
                                       FillListAndMakeUnique;
         EXCEPTION ==> line  694 -   Result := ColumnsLabels[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}];
                                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                       $GENERIC_INDEX IS DEFINED,
                                       THEREFORE IN FACT WE ARE TRYING TO GET A TStringList ITEM WITH INDEX = 1,
                                       THEREFORE THERE IS AN EXCEPTION List index (1) out of bounds
                                                                                     
Project Test Application Server raised exception class 'EStringListError' with message:
List index (1) out of bounds
In file '../../src/dbc/ZDbcResultSetMetadata.pas' at line 694:
Result := ColumnsLabels[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}];


I made another, a very simple fpc example (console app) to reproduce this error.
The database can either be created with my script, or simply you can specify the path to another Firebird 4 database and correct the query in the project.

After starting the application from the IDE, the 'List index (1) out of bounds' exception will occur and you can see everything in the debugger.

Below is a link to the test example:
https://drive.google.com/file/d/1myazV8 … sp=sharing

#35 mORMot 1 » mORMot2: List index out of bounds in ZDbcResultSetMetadata.pas » 2021-02-26 10:53:34

L_VV
Replies: 20

Good afternoon,

I started learning mORMot2, and I adapted the example from the article
https://tamingthemormot.wordpress.com/2 … databases/

Almost everything worked, but at the last stage, after connecting to the database, when receiving the current time from the server, an exception in ZDbcResultSetMetadata.pas occurs (called from mormot.db.sql --> mormot.db.sql.zeos).
This is not my select, but the select from the mORMot code (select current_timestamp from rdb$database).
I can't figure out what I'm doing wrong, or may be this is a bug in mORMot / Zeos...

Below is a link to an archive with a script for creating a Firebird database with one table (create_db.sh) and a console application project on fpc / Lazarus:
https://drive.google.com/file/d/1WV1DQn … sp=sharing

You can run it and make a request from the console (test_curl_post.sh):
curl --header "Content-Type: application / json" --request POST --data '{"ID": "\ {A37E3E34-48AE-40B3-87A8-BBC3F97BEAD4 \}"}' http: // localhost: 8080 / root / UsrService / GetUsr

In response to it, the following json is returned:
{
"errorCode": 500,
"error":
{"EZSQLException":
{
        "ClassName": "EZSQLException",
        "Address": "7ffff5f2b300",
        "Message": "Bound variable index out of range: 1"
}}
}

as a result of the exception:
Project Test Application Server raised exception class 'EStringListError' with message:
List index (1) out of bounds
In file '../../src/dbc/ZDbcResultSetMetadata.pas' at line 694:
Result: = ColumnsLabels [ColumnIndex {$ IFNDEF GENERIC_INDEX} - 1 {$ ENDIF}];

and then

Project Test Application Server raised exception class 'EZSQLException' with message:
Bound variable index out of range: 1
In file '../../src/dbc/ZDbcFirebirdInterbase.pas' at line 3738:
raise EZSQLException.Create {$ IFDEF UNICODE} FUniTemp {$ ELSE} FRawTemp {$ ENDIF});


In a comment in the TUsrService.GetUsr method in the rest_Usr.pas file, I wrote the function calls that throw the exception.

Environment:
OS: 5.10.0-3-amd64 # 1 SMP Debian 5.10.12-1 (2021-01-30) x86_64 GNU / Linux
FPC / Lazarus: trunk / trunk (same on stable)
DB: Firebird 4 amd64 trunk

Please help me to solve this problem, because of this error I can not go further.

#37 Re: mORMot 1 » mORMot2 examples and documenation. Where should a beginner start? » 2021-01-21 10:59:35

Thank you for the quick answer, Arnaud!

ab wrote:

I don't want to make something as huge - and therefore unreadable for some users - as mORMot 1.
The mORMot 2 documentation should be more like a "User Guide".

Yes, the documentation for version 1.18 is very voluminous and detailed, it is rather more suitable for developers already working with mORMot to clarify details and best practices.

For beginners, we need something simple to get started quickly. And already in the process it will be possible to improve knowledge and approaches.


ab wrote:

Currently, the easiest is to look at mORMot 1 documentation, and blog articles like https://tamingthemormot.wordpress.com/2 … databases/
Then the mORMot 1.18 classes have all their mORMot 2 classes defined by default.
So use regular mORMot 1.18 client/server code - just change the unit names.
Then you define USEPUREMORMOT2 and you just change the old names into the new names.


It's excellent if for all classes with new names there are corresponding classes with old names, this greatly facilitates learning the framework smile
We can take any old examples, try them, and after the desired result is obtained (well, or in the process), simply change the names of the units in uses. Great!

And somewhere there is information, which classes were moved to which units?

It is also a pity that the mORMot blog is not available right now to view articles in it sad

#38 mORMot 1 » mORMot2 examples and documenation. Where should a beginner start? » 2021-01-21 07:44:51

L_VV
Replies: 6

Good day Arnaud,

Thank you very much for your wonderful project!

Could you tell us about when we can expect examples for mORMot2?

Since many classes have been renamed and redistributed among units, it is difficult for a beginner to understand from old examples and documentation where to start and how to do it.

Specifically, I want to try developing a project consisting of:
- application server with Interface-based services (json) under linux and windows ("REST" part of the mORMot2);
- Firebird database with 100% use of stored procedures, i.e. no ORM (via zeos lib);
- a client application that interacts with the application server (first a desktop application, then there may be other options).

All this on fpc / lazarus (stable or trunk).

What can I start from?

It is planned that the project will be big enough, so I want to start doing it right away on mORMot2, and not on the previous version of the framework.

Board footer

Powered by FluxBB