Page 1 of 1

Compiling out 'undesired' database drivers

Posted: 14.01.2009, 16:36
by mdaems
Hi,

Quite some people want an option to exclude some zeoslib database drivers from their projects, simply because they don't use these databases.
I'm happy to tell you the Parameters documentation file now also has this new chapter.
1. Project options
==================
1.1. Conditional Defines
========================

It is possible to avoid databasedrivers are compiled into your program
executable if you're not planning to support the use of them. You can do
this by commenting out the ENABLE_XXXX DEFINES in zeos.inc before
compiling and installing zeoslib.

A more flexible way is to install zeoslib using the standard zeos.inc
file and add some conditional DEFINE's to your project options. Supported
values are:

* ZEOS_DISABLE_MYSQL
* ZEOS_DISABLE_ORACLE
* ZEOS_DISABLE_SQLITE
* ZEOS_DISABLE_ASA
* ZEOS_DISABLE_INTERBASE
* ZEOS_DISABLE_DBLIB
* ZEOS_DISABLE_POSTGRESQL
* ZEOS_DISABLE_ADO

To use this feature you must add the zeoslib source dir's to the search
path of your project. So only the required features will be compiled in
your project executable. (Make sure the zeoslib units are recompiled as
well)
I know some people think different about it. eg. By encapsulating driver specific code into a new component you'd have to add to your project, like a TZMysqlDriver that you can connect to a ZConnection.

Two reasons why I did not do it that way:
- Impossible to do that to a stable version.
- It's against the easy swapping principle zeoslib currently uses. Setting a new protocol (eg using an ini file read by your program) is much easier than adding a new component, because last option needs recompilation.

BTW : if you think you never swap just by setting an ini-file : this trick enabled one of my projects to change data import on the fly when a third party program decided to use an other database. Copied the right dll next to my program, changed the parametrised query and changed the protocol setting from mysql to firebird.

This change will be committed to testing branch in a few minutes. (I need the id of this post for the documentation). When the response looks allright I'll also move the changes to 6.6-patches soon.

Mark

Posted: 29.01.2009, 19:12
by trupka
Hi,
works fine for me, but it would be nice to achieve different compiler modes (typicality DEBUG/RELEASE) without editing Zeos.inc. That's not currently possible because of {$D+} directive in line 182 (testing branch rev.573) but can be easily achieved with some additional defines.
I'm willing to make patch if You are interested.

Posted: 29.01.2009, 23:14
by mdaems
What about

Code: Select all

{$IFDEF ZEOSDEBUG}
{$D+}
{$ELSE}
{$D-}
{$DEFINE BINARY_RELEASE}
{$ENDIF}
?

Posted: 30.01.2009, 14:29
by trupka
Something like that, maybe a few more "improvements"

Code: Select all

// Debug/release compiler options
{$IFDEF DEBUG}
    {$DEFINE ZEOSDEBUG}
{$ELSE}
    {$DEFINE BINARY_RELEASE}
{$ENDIF}

{$IFDEF ZEOSDEBUG}
    {$D+}
{$ELSE}
    {$D-}
    {$DEFINE BINARY_RELEASE}
{$ENDIF}

{$IFDEF BINARY_RELEASE}
    // Settings for Release mode
    {$C-}
    {$I-}
    {$R-}
    {$L-}
    {$Q-}
    {$IFNDEF FPC}
        {$O+}
        {$W-}
    {$ENDIF}
{$ELSEIF ZEOSDEBUG}
    // Settings for Debug mode
    {$C+}
    {$I+}
    {$R+}
    {$L+}
    {$Q+}
    {$IFNDEF FPC}
        {$O-}
        {$W+}
    {$ENDIF}
{$IFEND}
And here's explanation:
There are two "kinds" of ZEOS programmers, lets call them:
- ZEOS users - use ZEOS in their own project without going too deep into ZEOSlib, debugging/modifying. I believe they are in majority and most of them just compile ZEOS within Delphi IDE and start to use it.
- ZEOS developers - they work on ZEOS itself. No explanations necessary...
Another thing - newer Delphi versions come with MSBuild with some predefined defines (DEBUG/RELEASE) which we can put into use. My idea is:
- default target is RELEASE - compile it and use it, ideal for "users".
- those who want to debug ZEOS itself have enough knowlege to define DEBUG for entire project or ZEOSDEBUG if they want to debug ZEOS only.
"Old delphi"/FPC users - default target is RELEASE, but that's what most of us need most of the time :)

Posted: 30.01.2009, 14:46
by mdaems
Wouldn't this version automatically enable zeoslib debugging for all users when they enable simply 'DEBUG' for their own project? I believe we should just keep with the special ZEOSLIB_DEBUG define to force users to add it when they want to build a debug version.
ALSO : The ZEOSDEBUG option alone would make a BINARY_RELEASE in your version. Exactly the opposite result.

Code: Select all

// Debug/release compiler options
{$IFDEF ZEOSDEBUG}
    {$D+}
{$ELSE}
    {$D-}
    {$DEFINE BINARY_RELEASE}
{$ENDIF}

{$IFDEF BINARY_RELEASE}
    // Settings for Release mode
    {$C-}
    {$I-}
    {$R-}
    {$L-}
    {$Q-}
    {$IFNDEF FPC}
        {$O+}
        {$W-}
    {$ENDIF}
{$ELSE}
    // Settings for Debug mode
    {$C+}
    {$I+}
    {$R+}
    {$L+}
    {$Q+}
    {$IFNDEF FPC}
        {$O-}
        {$W+}
    {$ENDIF}
{$IFEND} 

Posted: 30.01.2009, 15:19
by trupka
mdaems wrote:Wouldn't this version automatically enable zeoslib debugging for all users when they enable simply 'DEBUG' for their own project?
You got me thinking...
Well.. yes and no. Yes if they include ZEOS source path into compiler library/search path (I rarely do that for application-building so it didn't even cross my mind). No if they use precompiled dcu's. Of course, "worst case" must be taken into consideration so:
mdaems wrote:I believe we should just keep with the special ZEOSLIB_DEBUG define to force users to add it when they want to build a debug version.
Agreed, ZEOS debugging should newer be unintentionally activated.
mdaems wrote:ALSO : The ZEOSDEBUG option alone would make a BINARY_RELEASE in your version. Exactly the opposite result.
Sorry, I can't see how/where??

Posted: 30.01.2009, 15:23
by mdaems

Code: Select all

{$IFDEF DEBUG}
    {$DEFINE ZEOSDEBUG}
{$ELSE}
    {$DEFINE BINARY_RELEASE}
{$ENDIF} 
does {$DEFINE BINARY_RELEASE} if the DEBUG define isn't set...

Mark

Posted: 30.01.2009, 15:44
by trupka
Aarrghhh! :oops:
To excuse myself: 24/7 babysitting of 8-month boy had some impact on my mental health :)

This code works fine...

Code: Select all

// Debug/release compiler options
{$IFDEF ZEOSDEBUG}
    {$D+}
{$ELSE}
    {$D-}
    {$DEFINE BINARY_RELEASE}
{$ENDIF}

{$IFDEF BINARY_RELEASE}
    // Settings for Release mode
    {$C-}
    {$I-}
    {$R-}
    {$L-}
    {$Q-}
    {$IFNDEF FPC}
        {$O+}
        {$W-}
    {$ENDIF}
{$ELSE}
    // Settings for Debug mode
    {$C+}
    {$I+}
    {$R+}
    {$L+}
    {$Q+}
    {$IFNDEF FPC}
        {$O-}
        {$W+}
    {$ENDIF}
{$ENDIF}