Installing Firebird 3.06 on Ubuntu 18.04.5 LTS

September 21st, 2020

Thanks to my inexperience with the Ubuntu package manager, and my talent for breaking software, I managed to trash my Ubuntu installation recently to the point where it wouldn’t even boot.  It gave me the opportunity to test my backups, and I’m happy to say that re-installing Ubuntu with a restore of data, with some re-installation of apps got me pretty much back to where I was.  I did however, encounter an issue where Ubuntu would not login to the GUI.  Thankfully I eventually found this post, which solved the problem.

The original issue started around the installation of Firebird 3.0.5 for Linux. It appeared the installer needed a file libtommath.so.0 which was not present on my distro.  I thought I had gotten it installed properly, then I ran into the infamous “COLLATION UNICODE_CI_AI for CHARACTER SET UTF8 is not installed” error.  I managed to get past that, but when I opened the database in an FMX app using FireDAC in local mode I got an exception “N8Firebird16status_exceptionE”.   FlameRobin would open it without issue.  If I chose Break in the exception dialog it looked for the source to libstdc++.so.6. The exception was in a call to isc_attach_database or isc_dsql_fetch.  I assumed it was an incompatibility between FireDAC and the standard C++ library.

It turns out I had gotten myself into a mess trying to get the libtommath file.  I broke some package references and when I tried to fix them, a slew of packages were removed.  I was warned not to continue unless I knew what I was doing, but when has that stopped me?  Also there didn’t seem to be any alternative to fix the package manager’s complaint that things were broken even if everything still seemed functional.  Ah live and learn…

This time I tried installing Firebird 3.06 thinking it was newer and might address some of the problems I had encountered….nope.  This time I used a symlink ( sudo ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 ) to resolve the missing libtommath.

Then I got a completely new error in the FMX deployment code.  It attempted to create a hidden folder “/home/<username>/.fmxlinux” which contains “libfmux-1.48.so”.  I did not invoke paserver with sudo so I didn’t have adequate permissions and got an EFCreateError exception with an empty message triggered by line 9345 of System.Classes.  I only mention that because the message should contain the filename being created and the OS error message but it did not.

After resolving the permission issue, I re-confirmed that even on my fresh Linux/Firebird install, I still get an exception when attempting to access my database, which of course pertains to the missing collation.  Since I didn’t make note of how I resolved the collation error when I installed 3.05 I can’t be sure what I did, or whether the “resolution”  did not truly work.

Reading the “Release notes for Firebird 3.06″ I saw they had upgraded the ICU libraries to v52.1 so I downloaded the package and installed it.  Re-starting Firebird the collation error was resolved and neither FireDAC or FlameRobin reported the “N8Firebird16status_exceptionE” error any longer.  Obviously whatever I did to fix the collation error when I installed Firebird 3.05 was not correct despite the fact I was no longer getting the collation exception.

I hope this helps someone else install FireBird 3.06 on Ubuntu/Debian and saves them all the time I spent searching for solutions to the myriad of issues I encountered including my own folly.

I Just Don’t GetIt

September 17th, 2020

In case you were wondering, GetIt appears to be down at the moment.  I went to take 5 minutes to update a bug report, and I needed to install FmxLinux to do so, only to see:

GetIt Not Accessible

GetIt Not Accessible

I guess it will have to wait.  This is the problem of automating everything.  You become reliant on services that need to be up 24×7 or the odds are they will impede your work at some point.

UPDATE:  GetIt is back up now.

Ubuntu is better with WINE

September 15th, 2020

It’s been a couple of years since I made the jump to Ubuntu 18.04 LTS as my primary operating system, thanks in no small part to Windows 10 updates and BODs.

It all started when I loaded my Toshiba Satellite L70D laptop with an SSD and Ubuntu to try to extend its usable lifetime. To give you an idea how old it is, the laptop shipped with Windows 8.1 on it, and I bought it because it was one of the few 17″ laptops still available at the time.  I would have bought a 17″ Macbook Pro after my 15″ died, but it seemed Apple

