SQLCipher ported to Harbour (Windows)

Moderator: Rathinagiri

Post Reply
User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

SQLCipher ported to Harbour (Windows)

Post by Rathinagiri » Thu Feb 09, 2012 7:35 am

I am happy that I could port SQLCipher to Harbour (Windows) successfully:

Here are the steps I have followed to port it to Harbour: (My System is Vista Ultimate, HMG 3.0.40)

If you do not want to know about the build procedure and straightaway use SQLCipher you can go to step 12.

1. Downloaded SQLCipher Source code from here. https://github.com/sqlcipher/sqlcipher/tarball/v2.0.3 This version is based on SQLite version 3.7.9) in c:\sqlcipher

2. Downloaded and installed MingW + Msys latest version from http://sourceforge.net/projects/mingw/f ... urce=files in c:\mingw

3. Downloaded and installed ActiveState TCL from http://www.activestate.com/activetcl/downloads in c:\tcl
TCL is not required for SQLite as such. But MingW & MSys requires TCL to generate some c codes. It requires AWK too. But MingW installation includes AWK. So, there is no problem once you install Mingw + MSys.

4. Downloaded and installed OpenSSL from http://www.slproweb.com/products/Win32OpenSSL.html in c:\openssl

5. Copied c:\openssl\include\openssl folder to c:\mingw\include\openssl

6. Copied c:\openssl\lib\mingw\libeay32.a to c:\mingw\msys\1.0 (This is not required, but I have done for easy path)

7. Opened Command prompt. Set path to mingw and msys using the following commands, changed directory to SQLCipher and opened shell:

Code: Select all

c:\>path=%path%;c:\mingw\bin;c:\mingw\msys\1.0\bin
c:\>cd sqlcipher
c:\sqlcipher>sh
[code]

7. Run configure script as mentioned in SQLCipher site as below in the shell prompt as instructed in SQLCipher.net:
[code]
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="libeay32.a"
8. Once the configuration is over, type make
[/code]
make
[/code]

This command would create many files including amalgamated single sqlite3.c and sqlite3.h

The make command gave many errors, I could not trace out but we need not worry about this as we require only sqlite3.c and sqlite3.h as above.

9. Created a directory sqlcipher inside Harbour folder. Copied sqlite3.c and sqlite3.h to this folder. Copied c:\openssl\lib\libeay32.a to c:\hmg.3.0.40\lib folder for having openssl at the time of application building.

10. Created the following hbc and hbp files:

sqlcipher.hbp file.

Code: Select all

#
# $Id: sqlite3.hbp 16257 2011-02-09 12:47:35Z vszakats $
#

-stop{hbdyn}

-stop{poccarm}
# NOTE: old msvcarm can't cope with some PP directives. [vszakats]
-stop{msvcarm&HB_COMP_VER!='1200'&HB_COMP_VER!='1300'&HB_COMP_VER!='1310')}
# NOTE: dos based watcom runs out of memory. [vszakats]
-stop{HB_HOST_PLAT='dos'&watcom}
# NOTE: disable *nix builds on non-*nix platforms; [vszakats]
#       except for cygwin-on-win
-stop{!(HB_HOST_PLAT='win'&cygwin)&HB_HOST_PLAT_UNIX=''&unix}

-hblib
-inc

-o${hb_targetname}

-warn=low
-cpp=no

-cflag=-DSQLITE_HAS_CODEC
-cflag=-DSQLITE_OMIT_DEPRECATED
-cflag=-DSQLITE_ENABLE_COLUMN_METADATA
-cflag=-D_WIN32_WCE{wce}
# DJGPP and OpenWatcom in DOS aren't correctly recognized by SQLite,
# so we're forcing the next best available option. This will cause missing
# externals though. [vszakats]
-cflag=-DSQLITE_OS_OTHER{dos}
# Watcom Linux builds cannot use system header files
-cflag=-DSQLITE_OS_OTHER{linux&watcom}

-cflag=-DSQLITE_THREADSAFE=0{minix}
-cflag=-DSQLITE_OMIT_LOAD_EXTENSION=1{minix}

sqlite3.c

sqlcipher.hbc

Code: Select all

#
# $Id: sqlite3.hbc 16215 2011-02-05 15:53:17Z vszakats $
#

libs=${hb_name}

cflags=-DSQLITE_OMIT_LOAD_EXTENSION=1{minix}
11. Created buildlib.bat as below and run in the command prompt:

Code: Select all

SET HMGPATH=\hmg.3.0.40

SET PATH=%HMGPATH%\harbour\bin;%HMGPATH%\mingw\bin;%PATH%

hbmk2 sqlcipher.hbp -i%hmgpath%\include
File libsqlcipher.a is created by the above step. Copied this file to c:\hmg.3.0.40\lib folder.

12. Created a sample hmg application to find out whether everything is fine:
sample.prg

Code: Select all

#include <hmg.ch>

