Firebird specials in table structure for varchar and UTF-8

Nov 15

In my Visual Objects applications based on DBFs I have a routine that checks the structure of the DBF tables, compares them with the structure that is required and adjusts the structure.

I’m now working on a similar functionality for my Firebird based .NET applications. To retrieve the list of the currently existing user tables, I’m using such a statement:

select rdb$relation_name as tablename from rdb$relations where rdb$view_blr is null and (rdb$system_flag is null or rdb$system_flag = 0)

and to retrieve the actual structure of such a table I use the following statement:

select rf.rdb$field_position as fieldpos, TRIM(rf.rdb$field_name) as fieldname, f.rdb$field_type as fieldtype, f.rdb$field_length as fieldlen,
f.rdb$field_scale as fielddec, (f.rdb$null_flag = 1) OR (rf.rdb$null_flag = 1) as canbenull from rdb$relation_fields rf JOIN rdb$fields f ON f.rdb$field_name = rf.rdb$field_source WHERE upper( rf.rdb$relation_name ) = upper( 'mytable' ) order by rf.rdb$field_position

To have no limitations with foreign languages, I have opted to use the UTF-8 character set for all varchar columns.

And now I was very surprised: the select statement returned 4 times the actual field width: for a field defined as varchar(20) the query returned 80 as field length.

My conclusion is very simple: since every UTF-8 character can take up to 4 bytes, Firebird reserves 4 bytes for every character.

I have now found the following StackOwerflow article about this:

Firebird 3.0, Embedded server and the .NET provider

Nov 15

For local data, the embedded server of Firebird is very welcome because it does not needs any configuration.

With Firebird 2.5, a special DLL (fbembed.dll) was needed, but Firebird 3.0 has added this functionality into the standard fbclient.dll.
So, if using the embedded server of Firebird 3.0 instead of the one of Firebird 2.5, you need to specify this in the connection string. It is the best to use the ClientLibrary property of the FBConnectionStringBuilder (namespace FirebirdSql.Data.FirebirdClient).

The following files need to be put in your application directory (please make attention to use the correct bitness – 64 bit files for a 64 bit application and 32 bit files for a 32 bit application):

Normally, you should NOT need to put a firebird.conf file in you application directory.


XIDE: Starting without loading the plugins

May 26

Specially for developing XIDE plugins there is a possibility to startup XIDE without loading the plugins:

– keep the shift key pressed while XIDE starts
– add a /noplugins switch to the command line

This functionality was added yesterday ( May 25, 2016 ). So if you need this and your XIDE version is older, ask the author for an update.

XIDE: global variables

May 09

The new XIDE-Build from May 2016 supports the definition of own global variables to use in Pre- and Post-Build events, for example to set some system-wide paths.

Simply add a section [GlobalVariables] to XIDE.cfg, when the program is not open, like this one:

GlobalVariable = %mygeneralmanifest% , C:\temp\mymanifestfile

Later versions may support these variables also in templates.

XIDE: Tools on menu

May 06

You just need to add a section in the bottom of the xide.cfg file:

xml = notepad.exe
txt = wordpad.exe,%1

The 2nd syntax allows you to use command line options, for example

wordpad.exe , /param1 %1 /param2

(%1 is replaced with the filename)

If you press CTRL or SHIFT while opening a file, it gets opened inside XIDE, instead of the tool you specified. Obviously I am just sending it now but not waiting for a quick response, only when you have time about this.

XIDE: Placeholders in prebuild and postbuild events

May 06

The following placeholders are available:


A small sample for the executable cmd.exe:
%AppPath%Prg\App.config %ProjectOutputPath%%ConfigPath%%AssemblyName%.exe.config /y

or preferred by myself:
/c c:\xsharp\xide\postbuildcopy.cmd "%AssemblyName%.dll" "%ProjectOutputPath%%ConfigPath%" "c:\devnet\libs\rdm"

where postbuildcopy.cmd has the following content:
@echo off
set assemblyname=%1
set sourcepath=%2%
set targetpath=%3%
set sourcefile=%sourcepath%\%assemblyname%
set targetfile=%targetpath%\%assemblyname%
if not exist %sourcefile% goto ende
if exist %targetfile% goto replace
copy %sourcefile% %targetfile%
goto ende
replace %sourcefile% %targetpath% /u

XIDE: Plugin system

May 06

XIDE supports a plugin system.

The core of a plugin is to define a class that inherits from Xide.PluginSystem.Plugin and implements the METHOD Initialize() and PROPERTY Name. Initialize() passes you a PluginService object, with which you can communicate with XIDE. Type self:oService: in the sample to get a list of available methods of this class.
After you have built your plugin dll, simply copy it in the plugin subdirectory of the XIDE directory, and it will be loaded on the next start of XIDE.

And this is a sample code by Chris Pyrgas, the author of XIDE:

using Xide.PluginSystem
using System.Windows.Forms

class TestPlugin inherit Xide.PluginSystem.Plugin
protect oService as PluginService
virtual method Initialize(_oService as PluginService) as void

self:oService := _oService

local oMenuItem as MenuItem

oMenuItem := MenuItem{"Add some custom text" , PluginMenuItem_Edit_clicked }
self:oService:RegisterMenuItem(MainMenuItem.Edit , oMenuItem)

oMenuItem := MenuItem{"My Plugin" , PluginMenuItem_Window_clicked }
self:oService:RegisterMenuItem(MainMenuItem.Window , oMenuItem)


