Recent

Author Topic: [SOLVED] mORMot Sample 30 MVC Server - still working?  (Read 11632 times)

jeffp

  • New Member
  • *
  • Posts: 15
[SOLVED] mORMot Sample 30 MVC Server - still working?
« on: July 20, 2021, 04:10:54 pm »
Hello All.

I'm trying to learn mormot. I was able to compile and run successfully the first few samples. Now I want to test sample 30, specifically want to try working with an external Firebird database. (I've deployed a few apps with FB before). I was able to compile MVCServerFirebird, but then I get an error when running it:

Code: [Select]
An unhandled exception occurred at $00000001000FDDD6:
ESQLite3Exception: Error SQLITE_ERROR (1) [Step] using 3.35.5 - SQL Error: I/O e
rror during "CreateFile (open)" operation for file "MVCSERVERFIREBIRD.FDB"Error
while trying to open fileThe system cannot find the file specified. . Error Code
: -902. Unsuccessful execution caused by a system error that precludes successfu
l execution of subsequent statements, extended_errcode=1
  $00000001000FDDD6  SQLITE3_CHECK,  line 5400 of ../../../SynSQLite3.pas
  $00000001000FD71E  STEP,  line 5320 of ../../../SynSQLite3.pas
  $00000001000FC961  EXECUTE,  line 4913 of ../../../SynSQLite3.pas
  $00000001000FC9D3  EXECUTE,  line 4933 of ../../../SynSQLite3.pas
  $00000001000F99C8  EXECUTE,  line 3999 of ../../../SynSQLite3.pas
  $00000001002147F1  CREATEMISSINGTABLES,  line 850 of ../../mORMotSQLite3.pas
  $000000010000200F  main,  line 73 of MVCServerFirebird.dpr
  $0000000100002206  main,  line 103 of MVCServerFirebird.dpr

Tweaked a little in the code:
Code: [Select]
    {$ifdef USEZEOSFIREBIRD}
    aExternalDB := TSQLDBZEOSConnectionProperties.Create(
      TSQLDBZEOSConnectionProperties.URI(dFIREBIRD,'127.0.0.1',
      'bin\fbclient.dll'),
      'MVCSERVERFIREBIRD.FDB','sysdba','masterkey');
    aExternalDB.ThreadingMode := tmMainConnection; // as expected for FB embedded
    {$endif}                                                                     

System:
Laz 2.0.12
FPC 3.2.0
mORMot (grabbed it thru FPCupdeluxe using mORMot button)
Zeos 7.2.6 stable


Thanks.
jeffp
« Last Edit: July 26, 2021, 09:48:25 am by jeffp »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: mORMot Sample 30 MVC Server - still working?
« Reply #1 on: July 20, 2021, 07:57:54 pm »
Code: [Select]
ESQLite3Exception: Error SQLITE_ERROR (1) [Step] using 3.35.5 - SQL Error:  I/O error during "CreateFile (open)" operation for file "MVCSERVERFIREBIRD.FDB"Error
while trying to open fileThe system cannot find the file specified.

Sqlite errors on not finding file "MVCSERVERFIREBIRD.FDB" which is doubly wrong.

  • the file apparently is not there.
  • if it would be there the .fdb extension seems to indicate firebird file, not sqlite

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: mORMot Sample 30 MVC Server - still working?
« Reply #2 on: July 20, 2021, 09:12:06 pm »
Create empty firebird database first with any db tool, then change props in code.

alpine

  • Hero Member
  • *****
  • Posts: 1032
Re: mORMot Sample 30 MVC Server - still working?
« Reply #3 on: July 20, 2021, 10:26:06 pm »
IMHO, using mORMot with the Firebird is quite an adventure, but perhaps it is OK on the educational side.  ;)
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

jeffp

  • New Member
  • *
  • Posts: 15
Re: mORMot Sample 30 MVC Server - still working?
« Reply #4 on: July 21, 2021, 12:29:20 am »
Hey marcov,

Sqlite errors on not finding file "MVCSERVERFIREBIRD.FDB" which is doubly wrong.

  • the file apparently is not there.
  • if it would be there the .fdb extension seems to indicate firebird file, not sqlite

