Lazy binding related

Hi,

I'm building an application that would connect to either one of the 2 databases in production. I want to keep the source code common for both environments.

The problem lies in the fact that in the target servers there will be only one of the 2 databases installed, hence the application would not be able to start as it would look up for the required libraries even though it wouldnt need them.

Can I use lazy binding here, and make my executable such that it loads libraries only when it needs to use them?

I'm developing on a Linux server and my compiler is gcc.

Thanks
Ishdeep

Yes, you can use dlopen, dlsym, and so on. It just adds a lot more code.
You need to declare common functions - like maybe cursor open, cursor fetch as function pointers.

The real problem is that database apps often use a lot of variable and structs that are peculiar to one db flavor or another, and I cannot say if they will cause problems.

Consider writing a base module that does your operations as a set of very simple operations: update table, open cursor. Then write two sets of basic db intefaces that supply the functions. Link in the interface you want for each machine.

That way your business logic is in a single module, which is what you want.

Thanks Jim!!

What I'm looking for is that, if it's possible to build a common executable using libraries for both databases. But the executable can start even if one of the libraries is missing in the runtime environment.

To illustrate,

Database FirstDB - libDBFirst.so which has a function ConnectFirst()
Database SecondDB - libDBSecond.so has a function ConnectSecond()

Now at runtime I want the executable to lookup these libraries only if its respective function call is made and not try to load both libraries at startup.

Thanks in advance :slight_smile:
Ishdeep