and other manufacturer’s were no longer making 17″ laptops.  Now you can find numerous 17″ PC laptops aimed at the gaming market.  Anyway, the laptop ran well and I discovered I could run VMs using VirtualBox reliably.  I had been using VMWare Fusion before, and had tried earlier versions of VirtualBox with no success.

I had been looking for a lean OS on which to run numerous VMs.  I was considering OS/X, but there is definitely a cost premium for the hardware, and the choices available are more limited than the clone market.  I even thought about a Hackintosh but didn’t really want to explore EULA violations and support issues for updates.

After discovering all the major software I was using had Ubuntu supported versions, I decided to take the jump and load it on my new (at the time) desktop.  While I ran into a few VirtualBox issues along the way I have never lost any data so far, and would have to say that my experience rivals the commercial VM software I have used.  I’ve also had no hardware support issues like I had experienced previously when trying out Linux distros.

Linux seems to have matured enough that even a noob with a little Googling can find the solution to any issue or question I have had thus far.  Of course I chose Ubuntu because it is one of the largest distros, so it’s a relatively safe choice, but other distros I played with seemed just as viable.

Recently I wanted to see if a personal VCL project would run natively under Ubuntu.  I was contemplating making an FMX version just to have it natively on Linux without using a VM.  The app uses a dynamic plug-in architecture with run-time packages.  It is based on code I originally received from Mark Miller; the author of Coderush for Delphi and DevExpress’ Coderush for .NET.  The project also uses Firebird 3.0 embedded, and the VirtualTreeView in grid mode, since it’s open source and lightning fast.

I tried CrossVCL’s VTreeView demo only to find out that it is indeed a work in progress.  It’s VTreeView support has some painting issues and run-time exceptions were thrown so I knew I needed to find another way to get my VCL app onto Ubuntu without using VirtualBox.  The other night I thought I would see if I could get it to work under WINE.  I installed Q4Wine from the Ubuntu software app, and added my application EXE with the default settings.  Much to my surprise, it fired right up.  I even managed to make an Ubuntu shortcut and add it to my favorites.

CompositeApp running on Ubuntu 18.04LTS with WINE

Embedding Firebird 3.0X

September 1st, 2020

With Firebird 3.0X releases there is no longer a separate install for embedded deployments.  In fact the guidance essentially is to use the ZIP package and customize it as desired.  If you want a minimal deployment, it’s difficult to know what files are absolutely necessary, unless you are very familiar with the project.

I recently had a need to distribute an application for testing, and didn’t want the users to have to install the Firebird server.  The target audience is also well suited to an embedded install, so I thought I would try it out.  With the help of ProcessMonitor and the aforementioned guidance documentation I discovered that the following files seem to be the bare requirements:

firebird.conf
databases.conf
plugins.conf
msvcr100.dll
msvcp100.dll
icuuc52.dll
icuin52.dll
icudt52l.dat
icudt52.dll
ib_util.dll
fbclient.dll
plugins\engine12.dll
plugins\fbtrace.dll

I am using Local DB access via FireDAC with Delphi 10.4 and tested this configuration by simply unzipping the files including my app, and the database into a Win7 VM and running it.  Firebird weighs in at about 16Mb where my app and it’s supporting DLLs are 40Mb with Debug info.

Getting Cross with CrossVCL

August 17th, 2020

Thought I would give CrossVCL VirtualTreeView support a look see, but when I installed it I couldn’t even run any sample applications.  Kept getting “ld-linux.exe: error: cannot find -lGL”.  Being a Linux newbie I searched the KSDEV CrossVCL issue forum and FAQ thought I was onto something, but after expanding the compiler messages I discovered it was GTK3 related.

A little googling and I found this post which explains that if you want to compile apps for GTK3 you need to change the version of the GTK3 libs that come with Ubuntu 18.04 LTS.

