Recent

Author Topic: [SOLVED] Firebird embedded  (Read 3174 times)

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
[SOLVED] Firebird embedded
« on: April 20, 2023, 09:27:53 pm »
---edit---
Problem solved.
The instruction for Firebird Embedded on Linux is here:
https://forum.lazarus.freepascal.org/index.php/topic,63142.msg478478.html#msg478478






Just do not use Firebird.

I didn't believe it but it seems I now have to agree with Thaddy.
Someone, please prove me wrong!

Short story:
I am not good in database programming but I am very good in using TDbf. COVID means less jobs but plenty of time for me. I used the time studying SQL and understood how to use SQLite. I created some tests and knew that SQLite is roughly 8x faster than TDbf. But some said SQLite is not a good database so I later learned how to use Firebird.

Problems:
For some reasons, I need to use Firebird embedded. The documentation and information on the Firebird 3 embedded for Linux topic is extremely rare. All of them are for versions below 3. FYI, version 5.0 beta 1 is now ready for download.

How I test:
I use Ubuntu Mate 19.10 64-bit + Lazarus 2.3.0 + Firebird 3. I created a small program for runtime creating table and inserting data, and I run it on a Ubuntu Mate 18.04 64-bit virtual machine. I have tried all the things I found on the web, but I only got connection error. It could be solved only if I install Firebird 3 on the virtual machine. I used TIBConnection (not IBX).

Questions:
- Have anyone managed to use Firebird embedded version 3 or 4 on Linux?
- If yes, how to do it?

The only advantage of using Firebird, to me is able to switch between embedded and client-server mode with minimal effort. But if it can't work for version 3 or 4 on Linux, I will go to the industry standard or at least SQLite.
« Last Edit: May 01, 2023, 05:50:33 pm by Handoko »

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: Firebird embedded
« Reply #1 on: April 20, 2023, 09:58:40 pm »
Just do not use Firebird.

I didn't believe it but it seems I now have to agree with Thaddy.
Someone, please prove me wrong!

Short story:
I am not good in database programming but I am very good in using TDbf. COVID means less jobs but plenty of time for me. I used the time studying SQL and understood how to use SQLite. I created some tests and knew that SQLite is roughly 8x faster than TDbf. But some said SQLite is not a good database so I later learned how to use Firebird.

Problems:
For some reasons, I need to use Firebird embedded. The documentation and information on the Firebird 3 embedded for Linux topic is extremely rare. All of them are for versions below 3. FYI, version 5.0 beta 1 is now ready for download.

How I test:
I use Ubuntu Mate 19.10 64-bit + Lazarus 2.3.0 + Firebird 3. I created a small program for runtime creating table and inserting data, and I run it on a Ubuntu Mate 18.04 64-bit virtual machine. I have tried all the things I found on the web, but I only got connection error. It could be solved only if I install Firebird 3 on the virtual machine. I used TIBConnection (not IBX).

Questions:
- Have anyone managed to use Firebird embedded version 3 or 4 on Linux?
- If yes, how to do it?

The only advantage of using Firebird, to me is able to switch between embedded and client-server mode with minimal effort. But if it can't work for version 3 or 4 on Linux, I will go to the industry standard or at least SQLite.

Sounds like you're expecting the fb client to be part of your compiled executable. It's not. Perhaps they should have called it Firebird Serverless instead of embedded. You need a copy of the firebird client where the .FDB file is installed. It's a local connection, and the library is dynamic.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Firebird embedded
« Reply #2 on: April 20, 2023, 10:03:51 pm »
You need a copy of the firebird client where the .FDB file is installed. It's a local connection, and the library is dynamic.

I tried but not did not work. I even installed libfbclient2 package using Synaptic Package Manager, the libfbclient2 is provided on Ubuntu Software Center.
« Last Edit: April 20, 2023, 10:06:25 pm by Handoko »

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: Firebird embedded
« Reply #3 on: April 20, 2023, 10:15:45 pm »
You need a copy of the firebird client where the .FDB file is installed. It's a local connection, and the library is dynamic.