Function Main
   local oDB := nil
   local cKey := 'password123'
   local cFile := 'sample.sqlite'
   local aTable := {}
   
   if file( cFile )
      oDB := connect2db( 'sample.sqlite', .f. )
      if oDB == Nil
         msgstop( 'Database File can not be connected' )
      else
         msginfo( iif( miscsql( oDB, 'pragma key = ' + c2sql( cKey ) ), 'Encryption Key is set', 'Encryption key can not be set' ) )
         aTable := sql( oDB, 'select name, city from master' )
         if len( aTable ) > 0
            msginfo( 'Name:' + aTable[ 1, 1 ] + ' City:' + aTable[ 1, 2 ] )
         endif   
      endif   
   else
      oDB := connect2db( 'sample.sqlite', .t. )
      if oDB == Nil
         msgstop( 'Database File can not be connected' )
      else
         msginfo( iif( miscsql( oDB, 'pragma key = ' + c2sql( cKey ) ), 'Encryption Key is set', 'Encryption key can not be set!' ) )
         msginfo( iif( miscsql( oDB, 'create table master (name, city)' ), 'Master table is created successfully!', 'Table can not be created!' ) )
         msginfo( iif( miscsql( oDB, 'insert into master ( name, city ) values ( ' + c2sql( 'Name1' ) + ', ' + c2sql( 'City1' ) + ' )' ), 'Sample Data updated', 'sample data can not be updated!' ) )
      endif
   endif      
Return nil
13. Compiled using the following HMG-IDE configuration:

Code: Select all

inc=yes
head=native
libs=hmgsqlite
libs=sqlcipher
libs=eay32
14. Note: All our applications created using the above libsqlcipher.a library requires libeay32.dll at the runtime. It can be kept in the same directory as application file or can be kept at c:\windows\system32 folder too.

I have enclosed herewith sqlite3.c, sqlite3.h, libsqlcipher.a. Kindly test with your applications and give your feedback.
sqlcipher.zip
(1.95 MiB) Downloaded 461 times
Enjoy HMGing!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
bpd2000
Posts: 1107
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 204 times
Been thanked: 109 times

Post by bpd2000 » Thu Feb 09, 2012 8:01 am

Dear Rathinagiri,

Excellant
BPD
Convert Dream into Reality through HMG

Rossine
Posts: 87
Joined: Thu Jun 30, 2011 10:04 pm

Post by Rossine » Thu Feb 09, 2012 11:33 am

Hello Rathinagiri,

Thanks for sharing :D

Best Regards,

Rossine.

Rossine
Posts: 87
Joined: Thu Jun 30, 2011 10:04 pm

Post by Rossine » Thu Feb 09, 2012 6:56 pm

Hello Rathinagiri,

Is possible use SQLCipher with bcc582 ?

Best Regards,

Rossine.

User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

Post by Rathinagiri » Thu Feb 09, 2012 7:31 pm

IMHO, Yes, you can!

Please change the appropriate build batch file.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Hazael
Posts: 109
Joined: Thu Jun 24, 2010 11:37 am
Location: France

Post by Hazael » Thu Oct 04, 2012 12:43 pm

Really nice!

Well, once you have the .c and .h file + .dll and .hbp/.hbc you can build applications with sqlcypher with any version of harbour, right?

Is there any way to put the .dll in some lib so you do not need to have the external .dll file? I ask that because external .dll files can bring problems sometimes... it can cause conflict with other .dll versions (in this case I would doubt - it applies more to QT and similar ones).

I preffer to have only the .EXE and nothing else (no .DLLs), if possible, of course.

Thanks!
Harbour | GTWVT | MingW | Visual Studio Code

User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

Post by Rathinagiri » Thu Oct 04, 2012 1:08 pm

SQLCipher is based on OpenSSL. So, it requires the runtime library file. However, if we can convert dll files into .a files, we can link that file too.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Hazael
Posts: 109
Joined: Thu Jun 24, 2010 11:37 am
Location: France

Post by Hazael » Fri Oct 05, 2012 3:11 pm

Right. I will try to see if it is possible (I belive it is with something like implib)
Harbour | GTWVT | MingW | Visual Studio Code

User avatar
bpd2000
Posts: 1107
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 204 times
Been thanked: 109 times

Post by bpd2000 » Fri Oct 05, 2012 4:26 pm

rathinagiri wrote:SQLCipher is based on OpenSSL. So, it requires the runtime library file. However, if we can convert dll files into .a files, we can link that file too.
Following will help you

LIB to A converter [Free Open Source program - GNU GPL Licence.]
Link : http://code.google.com/p/lib2a/
BPD
Convert Dream into Reality through HMG

User avatar
Hazael
Posts: 109
Joined: Thu Jun 24, 2010 11:37 am
Location: France

Post by Hazael » Sat Oct 06, 2012 6:16 pm

Thanks but I think I need a .DLL to .A converter (or just link the DLL directly to a static .EXE).

Regards,
Harbour | GTWVT | MingW | Visual Studio Code

Post Reply