Recent

Author Topic: Firebird 4 embed - error when turning on Connected in IBConnection1 properties.  (Read 3514 times)

Jiří Huňáček

  • New Member
  • *
  • Posts: 28
Hello to everybody,

I'm having trouble turning on the Connected feature when using Firebird 4.0.3 (x64) embedded.

I copied all the necessary files according to the instructions (Figure 1).

When I only use the property setting in the FormCreate method, the database connects to Firebird embedded without any error.

But when I instead want to switch the Connected property to true in the object inspector and all other properties are set the same as in FormCreate, it always tells me that it can't find the Firebird library (Figure 2).

I am also attaching a test project. Necessary embedded files here https://drive.google.com/file/d/1PX0yB0Vgn3GFoB3BPZzP6lbrcgTrX3Nz/view?usp=sharing.

Thanks for your replay

George
« Last Edit: August 19, 2023, 04:58:34 pm by Jiří Huňáček »
Best regards / mit freundlichen Grüßen / s pozdravem
Jiří Huňáček (George)

Lazarus v3.6 and FPC v3.2.2 on Windows 10 x64

korba812

  • Sr. Member
  • ****
  • Posts: 441
If you want to use Firebird connection at design time then you should also put Firebird libraries in directory where Lazarus IDE executable file is located.

johnsg

  • Newbie
  • Posts: 4
The Firebird website shows FB2.5 as 'discontinued'. FB3 and 4 are current and FB5 is under development. But the only IBConnection component  is hard coded to Firebird 2.5.1., and appears to accept only those libraries.  Short of hand coding a generic SQLConnection for FB3/4, how are you getting a connection to them?  If there is a shortcut it would be useful.  For that matter, could you expand a little on your explanation?

thanks
JG 

korba812

  • Sr. Member
  • ****
  • Posts: 441
You can point to library file using the InitialiseIBase60 function from the ibase60dyn unit. However, you must do this before using components from SQLDB package (for example, at the beginning of your program). It should work with FB4 but I don't know if SQLDB supports all new data types.

rvk

  • Hero Member
  • *****
  • Posts: 6572
With TIBConnection there is no need to set the library name.
There is also no difference in library name between 2.5, 3 and 4 version of FB.
It should just work with any version.

https://www.freepascal.org/docs-html/fcl/ibconnection/tibconnection.html

So what exactly is the problem?

korba812

  • Sr. Member
  • ****
  • Posts: 441
On Linux platform, name of library file may contain a suffix with version number. Looking at code of ibase60 module, you can see hard-coded library names with version 2.5.1. This is probably what the OP is referring to.

rvk

  • Hero Member
  • *****
  • Posts: 6572
On Linux platform, name of library file may contain a suffix with version number. Looking at code of ibase60 module, you can see hard-coded library names with version 2.5.1. This is probably what the OP is referring to.
On Linux the client will also try to load libfc which contains libfbclient.so without version.
See https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/ibase/src/ibase60.inc?ref_type=heads

And a FB client install will always create a symlink for that to the correct version.
So this should even work for FB 4 client without problems.

But without more information it is hard to say what exactly the problem is.

johnsg

  • Newbie
  • Posts: 4
Problem is no longer reproducable. Source was wiped for fresh start.  Which worked.  Early fumbling with connection strings may have gummed things up.  Problem presented as an error box complaining it coundn't find the v2.5.1 library.  But this was a machine with only FB4.  Backtracking thru the source gets to the ibase60 code which is hard wired to 2.5.1.

BUT.  There we have a lot what of fixes that are really workarounds; not suitable for non-expert users of FPC/Laz.  Let alone the insides of Firebird.  And the only IBConnectin component is locked to 2.5.1.  Can't we apply the visual prgmg paradigm to picking the applicble version of FB? 

Thanks again
JG

Handoko

  • Hero Member
  • *****
  • Posts: 5375
  • My goal: build my own game engine using Lazarus
It works on my test on Ubuntu Mate 23.04 Lazarus 2.2.6 using Firebird 4 Embedded.

There are 3 things need to be done to make the code posted in the first post to work:

1. Linux use '/' as directory separator.
So in line #40, that should be:
IBConnection1.DatabaseName := ExtractFileDir(ParamStr(0)) + '/DATABASE-v4.FDB';