The file is there. And it is intentionally Firebird.

@ttomas,
Create empty firebird database first with any db tool, then change props in code.
I did create an empty Firebird db with Flamerobin. Which props to change, please?

@y.ivanov,
IMHO, using mORMot with the Firebird is quite an adventure, but perhaps it is OK on the educational side.  ;)
Indeed. But the mORMot promises are so irresistible. I can try postgresql, but I have some FB apps I wanted to convert. I've poured over the docs for about two days and scouring the internet for answers. Now that's adventure.

What brings me to mormot is the promise of speed. And the several services I might not even need. I like how the ORM works. Having to work with FP classes instead of manually designing the DB appeals to me. This is similar to Python + SQLAlchemy auto migration. You work with classes and let the ORM take care of DB tedium. Not all the time of course.

I want to have a Datasnap-like midware to work with remote databases, although I am reading in several places that same requirement can also be performed with a REST API approach, which would bring me back Python + flask.

Additional info:
Win8.1 x64
Laz installed with fpcupdeluxe is also x64
FB is also x64
   Also tried FB 32, no joy.
« Last Edit: July 21, 2021, 12:45:39 am by jeffp »

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: mORMot Sample 30 MVC Server - still working?
« Reply #5 on: July 21, 2021, 01:08:40 am »
Just sample to connect to sample employee.fdb database.
You don't mention Firebird version. This code work with Firebird 3 and Zeos 7.3(8.0) on Manjaro Linux
Code: Pascal  [Select][+][-]
  1.   Props := TSqlDBZeosConnectionProperties.Create( 'zdbc:firebird://localhost:/employee.fdb?username=SYSDBA;password=masterkey', '', '', '' );
  2.   try
  3.     pRow := Props.Execute('select * from employee',[]);
  4.     while pRow.Step do begin
  5.       writeln(FormatUtf8('%: %, %: %, %: %', [
  6.         pRow.ColumnName(0), pRow.ColumnUtf8(0),
  7.         pRow.ColumnName(1), pRow.ColumnUtf8(1),
  8.         pRow.ColumnName(2), pRow.ColumnUtf8(2)
  9.         ]));
  10.     end;
  11.   finally
  12.     Props.Free;
  13.   end;
  14.  
« Last Edit: July 21, 2021, 01:12:08 am by ttomas »

jeffp

  • New Member
  • *
  • Posts: 15
Re: mORMot Sample 30 MVC Server - still working?
« Reply #6 on: July 21, 2021, 02:13:48 am »
Just sample to connect to sample employee.fdb database.
You don't mention Firebird version. This code work with Firebird 3 and Zeos 7.3(8.0) on Manjaro Linux
Code: Pascal  [Select][+][-]
  1.   Props := TSqlDBZeosConnectionProperties.Create( 'zdbc:firebird://localhost:/employee.fdb?username=SYSDBA;password=masterkey', '', '', '' );
  2. ...
  3.  


@ttomas, I'm using FB 2.5.9. With that code, how do you tell mORMot where to look for FB client lib, as it is giving me this error:

Code: [Select]
An unhandled exception occurred at $00000001000FDD66:
ESQLite3Exception: Error SQLITE_ERROR (1) [Step] using 3.35.5 - None of the dyna
mic libraries can be found or is not loadable: fbclient25.dll, fbclient.dll !
Use TZConnection.LibraryLocation if the location is invalid., extended_errcode=1

  $00000001000FDD66  SQLITE3_CHECK,  line 5400 of ../../../SynSQLite3.pas
  $00000001000FD6AE  STEP,  line 5320 of ../../../SynSQLite3.pas
  $00000001000FC8F1  EXECUTE,  line 4913 of ../../../SynSQLite3.pas
  $00000001000FC963  EXECUTE,  line 4933 of ../../../SynSQLite3.pas
  $00000001000F9958  EXECUTE,  line 3999 of ../../../SynSQLite3.pas
  $0000000100214781  CREATEMISSINGTABLES,  line 850 of ../../mORMotSQLite3.pas
  $0000000100001FB1  main,  line 74 of MVCServerFirebird.dpr

