@Vodnik. You have not stated what database you are working with. If it is powerful enough, like MS SQL Server, there is lot of ways to achieve desired results. You client application can run a query at start-up to make temporary lookup tables; it may be a case statement with 50 options, but you run it only once and use as long as you connection is active.
Another suggestion is to separate Pascal code from any other languages, be it SQL, HTML, XML or what ever else you program may work with. This makes life much easier.
Seems to be running off-topic.