I tried but not did not work. I even installed libfbclient2 package using Synaptic Package Manager, the libfbclient2 is provided on Ubuntu Software Center.

Isn't libfbclient2 for firebird 2.X? You said you were using FB3.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Firebird embedded
« Reply #4 on: April 20, 2023, 10:27:43 pm »
I copied/pasted libfbclient from FB3. I also tried install libfbclient2 (which the package manager said: version 3.0.5, see the screenshot below).

Even weirder, the compiled binary (server mode) can run but got connection error on the newly installed server machine, which already have Firebird 3 server installed. It only worked correctly if I also install the firebird-dev package.
« Last Edit: April 20, 2023, 10:32:06 pm by Handoko »

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: Firebird embedded
« Reply #5 on: April 20, 2023, 10:42:09 pm »
I copied/pasted libfbclient from FB3. I also tried install libfbclient2 (which the package manager said: version 3.0.5, see the screenshot below).

Even weirder, the compiled binary (server mode) can run but got connection error on the newly installed server machine, which already have Firebird 3 server installed. It only worked correctly if I also install the firebird-dev package.

Requiring the dev package sounds pretty standard for the server install... but I don't know about for just the client. I'm out of my league when it comes to Ubuntu.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: Firebird embedded
« Reply #6 on: April 21, 2023, 12:42:54 am »
I copied/pasted libfbclient from FB3. I also tried install libfbclient2 (which the package manager said: version 3.0.5, see the screenshot below).

Even weirder, the compiled binary (server mode) can run but got connection error on the newly installed server machine, which already have Firebird 3 server installed. It only worked correctly if I also install the firebird-dev package.

I stumbled across these:

https://docs.huihoo.com/firebird/manual/ufb-cs.html
https://www.ibphoenix.com/files/Embedded_fb3.pdf

It does discuss some Linux-specific things. Maybe this'll help a little.
« Last Edit: April 21, 2023, 12:44:55 am by dsiders »
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Firebird embedded
« Reply #7 on: April 21, 2023, 06:11:26 am »
Of course I had read the pdf before I started the questions here.

For doing Firebird Embedded version 3 and 4 on Windows, they are relatively easy. After  some research on the Internet and testing, I managed to find out the minimum files needed for Firebird Embedded but for Windows only. If anyone interested, the see the attached picture. I always write and save the information if I found something useful.

Quote
Embedded in Firebird 3
Everything you need for deploying Firebird 3 embedded with your application is present
in the .zip (Windows) or .tar.gz (Linux) kit that you download from the Firebird website.
We'll work with mainly with the Windows zip kit here, but the principle is the same for
the Linux kit: unzip the Windows kit into its own folder or decompress and untar the
Linux one into its own directory. There are differences between structures of the file
systems now, specifically in the location of the binary files: Linux retains them in the
/bin directory beneath the Firebird root, whereas Windows has them all directly in the
Firebird root.

The pdf tutorial in the link you gave is for Windows - as I quoted above - it says the principle is the same for Linux. But no, it didn't work on my test.

And, the information on the first link is not applicable on Firebird 3 Linux because the mentioned files libfbembed.so and libgds* are no where to be found.

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: Firebird embedded
« Reply #8 on: April 21, 2023, 06:42:44 am »
Of course I had read the pdf before I started the questions here.

For doing Firebird Embedded version 3 and 4 on Windows, they are relatively easy. After  some research on the Internet and testing, I managed to find out the minimum files needed for Firebird Embedded but for Windows only. If anyone interested, the see the attached picture. I always write and save the information if I found something useful.

Quote
Embedded in Firebird 3
Everything you need for deploying Firebird 3 embedded with your application is present
in the .zip (Windows) or .tar.gz (Linux) kit that you download from the Firebird website.
We'll work with mainly with the Windows zip kit here, but the principle is the same for
the Linux kit: unzip the Windows kit into its own folder or decompress and untar the
Linux one into its own directory. There are differences between structures of the file
systems now, specifically in the location of the binary files: Linux retains them in the
/bin directory beneath the Firebird root, whereas Windows has them all directly in the
Firebird root.

