Static linking for Sqlite library for Zeos

Code patches written by our users to solve certain "problems" that were not solved, yet.

Moderators: gto, cipto_kh, EgonHugeist, mdaems

gururamnath
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 05.05.2010, 20:27

Static linking for Sqlite library for Zeos

Postby gururamnath » 05.05.2010, 20:33

Hello,
I have made modifications to make the sqlite library link statically in zeos for DelphiWin32 - so that zeos users dont have to distribute sqlite3.dll. This patch is based on the work by Bouchez - http://blog.synopse.info/ .

I have uploaded the patch to

http://www.twinforms.com/downloads/Zeo_ ... Change.zip

Let me know if this can be part of the main distribution.

Thanks,
Guru Kathiresan

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 12.05.2010, 23:31

This change may very well make it into the official zeoslib distro. It looks very powerful.
Some remarks/questions however:
- 7.x only. If someone wants that experimental code in 6.6 he'll have to patch it himself.
- use a define in zeos.inc to include the code
- if this only works for delphi use {$IFNDEF FPC} in zeos.inc to make sure FPC doesn't try to compile
- use the new driver structure in the plaindrivers correctly : the statically linked driver should be a descendent of TZSQLiteBaseDriver. Then the new Class should be added in TZSQLiteDriver.Create (ZDbcSqlite.pas). I propose you use as protocol-name of your new class something like 'sqlite3static'
- what about the obj files needed? I must admit I don't understand exactly how obj's are be linked in. Are they usable for all delphi versions? Is it legal to distribute them as part of zeoslib?

Mark
Image

gururamnath
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 05.05.2010, 20:27

Postby gururamnath » 14.05.2010, 18:35

Hi Mark,
Thanks for looking at the patch.

1) Since I also have added 6.6 compatible patch, is it possible to add it to the future releases of 6.6 tree ?

2)Since the code is specific to Delphi on Win32 alone, I added a special #define. I dont see any specific defines for Delphi Win32 alone. Since Delphi is coming for Mac and 64 bit in the near future, I thought this would be a safe #define. if you dont agree, then I'll just added #ifndef fpc.

3)As mentioned above this works only for Delphi for Win32 as the Obj file is specific to DelphiWin32. If we want to have something for FPC, then we need to create Sqlite3.obj from GCC compiler and link it.

4)I dont have experience mucking with the drivers yet. I'll see if I can add a separate driver and a new protocol name

5)For Delphi for Win32, the sqlite3.obj and the one with free text option is compiled with Borland C++. In the Delphi Code some of the c-runtime calls used in the obj file are declared and define so that when linking the obj file delphi wont complain about missing c runtime functions. This might be a problem with FPC because almost of the c-runtime code that are added is specific for Intel platform.

The obj file is usable in almost all the Delphi Win32 compilers (so far tested with d7-2010).

Sqlite is a public domain library so there is no problem with the licensing terms and it is perfectly legal to link it statically in any application.

Let me know if you have any other questions.

Thanks,
Guru Kathiresan

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 17.05.2010, 00:14

gururamnath wrote:1) Since I also have added 6.6 compatible patch, is it possible to add it to the future releases of 6.6 tree ?


Sorry, but no. The patch in this form (but for 6.6 no other form is easy I think) is to intrusive in my opinion. As 6.6 is stableI jus can't risk that.
But for people wanting to take that risk the patch you propose should be clear enough, so they can go for it if they want. (People who can not apply it just shouldn't take the risk with a stable version)

gururamnath wrote:2)Since the code is specific to Delphi on Win32 alone, I added a special #define. I dont see any specific defines for Delphi Win32 alone. Since Delphi is coming for Mac and 64 bit in the near future, I thought this would be a safe #define. if you dont agree, then I'll just added #ifndef fpc.

The moment Delphi provides 64 bit I suppose they'll provide an appropriate compiler directive. Until that time we should just ignore this possibility, I believe. So what about ENABLE_SQLITE_STATIC

Code: Select all

{$IFNDEF ZEOS_DISABLE_SQLITE_STATIC}
 {$IFNDEF UNIX}
  {$DEFINE ENABLE_SQLITE_STATIC}
 {$ENDIF}
{$ENDIF}

If you add a {$IFDEF ENABLE_SQLITE_STATIC} around every new line you add that's the safest way to add your code without disturbing existing functionality

gururamnath wrote:3)As mentioned above this works only for Delphi for Win32 as the Obj file is specific to DelphiWin32. If we want to have something for FPC, then we need to create Sqlite3.obj from GCC compiler and link it.

Would a GCC compiled obj file be compatible with Delphi? If yes, I think it would be a good idea to provide only GCC versions. (Might even be possible to provide 64-bit versions that way, isn't it?)
If not, we would have to provide both and give them different names, depending on the version.

gururamnath wrote:4)I dont have experience mucking with the drivers yet. I'll see if I can add a separate driver and a new protocol name

Believe me, that's easy. Even I was able to convert some drivers to that new way of working. (The idea wasn't mine, but I rewrote the mysql and sqlite code)

gururamnath wrote:5)For Delphi for Win32, the sqlite3.obj and the one with free text option is compiled with Borland C++. In the Delphi Code some of the c-runtime calls used in the obj file are declared and define so that when linking the obj file delphi wont complain about missing c runtime functions. This might be a problem with FPC because almost of the c-runtime code that are added is specific for Intel platform.

Sorry, I'm not smart enough to understand this point. (Which is entirely my fault as I'm a linking dummy.

gururamnath wrote:The obj file is usable in almost all the Delphi Win32 compilers (so far tested with d7-2010).

Sqlite is a public domain library so there is no problem with the licensing terms and it is perfectly legal to link it statically in any application.

This is the good news I suppose. I hope the result of a free library compiled by a closed source compiler is also free? If not distributing the obj's as part of zeoslib might be a problem.

Mark
Image


Return to “User Patches”

Who is online

Users browsing this forum: No registered users and 1 guest