method PluginMenuItem_Edit_clicked(o as object,e as EventArgs) as void
local oFilePad as FilePad
local oEditor as Editor
oFilePad := self:oService:GetActiveFilePad()
if oFilePad == null
end if
oEditor := oFilePad:Editor
oEditor:AddLine("// This is some test enetered from the plugin!")

method PluginMenuItem_Window_clicked(o as object,e as EventArgs) as void
local oProject as Project
oProject := self:oService:ActiveProject
if oProject == null
end if
MessageBox.Show("Applications in project " + oProject:Name + " : " + oProject:GetApplications():Length:ToString() , "Message from plugin!")

virtual property Name as string get "A test plugin"

end class

XIDE: Reference templates

May 06

In XIDE, it is possible to add reference templates:

You can edit them through VIDE\Config\References.cfg and they appear in the add references page by pressing the button in the bottom left named “Select from template…”

SideBySide or Registration-Free Activation of Vulcan.NET/X# components

May 06

In this post I will try to list some things that are needed for registration-free use of Vulcan.NET or X# components in Visual Objects applications. Some of these issues have costed me several days of tries.

First, a background article from MSDN: How to: Configure .NET Framework-Based COM Components for Registration-Free Activation

Then: a big “Thank You” to Meinhard Schnoor who has helped me a lot not only with this issue, but often also with other issues.

How SxS (how I will call it to shorten) works basically? I’ll try to simplify at maximum what is needed and where the potential problems stay.

Normally, COM works only with “registered” components. This has some issues:

  • you can only register components from your local machine, not from a network share
  • you need administrative rights to register the component
  • the component registration is global for the machine, you cannot use different versions of the component
  • With SxS things are different:

  • components are called from the program directory without installation
  • every application can use the proper component version
  • of course no administration rights are needed
  • Unfortunately, SxS is very bad documented, and there are not many helpful articles and tools available. And if something goes wrong, it may be very difficult to find out the “why”. sxstrace.exe normally is a help, but not every time. Manifest caching can also disturb.


    Manifests are the basic mechanism for SxS, they are needed for both the component and the executable. The manifest for the component needs to specify the available classes and GUIDs, and the manifest for the executable needs to specify the name of the component. At loading time, the loader first reads the manifest for the executable and then the manifest for the component. If something goes wrong, you exe will not start. Look first in the event viewer and then use sxstrace to see the errors. Because of manifest caching it can be necessary to change the time stamp of your executable (best: regenerate it). Manifests can be standalone (name of the exe or dll with added .manifest extension), or built into the executable. My recommendation would be to use standalone manifests for development and embedded manifests for deployment.


    Every class and also the interfaces need their own GUID – generate a new one with the guidgen tool (You’ll need the Visual Studio Developer Command Prompt for this). Please pay attention to use the right GUIDs!


    The entire system is very sensible to versioning! You need to use the correct version in every place: manifests and component itself (an AssemblyInfo.prg with the correct AssemblyVersionAttribute and the AssemblyFileVersionAttribute entries is needed – otherwise SxS will give no errors, but don’t load the component! This alone has costed me several days of tries.


    Correct naming is the next potential issue: this is not only important for the name of the DLL and for the name of the classes, but also for the namespace used in the component. Name the component the same as the used namespace (and use a namespace!) to save you troubles (with naming errors the registered assembly may work, the SxS loading will fail silently at runtime).

    Any error in one of the components will cause the failure of the entire loading mechanism.

    Getting started with the AdWords API

    Mar 17

    Actually, I have a project where I have to retrieve Google AdWords statistic data and store it locally to generate reports.

    Unfortunately, I lost a lot of time to find out how to start. Therefore you can find here the most important things from the view of a Windows programmer.

    1) request an API token. Google ask something from you, like the use you make, if your software will be distributed, if you plan only read access or also to write. You have also to write a short project description. And if you don’t use your API token for more as 3 months, they will ask you the reason. More informations are here:

    2) decide how you will authenticate. OAuth2 is not very simple to understand. Unfortunately, I had opted first for a service authentication. This one is very complicated and you need a Google Apps domain for it, i.e. one of your domains must be registered for a Google cloud service like GMail or Apps. So my recommendation is to use the APPLICATION authmode.

    3) on the developers console you need then to request a new client ID – as type I opted for “OTHER”, as my project is neither a web project, nor a mobile app.

    4) for the authentication you need basically 4 things: your API token, a client ID, a client secret and a refresh token. The API token you should have from step 1, client ID and client secret come from step 3, and the refresh token will be described later.

    5) generate an AdWords account that has read-only access to the Adwords accounts you need – if you are a developer like me, ask the Adwords guys of your company.

    6) download the client libraries here I would recommend to download the entire project as ZIP and build the client libraries yourself – open the Visual Studio solution file and build all. In this solution you will find a lot of useful things: not only the complete source code of the client libraries, but also samples in C# and VB.NET

    7) the OAuth2 flow is not so easy to implement – I have used the OAuthTokenGenerator application from the client libraries from step 6. This application (beware: you have to start this application with elevated rights as it uses internally the httpListener class!) gives you the last pieces needed for authentication: the refresh token

    8) use the samples from the client libraries to understand how the entire API works. It is very well documented, and the fact that you have the sources is very helpful. For the authentication best you use the app.config file (yourApplication.exe.config), copy it from the sample in the client library and replace the authentication data

    9) last error I made: the AdWords account I used had no campaigns in it since it was the account of the company itself, I had to use one of the customer accounts and set it not in the .config file, but in my program. How this can be accomplished, is documented in the app.config file.

    I have to make a compliment to Google: they are very helpful, the API is well documented and you have the full sources to it.