The pdf tutorial in the link you gave is for Windows - as I quoted above - it says the principle is the same for Linux. But no, it didn't work on my test.

And, the information on the first link is not applicable on Firebird 3 Linux because the mentioned files libfbembed.so and libgds* are no where to be found.

If you read the release notes for version 3: https://firebirdsql.org/file/documentation/release_notes/html/en/3_0/rlsnotes30.html#rnfb30-engine

Code: Text  [Select][+][-]
  1. Unification of the Firebird executable is complete
  2.  
  3. With the completion of true SMP support for Superserver, the Firebird core is now a unified library that supports
  4. a single ODS, loadable either as an embedded engine or by the “network listener” executable. Choice of server
  5. model is determined by settings for a new configuration parameter ServerMode, defining the locking and cache
  6. modes. It is specified at global level in firebird.conf.
  7.  
  8. ...
  9.  
  10. When <database name> does not contain a network protocol but just the database name,
  11. the Remote provider rejects it, and the Engine12 provider comes to the fore and tries to open
  12. the named database file. If it succeeds, we get an embedded connection to the database.
  13.  
  14. A special “embedded library” is no longer required. To make the embedded connection, the
  15. standard client loads the appropriate provider and becomes an embedded server.
  16.  

So there is no libfbembed.so for firebird 3.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Firebird embedded
« Reply #9 on: April 21, 2023, 06:51:28 am »
I also had read that information. As I said most of the information about Firebird Embedded Linux is written for version below 3.

Thank you for trying to help. Lets wait for maybe 1 or 2 weeks and see if anyone really managed to do Firebird Embedded version 3 or above on Linux.

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: Firebird embedded
« Reply #10 on: April 21, 2023, 06:55:33 am »
I also had read that information. As I said most of the information about Firebird Embedded Linux is written for version below 3.

Thank you for trying to help. Lets wait for maybe 1 or 2 weeks and see if anyone really managed to do Firebird Embedded version 3 or above on Linux.

If you like. The unasked question is: Did you put the required files from the list above in the application directory?
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Firebird embedded
« Reply #11 on: April 21, 2023, 07:12:04 am »
Yes.

I first tried it on Windows. Copying all mentioned files to the application directory (I mean my program folder: Desktop\aRFQ), it worked.

But on Linux, it didn't. My program and the fdb file is located in Desktop/fbtest. I copied them to both Desktop/fbtest and Desktop/fbtest/bin, also duplicated libfbclient.so to name it as libfbclient.so.02, libfbclient.so.3.0.5 in those folders and also to the /bin folder. I also did the same thing on libEngine12.so. No luck so far.
« Last Edit: April 21, 2023, 07:38:24 am by Handoko »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Firebird embedded
« Reply #12 on: April 21, 2023, 08:55:19 am »
hello,
the ibase components of sqldb seem to be obsolète. The last version of Zeos ( 8.0. 0-beta) in development (not the online packager version) seemss to work with firebird 3 and 4.
see here for firebird 4 server windows and attachment for firebird 3 embedded on Ubuntu 20.04. You need to replace the sqldb components with the zeos components.

ibase include :
Quote
ibase60.inc :
{$MODE objfpc}
{$MACRO on}


interface

{$IFDEF LinkDynamically}
uses Dynlibs, sysutils,ctypes;

Var
  UseEmbeddedFirebird : Boolean = False;

{$ELSE}
uses Dynlibs,ctypes;
{$ENDIF}