2. Add FIREBIRD and LD_LIBRARY_PATH variables to point to the location of the embedded library (or the program binary location, which is shown by ParamStr(0)).
Lazarus main menu > Run Parameters > Environment > Add

3. Copy necessaries files to the program binary location.
It may also work if you put those files in a separate location, see #2 but I haven't tried.

If anyone want to learn more on how to make Firebird Embedded to work on Linux please read rvk's posts:
https://forum.lazarus.freepascal.org/index.php/topic,63142.msg477919/topicseen.html#new

In my opinion, Firebird embedded is not for newbies. For making it newbie friendly, someone please write a wiki page explaining how to do it correctly.

Also, as far as I know any distribution of Firebird library must also keep IDPLicense.txt and IPLicense.txt intact:

Quote
3.5. Required Notices. 
You must duplicate the notice in Exhibit A in each file of the Source Code. If it is not possible to put such notice in a particular Source Code file due to its structure, then You must include such notice in a location (such as a relevant directory) where a user would be likely to look for such a notice.
« Last Edit: October 25, 2023, 06:00:16 am by Handoko »

rvk

  • Hero Member
  • *****
  • Posts: 6572
And the only IBConnectin component is locked to 2.5.1.  Can't we apply the visual prgmg paradigm to picking the applicble version of FB? 
It's not locked to 2.5.1. (and the fact it works now proves that)

Please note that it is only the error message that says 2.5.1.
It actually also searches for libfbclient.so.2 and libfbclient.so too.
And the last one should be present for Firebird 4 (and 5).

So it's only the error message which should be fixed.
And in my opinion the searching for libfbclient.so.2.5 and libfbclient.so.2 should be removed in favor of just using libfbclient.so and displaying that if it can't be found. There should always be a symlink to the correct library. Otherwise you are always chasing new version.

Adding a version option in the component is also not advisable because then your executable can only run with that fb version. Using the symlink it can work with multiple fb versions (if you don't use specific version features.)


MAndreato

  • New Member
  • *
  • Posts: 11
Hi, I share my experience on using embedded Firebird 5 in a Lazarus application (Window 10). I hope this could helps, maybe it could be even more useful to update the https://wiki.freepascal.org/Firebird.

Download Firebird kit from https://firebirdsql.org/. I used "Firebird-5.0.0.1306-0-windows-x64.zip" for this testcase.

Create a new Lazarus project and in its folder extract the following files/folders from the zip:
  • /intl
  • /plugins
  • fbclient.dll
  • firebird.conf
  • firebird.msg
  • ib_util.dll
  • icu*.*
  • msvcp140.dll
  • vcruntime140.dll
  • EMPLOYEE.FDB <-- sample database to use in the application (path in the zip: /examples/empbuild/)
In the Lazarus project, add the following components:
  • IBConnection1
  • SQLTransaction1 --> set its Database property to IBConnection1
  • SQLQuery1 --> set its Transaction property to SQLTransaction1
  • DataSource1 --> set its DataSet property to SQLQuery1
  • DBGrid1 --> set its DataSource property to DataSource1 and adjust it to the form
Add also Button1 and populate its OnClick event with the following code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   IBConnection1.HostName:= '';
  4.   IBConnection1.UserName:= 'SYSDBA';
  5.   IBConnection1.Password:= 'masterkey';
  6.   IBConnection1.DatabaseName:= ExtractFileDir(ParamStr(0)) + '\EMPLOYEE.FDB';
  7.   IBConnection1.Connected:= True;
  8.   SQLQuery1.SQL.Text:= 'select RDB$Relation_Name from RDB$RELATIONS where RDB$Relation_Name not like ''%$%''';
  9.   SQLQuery1.Open;
  10. end;

That's all: press F9 to compile+run the application and then press Button1 --> the grid should connect to EMPLOYEE.FDB through the embedded engine and list all its tables (this is obviously just a small proof of concept).

Handoko

  • Hero Member
  • *****
  • Posts: 5375
  • My goal: build my own game engine using Lazarus
Thank you for sharing your experience on using embedded Firebird 5 in Lazarus for Windows 10. Very useful. I bookmarked this page, I'm sure I will need this information in the future.

 

TinyPortal © 2005-2018