To use gtk2 or gtk3 apps you don’t need to install anything. But, if you want to develop (or even just compile) apps this is what you’re looking for:

sudo apt-get install libgtk-3-dev

After issuing the command above and updating the SDK I was able to compile and run CrossVCL apps.  No need to get cross, just the correct libs.

Another GExperts GEM

August 11th, 2020

I’ve used GExperts for some time, and I keep finding gold nuggets or gems as the saying goes, that make it easier to accomplish day to day tasks.

GIT may be  a great version control system, but it probably contributes to a lot of task switching, which can impact productivity.  For instance, I often need to switch branches to address smaller issues, or make a fix for something QA has found during testing of a fix (hey..sh..it happens…).  Each time I do so, all the files I had open in the IDE for that particular issue, are lost in terms of knowing which ones they were.  AFAIK (as far as I know) there is no way to have the IDE save this information such that when you switch branches it will be preserved.  The IDE will save the current open file list in a project DSK file so it can restore them, but if you have the DSK file in version control, switching branches will replace it.  DSKs are normally not versioned because sharing them between developers is not desirable.  If it’s not in version control, saving it on a different branch will overwrite the list of files.  What is the solution?

One potential solution is to use GExperts Favorites feature.  You can create folders for each set of files (by project or issue # for instance),  Then just add the files you want and next time you switch you can easily re-open the files of interest from your favorites.  It even has the ability to add your Favorites to the File menu.

One of the great things about Delphi’s IDE is the OpenTools API which allows for such extensive add-ins, and Thomas Mueller has put a lot of effort in maintaining and evolving the project.  Thanks!

hcOPF supports Delphi 10.4 Sydney

July 25th, 2020

Things have been a little crazy in case you hadn’t noticed.  Between COVID-19, the economic fallout and all the turmoil in our nearest neighbour, I plum forgot to blog about updating hcOPF to support Delphi Sydney 10.4.

It might also be because adding support for a newer compiler version doesn’t take a great deal of effort. I normally just copy the ones from the previous version, and modify them as needed for the new one.  It would of course be a whole lot easier if {$LIBSUFFIX AUTO} was implemented and I could use that as well (or something like it) to set the output folder. Then I wouldn’t even need to make a copy and update the projects!

DevExpress now Supporting FMX

July 24th, 2020

I was so excited when I read Frank’s post today about DevExpress offering a FMX grid control.  So I went to download it, only to discover that in order to get the CTP release, an * “Active VCL Subscription or Express GridPack is required”.

Sadly I don’t personally have an active subscription so looks like I will have to wait until the release to give it a spin.  For those of you lucky enough to meet the requirements, who haven’t already purchased a TMS or Infpower grid for FMX, let me know what you think.  For the VCL, the Quantum Grid has practically been the defacto standard in most applications I’ve worked on, so I’m very interested to see what DexExpress is offering for FMX.

DevExpress took a wait and see position with FMX, so it’s very encouraging for the Delphi ecosystem to see them throw their hat into the ring.

10.4 Good Buddy

May 27th, 2020

For a long time there has been a lot of complaints about Error Insight in Delphi giving more false positives (red swiggly lines) than actual problems. It also slowed down the IDE so much that I for one, simply turned it off to avoid the noise and IDE lag. Code Insight also had it’s fair share of issues in terms of parsing blocking the IDE main thread making it unresponsive. The suggestions were not always relevant either.

Then there were IDE updates distributed as a ZIP file that you had to manually unzip and place the files in the correct installation subfolders. There wasn’t even a way to automatically find out if patches were available. The larger updates even required a re-install.

If you thought EMBT did not hear you, they just responded with a big 10-4; RAD Studio/Delphi 10.4. This is arguably the most significant release since Delphi 7. The new Delphi LSP unifies all the IDE code parsing, providing the compiler’s interpretation of the code. This makes Code and Error Insight much faster without blocking the IDE main thread so you can continue to actually use the IDE to….code. It also makes Code and Error Insight, well… more insightful.

Besides the plethora of fixes, there are other major features like managed records and the unification of all platform memory models, and another personal favourite that caught me by surprise; GetIt can now apply patches.

If you’re not on subscription or haven’t updated your Delphi version for some time, 10.4 is a release worthy of getting to know.

Exit Stage Left

May 8th, 2020

The Exit procedure has been around as long as Goto in Object Pascal.  Goto is considered an antiquated command, but what about about Exit?  When should it be used if at all?

I have often seen guard code at the beginning of a method that performs an Exit if the parameters passed are not appropriate or indicate the method does not need to act on the parameters passed.  This might happen in a method like this:

procedure TSomeForm.CheckHaveID(const AID: string);
begin
  if AID <> EmptyStr then
    Exit;

  ...other code to populate AID if necessary...
end;

In this case the first few lines are a common place to see such guard code. In fact, guard code is usually only in place to throw exceptions to let the developer know prerequisites have not been met. Exit calls may be more applicable depending on the purpose of the method but I would caution that taking this to extreme is the equivalent of making a function that returns a boolean for success and then never checking the result in the calling code. It’s a bad practice that will one day bite you. Pick a strategy, document it, and adhere to it. Consistency is king even if the code is less than ideal. Consistent code is easier to re-factor later.

Anyway, I digress, contrast the first method to the following:

procedure TSomeForm.CheckHaveID(const AID: string);
begin
  if not FIShouldCallCheckHaveID then
    Exit;

  if AID <> EmptyStr then
    Exit;

  ...other code to populate AID if necessary...
end;

Here a private field variable is accessed within the called method to determine if the called method should in fact have been called. Seems a little “ass backwards” to me. You don’t go to Vegas and then ask yourself “should I be in Vegas?”. You think before you act. If the method should not have been called, then the caller should make that determination and simply not call it. There is overhead with every method call.

What has also happened now, is that the CheckHaveID method is coupled to the form, making refactoring harder. This is the problem with business logic being tied to a form. Business logic needs to be applied throughout the application but it can’t do that if some variation is embedded in all related forms. Let’s say I want to pull the CheckHaveID method out into another unit as a classless or static class method so it can be shared in another form. Now I have to deal with changing the calling logic to account for the FIShouldCallCheckHaveID condition. If this had been done in the first place the risk of breaking code would have been non-existent.

The argument can be made that if you have 5 early Exits these tests should not be duplicated in every place the method is called, that it just doesn’t make sense. I would respond to such a statement that code duplication is a primary code smell that should result in re-factoring, In this case, all 5 instances of the calling code would be extracted into another method where the decision would be made. Just because putting the logic test in guard code eliminates duplication doesn’t mean you’re putting it in the right place.

In my opinion conditional flow logic should be implemented in the caller. In keeping with the Single Responsibility Principle, a method should do one and only one thing and it’s name should reflect exactly what it does. This keeps code readable and understandable. That was the whole purpose behind step-wise refinement I was taught in Computer Science. Embedding business logic (execution flow) in a method that is named DoX means it should not also do Y. Such code requires minimal documentation because it’s name says it all (well almost).

Structured programming purists would say never use Exits, but more modern engineers like Martin Fowler are advocate smaller methods with multiple Exits. The keyword here is smaller methods. In legacy code I’ve seen methods spanning several hundred lines. Try to find an Exit call in that code!

Not using Exit calls can certainly increase the level of nested if..then..else statements which can also be hard to follow and lead to bugs if begin/end blocks are not used. Again size does matter (method size).

I think as with most things in life, there is a balance, and at a certain point it becomes a personal choice but I think in at least this case, I have made an argument for avoiding the code shown.

Delphi Basics site sums it up quite nicely:

Warning : use with caution - jumping is a concept at odds with structured coding - it makes code maintenance difficult.