{$IFDEF Unix}
  {$DEFINE extdecl:=cdecl}
  const
    gdslib = 'libgds.'+sharedsuffix; // Needs completion ?
    libfc  = 'libfbclient.'+sharedsuffix;
    libem  = 'libfbembed.'+sharedsuffix;
    v2  = {$ifndef darwin}'.2'{$else}''{$endif};
    v21 = {$ifndef darwin}'.2.1'{$else}''{$endif};
    v25 = {$ifndef darwin}'.2.5'{$else}''{$endif};
    v251 = {$ifndef darwin}'.2.5.1'{$else}''{$endif};
    fbclib2      = libfc+v2;
    fbembedlib2  = libem+v2;
    fbclib21     = libfc+v21;
    fbembedlib21 = libem+v21;
    fbclib25     = libfc+v25;
    fbembedlib25 = libem+v25;
    fbclib251    = libfc+v251;
    fbembedlib251 = libem+v25;
    // Set default here
    fbclib       = fbclib251;
    fbembedlib   = fbembedlib251;
{$ENDIF}

Friendly, J.P
« Last Edit: April 21, 2023, 09:01:05 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

DomingoGP

  • Jr. Member
  • **
  • Posts: 61
Re: Firebird embedded
« Reply #13 on: April 21, 2023, 04:33:48 pm »
Have you tried to set the environment vars:

Quote
# tell dynamic loader where to find embedded lib:
LD_LIBRARY_PATH=/home/pascaldev/embed/firebird
# tell server where to find files (messages, config etc)
FIREBIRD=. #or use absolute path: /home/pascaldev/embed
as wiki page says  https://wiki.freepascal.org/Firebird_embedded

Sorry, don't tested, I don't have any Linux installed to test.

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Firebird embedded
« Reply #14 on: April 21, 2023, 09:29:50 pm »
But on Linux, it didn't. My program and the fdb file is located in Desktop/fbtest. I copied them to both Desktop/fbtest and Desktop/fbtest/bin, also duplicated libfbclient.so to name it as libfbclient.so.02, libfbclient.so.3.0.5 in those folders and also to the /bin folder. I also did the same thing on libEngine12.so. No luck so far.
You might have had more luck asking this on the Firebird forum.
But I took a stab at it...  :D