Why does it even mention TZConnection?

TIA

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: mORMot Sample 30 MVC Server - still working?
« Reply #7 on: July 21, 2021, 03:03:34 am »
Your fbclient is not properly installed. Copy 64bit fbclient.dll in system32 folder and 32bi in syswow64 folder in c windows folder.
Or you can add LibLocation param, look at SynDbZeos.pas Create and Uri method comments for TSQLDBZEOSConnectionProperties class.
TSQLDBZEOSConnectionProperties use TZConnection from zeoslib to connect to db using fbclient. Use apsolute path for liblocation not relative to your exe.
Uri class method is just helper for easy creation of connection string. For fb 2.5 use zdbc:firebird-2.5

jeffp

  • New Member
  • *
  • Posts: 15
Re: mORMot Sample 30 MVC Server - still working?
« Reply #8 on: July 21, 2021, 06:24:48 am »
Your fbclient is not properly installed. Copy 64bit fbclient.dll in system32 folder and 32bi in syswow64 folder in c windows folder.
Or you can add LibLocation param, look at SynDbZeos.pas Create and Uri method comments for TSQLDBZEOSConnectionProperties class.
TSQLDBZEOSConnectionProperties use TZConnection from zeoslib to connect to db using fbclient. Use apsolute path for liblocation not relative to your exe.
Uri class method is just helper for easy creation of connection string. For fb 2.5 use zdbc:firebird-2.5

No, the fbclient is properly installed, I'm sure. Anyway, I managed to point Zeos to the right fbclient.dll, using System32 and SysWOW64. It also knows how to locate the library with LibLocation parameter, but alas, comes back to the same error.

So which fault is it now? Zeos, SQLite3 or mORMot?

Code: [Select]
An unhandled exception occurred at $00000001000FDD66:
ESQLite3Exception: Error SQLITE_ERROR (1) [Step] using 3.35.5 - SQL Error: I/O e
rror during "CreateFile (open)" operation for file "MVCSERVERFIREBIRD.FDB"Error
while trying to open fileThe system cannot find the file specified. . Error Code
: -902. Unsuccessful execution caused by a system error that precludes successfu
l execution of subsequent statements, extended_errcode=1
  $00000001000FDD66  SQLITE3_CHECK,  line 5400 of ../../../SynSQLite3.pas
  $00000001000FD6AE  STEP,  line 5320 of ../../../SynSQLite3.pas
  $00000001000FC8F1  EXECUTE,  line 4913 of ../../../SynSQLite3.pas
  $00000001000FC963  EXECUTE,  line 4933 of ../../../SynSQLite3.pas
  $00000001000F9958  EXECUTE,  line 3999 of ../../../SynSQLite3.pas
  $0000000100214781  CREATEMISSINGTABLES,  line 850 of ../../mORMotSQLite3.pas
  $0000000100001FB1  main,  line 74 of MVCServerFirebird.dpr
  $0000000100002196  main,  line 104 of MVCServerFirebird.dpr

Code: [Select]
-902. Unsuccessful execution caused by a system error that precludes successfu
l execution of subsequent statements
I recognize this error message coming from the Firebird engine.
« Last Edit: July 21, 2021, 07:39:40 am by jeffp »

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: mORMot Sample 30 MVC Server - still working?
« Reply #9 on: July 21, 2021, 11:30:10 am »
I just compile and run MVCServerFirebird blog app. I use Firebird3 server not embedded mode. This is my changes:
Code: Pascal  [Select][+][-]
  1.     aExternalDB := TSQLDBZEOSConnectionProperties.Create( 'zdbc:firebird://localhost:3033/D:\bazi\MVCServerFirebird.fdb?username=SYSDBA;password=masterkey;LibLocation=C:\Firebird\firebird3_32\fbclient.dll', '', '', '' );
