[harbour-users] SQLCipher ported to Harbour (Windows -
MingW)
2/9/12
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.
based on SQLite version 3.7.9) in
c:\sqlcipher
2. Downloaded and installed MingW + Msys latest version
from
in c:\mingw
3. Downloaded and installed ActiveState TCL
from
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.
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]
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"
[/code]
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]
#
# $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
[/code]
sqlcipher.hbc
[code]
#
# $Id: sqlite3.hbc 16215 2011-02-05 15:53:17Z vszakats
$
#
libs=${hb_name}
cflags=-DSQLITE_OMIT_LOAD_EXTENSION=1{minix}
[/code]
11. Created buildlib.bat as below and run in the
command prompt:
[code]
SET HMGPATH=\hmg.3.0.40
SET
PATH=%HMGPATH%\harbour\bin;%HMGPATH%\mingw\bin;%PATH%
hbmk2 sqlcipher.hbp -i%hmgpath%\include
[/code]
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]
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
[/code]
13. Compiled using the following HMG-IDE
configuration:
[code]
inc=yes
head=native
libs=hmgsqlite
libs=sqlcipher
libs=eay32
[/code]
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.
You can download sqlcipher compiled library from here
(http://
and give your feedback.
Enjoy HMGing!
Long time ago I struggled to do all that and I got very close but I
never completed the whole process and I had to change my focus to some other
pressing needs so I gave up and just used the lib Rathinagiri generated (last
one in Aug/2014) - although I am still
interested in building the lib myself.
I hope it will help
you...