The reason why it didn't work for you could be seen by examining libfbclient.so.3.0.10.so with lddtree (from pax-utils).
(try it and see what you are missing if it still doesn't work)

Code: Bash  [Select][+][-]
  1. $ sudo apt install pax-utils
  2. $ lddtree lib/libfbclient.so.3.0.10
  3. libgds.so => ./libgds.so (interpreter => none)
  4.     librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1
  5.     libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
  6.     libncurses.so.5 => not found
  7.     libtommath.so.0 => not found
  8.     libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6
  9.     libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
  10.     libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
  11.     libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
  12.     libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
  13.     ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2

So you will need libncurses5 and libtommath1 libraries too.
Code: Bash  [Select][+][-]
  1. sudo apt-get install libncurses5 libtommath1

It could be that libtommath1 is already installed. In that case you need to create an extra symlink:
Code: Bash  [Select][+][-]
  1. sudo ln -s libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0

After that it should work.
Also don't forget to set the LD_LIBRARY_PATH accordingly.

Code: Bash  [Select][+][-]
  1. export LD_LIBRARY_PATH=~/Firebird-3.0.10.33601-0.amd64/opt/firebird/lib
  2. export FIREBIRD=~/Firebird-3.0.10.33601-0.amd64/opt/firebird
(with Firebird-3.0.10.33601-0.amd64 being the unpacked directory , including the buildroot.tar.gz)

Let me know if it doesn't work and I can see if I missed something.

~~
I tested this with a clean Ubuntu 22.04 version.
Here is the complete script I followed:

Code: Bash  [Select][+][-]
  1. # ---------
  2. # download and unpack firebird embedded
  3. # ---------
  4. wget https://github.com/FirebirdSQL/firebird/releases/download/v3.0.10/Firebird-3.0.10.33601-0.amd64.tar.gz
  5. tar -xf Firebird-3.0.10.33601-0.amd64.tar.gz
  6. cd Firebird-3.0.10.33601-0.amd64
  7. tar -xf buildroot.tar.gz
  8. cd opt/firebird
  9.  
  10. # ---------
  11. # check dependencies
  12. # ---------
  13. sudo apt install pax-utils
  14. lddtree lib/libfbclient.so.3.0.10
  15.  
  16. # ---------
  17. # install dependencies for firebird embedded ("not found")
  18. # ---------
  19. sudo apt-get install libncurses5 libtommath1
  20. sudo ln -s libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0
  21.  
  22. # ---------
  23. # install fpc, set environment and test. fpc only needed for compilation
  24. # ---------
  25. sudo apt-get install fpc
  26. export LD_LIBRARY_PATH=~/Firebird-3.0.10.33601-0.amd64/opt/firebird/lib
  27. export FIREBIRD=/home/rik/Firebird-3.0.10.33601-0.amd64/opt/firebird
  28. nano test.pp
  29. fpc -MObjFPC test.pp
  30. ./test

Result:
Quote
a
b
c
done

test.pp looks like this:
Code: Pascal  [Select][+][-]
  1. program testfirebird;
  2. uses SQLDB, DB, IBConnection;
  3. var
  4.   FB: TIBConnection;
  5.   SQL: TSQLQuery;
  6. begin
  7.   FB := TIBConnection.Create(nil);
  8.   SQL := TSQLQuery.Create(FB);
  9.   try
  10.     FB.Transaction := TSQLTransaction.Create(FB);
  11.     FB.Transaction.Database := FB;
  12.     FB.LoginPrompt := False;
  13.     // FB.HostName := 'localhost';
  14.     FB.DatabaseName := 'DEMO.FDB';
  15.     FB.UserName := 'SYSDBA';
  16.     FB.Password := 'masterkey';
  17.     try
  18.       FB.Connected := True;
  19.     except
  20.       on E: EDatabaseError do
  21.       begin
  22.         FB.CreateDB;
  23.         FB.Connected := True;
  24.         writeln('creating DEMO.FBD');
  25.         FB.ExecuteDirect('CREATE TABLE TEST(ID BIGINT, CODE VARCHAR(80));');
  26.         if FB.Transaction.Active then FB.Transaction.Commit;
  27.         FB.ExecuteDirect('INSERT INTO TEST VALUES(1, ''a'');');
  28.         FB.ExecuteDirect('INSERT INTO TEST VALUES(2, ''b'');');
  29.         FB.ExecuteDirect('INSERT INTO TEST VALUES(3, ''c'');');
  30.         if FB.Transaction.Active then FB.Transaction.Commit;
  31.       end;
  32.     end;
  33.     SQL := TSQLQuery.Create(FB);
  34.     SQL.Database := FB;
  35.     SQL.Transaction := FB.Transaction;
  36.     SQL.SQL.Text := 'SELECT * FROM TEST';
  37.     SQL.Open;
  38.     while not SQL.EOF do
  39.     begin
  40.       writeln(SQL.FieldByName('CODE').asString);
  41.       SQL.Next;
  42.     end;
  43.     SQL.Close;
  44.   finally
  45.     FB.Free;
  46.   end;
  47.   writeln('done');
  48.   readln;
  49. end.

BTW There is no need for a symlink or something because the tar already contains a symlink for libfbclient.so to the correct version.
So this should work 'out of the box'.

Also... if you need to keep the current LD_LIBRARY_PATH then you should do:
Code: Bash  [Select][+][-]
  1. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/firebird_embedded/opt/firebird/lib
You can also add it to your ~/.bashrc:
Code: Bash  [Select][+][-]
  1. echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/firebird_embedded/opt/firebird/lib' >> ~/.bashrc

Just do not use Firebird.
I didn't believe it but it seems I now have to agree with Thaddy.
Someone, please prove me wrong!
Hope your faith is restored after this  :D
« Last Edit: April 21, 2023, 10:39:57 pm by rvk »

 

TinyPortal © 2005-2018