I use Zeos 7.3 also work with v8.
Do you use server or embedded client? Firebird can work as server or as embedded client.
Client or Server can't find your MVCServerFirebid.fdb file.
If you use server firebird db must be in local disk not network shared location.
If you use embedded only one application can access this file, if you use FlameRobin and open this file then your app can't open this file. If you use server then you can have multiple connections to same database.
If you have only one version of firebird then install client for both 64 and 32 and you don't need to set LibLocation Zeos will find fbclient.dll in your system path.
If you have multiple versions of firebird (I have 1.5, 2, 2.5, 3) all in different ports, my Firebird 3 run on port 3033, then you must set LibLocation for your client (fbclient.dll) for 32 or 64 app and Firebird version.
If you use server then you can create alias for your database file in aliases.conf for Fb 2.5 or databases.conf for Fb3 like
Code: Pascal  [Select][+][-]
  1. MVCServerFirebird.fdb = D:\bazi\MVCServerFirebird.fdb
then use alias in connection string
Code: Pascal  [Select][+][-]
  1. zdbc:firebird://localhost:3033/MVCServerFirebird.fdb?username=SYSDBA;password=masterkey;LibLocation=C:\Firebird\firebird3_32\fbclient.dll
« Last Edit: July 21, 2021, 11:33:08 am by ttomas »

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: mORMot Sample 30 MVC Server - still working?
« Reply #10 on: July 21, 2021, 11:48:11 am »
IMHO, using mORMot with the Firebird is quite an adventure, but perhaps it is OK on the educational side.  ;)
I can't find a word not to be crud #@!%^&*.
Don't agree.
Production proof:
https://shop.tuctucandfriends.mk/
You can inspect page and see response header for _search
Code: Pascal  [Select][+][-]
  1. x-powered-by: mORMot 1.18 synopse.info

alpine

  • Hero Member
  • *****
  • Posts: 1032
Re: mORMot Sample 30 MVC Server - still working?
« Reply #11 on: July 21, 2021, 01:39:16 pm »
IMHO, using mORMot with the Firebird is quite an adventure, but perhaps it is OK on the educational side.  ;)
I can't find a word not to be crud #@!%^&*.
Don't agree.
Production proof:
https://shop.tuctucandfriends.mk/
You can inspect page and see response header for _search
Code: Pascal  [Select][+][-]
  1. x-powered-by: mORMot 1.18 synopse.info

So what? Why do you refrain from being rude?

Just see: https://synopse.info/forum/viewtopic.php?id=2209
Issues with mORMot+Firebird MVCC and transaction handling discussed. I believe you also participated in that thread. Although it is quite outdated, I don't believe the mORMot author has changed it's approach significantly. Firebird MVCC model hasn't changed either.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: mORMot Sample 30 MVC Server - still working?
« Reply #12 on: July 21, 2021, 01:56:32 pm »
The question is and remains why there are sqlite3 errors when accessing a firebird FDB database.

I suspect that zeos and/or mormot must have some define files configured to have the right database type.  IIRC zeos allowed to select registered database types in the TZconnection component.

jeffp

  • New Member
  • *
  • Posts: 15
Re: mORMot Sample 30 MVC Server - still working?
« Reply #13 on: July 21, 2021, 05:03:50 pm »
Progress! or workaround?

So the server expects a pre-created FB database all along. I am not sure if this is by design, but the earlier error seems to suggest that mormot tries to create the db and fails.

Based on advise, these are what I did.
  • Copied fbclient to system32. Zeos can't be bothered to look anywhere else, like the install directory
  • Used absolute file path for the database

Now onto more real world applications.

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: mORMot Sample 30 MVC Server - still working?
« Reply #14 on: July 21, 2021, 10:10:50 pm »
Just see: https://synopse.info/forum/viewtopic.php?id=2209
Issues with mORMot+Firebird MVCC and transaction handling discussed. I believe you also participated in that thread. Although it is quite outdated, I don't believe the mORMot author has changed it's approach significantly. Firebird MVCC model hasn't changed either.
This is not mORMot issue, this is ZeosLib Issue. ZeosLib open and keep open transaction from connection. When you commit, new transaction is started. This transaction logic is the problem, this is logic like PostgreSQL and MySQL RDBMS work.
« Last Edit: July 21, 2021, 10:37:19 pm by ttomas »

 

TinyPortal © 2005-2018