forked from softace/sqliteodbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mingw-cross-build.sh
executable file
·1688 lines (1550 loc) · 53.9 KB
/
mingw-cross-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#
# Build script for cross compiling and packaging SQLite
# ODBC drivers and tools for Win32 using MinGW and NSIS.
# Tested on Fedora Core 3/5/8, Debian Etch, RHEL 5/6
#
# Cross toolchain and NSIS for Linux/i386/x86_64 can be fetched from
# http://www.ch-werner.de/xtools/crossmingw64-0.3-1.i386.rpm
# http://www.ch-werner.de/xtools/crossmingw64-0.3-1.x86_64.rpm
# http://www.ch-werner.de/xtools/nsis-2.37-1.i386.rpm
# or
# http://www.ch-werner.de/xtools/crossmingw64-0.3.i386.tar.bz2
# http://www.ch-werner.de/xtools/crossmingw64-0.3.x86_64.tar.bz2
# http://www.ch-werner.de/xtools/nsis-2.37-1_i386.tar.gz
# Some aspects of the build process can be controlled by shell variables:
#
# NO_SQLITE2=1 omit building SQLite 2 and drivers for it
# NO_TCCEXT=1 omit building TCC extension
# WITH_SOURCES=1 add source directory to NSIS installer
# SQLITE_DLLS=1 build and package drivers with SQLite 2/3 DLLs
# SQLITE_DLLS=2 build drivers with refs to SQLite 2/3 DLLs
# SQLite3 driver can use System.Data.SQlite.dll
set -e
VER2=2.8.17
VER3=3.7.16.1
VER3X=3071601
VERZ=1.2.7
TCCVER=0.9.25
nov2=false
if test -n "$NO_SQLITE2" ; then
nov2=true
ADD_NSIS="-DWITHOUT_SQLITE2"
fi
notcc=false
if test -n "$NO_TCCEXT" ; then
notcc=true
ADD_NSIS="$ADD_NSIS -DWITHOUT_TCCEXT"
else
export SQLITE_TCC_DLL="sqlite+tcc.dll"
fi
if test -f "$WITH_SEE" ; then
export SEEEXT=see
ADD_NSIS="$ADD_NSIS -DWITH_SEE=$SEEEXT"
if test "$SQLITE_DLLS" = "2" ; then
SQLITE_DLLS=1
fi
fi
if test "$SQLITE_DLLS" = "2" ; then
# turn on -DSQLITE_DYNLOAD in sqlite3odbc.c
export ADD_CFLAGS="-DWITHOUT_SHELL=1 -DWITH_SQLITE_DLLS=2"
ADD_NSIS="$ADD_NSIS -DWITHOUT_SQLITE3_EXE"
elif test -n "$SQLITE_DLLS" ; then
export ADD_CFLAGS="-DWITHOUT_SHELL=1 -DWITH_SQLITE_DLLS=1"
export SQLITE3_DLL="-Lsqlite3 -lsqlite3"
export SQLITE3_EXE="sqlite3.exe"
ADD_NSIS="$ADD_NSIS -DWITH_SQLITE_DLLS"
else
export SQLITE3_A10N_O="sqlite3a10n.o"
export SQLITE3_EXE="sqlite3.exe"
fi
if test -n "$WITH_SOURCES" ; then
ADD_NSIS="$ADD_NSIS -DWITH_SOURCES"
fi
echo "=================="
echo "Preparing zlib ..."
echo "=================="
test -r zlib-${VERZ}.tar.gz || \
wget -c http://zlib.net/zlib-${VERZ}.tar.gz || exit 1
rm -rf zlib-${VERZ}
tar xzf zlib-${VERZ}.tar.gz
ln -sf zlib-${VERZ} zlib
echo "===================="
echo "Preparing sqlite ..."
echo "===================="
( $nov2 && echo '*** skipped (NO_SQLITE2)' ) || true
$nov2 || test -r sqlite-${VER2}.tar.gz || \
wget -c http://www.sqlite.org/sqlite-${VER2}.tar.gz
$nov2 || test -r sqlite-${VER2}.tar.gz || exit 1
$nov2 || rm -f sqlite
$nov2 || tar xzf sqlite-${VER2}.tar.gz
$nov2 || ln -sf sqlite-${VER2} sqlite
# enable sqlite_encode_binary et.al.
$nov2 || patch sqlite/main.mk <<'EOD'
--- sqlite.orig/main.mk 2005-04-24 00:43:23.000000000 +0200
+++ sqlite/main.mk 2006-03-16 14:29:55.000000000 +0100
@@ -55,7 +55,7 @@
# Object files for the SQLite library.
#
LIBOBJ = attach.o auth.o btree.o btree_rb.o build.o copy.o date.o delete.o \
- expr.o func.o hash.o insert.o \
+ expr.o func.o hash.o insert.o encode.o \
main.o opcodes.o os.o pager.o parse.o pragma.o printf.o random.o \
select.o table.o tokenize.o trigger.o update.o util.o \
vacuum.o vdbe.o vdbeaux.o where.o tclsqlite.o
EOD
# display encoding
$nov2 || patch sqlite/src/shell.c <<'EOD'
--- sqlite.orig/src/shell.c 2005-04-24 00:43:22.000000000 +0200
+++ sqlite/src/shell.c 2006-05-23 08:22:01.000000000 +0200
@@ -1180,6 +1180,7 @@
" -separator 'x' set output field separator (|)\n"
" -nullvalue 'text' set text string for NULL values\n"
" -version show SQLite version\n"
+ " -encoding show SQLite encoding\n"
" -help show this text, also show dot-commands\n"
;
static void usage(int showDetail){
@@ -1297,7 +1298,10 @@
}else if( strcmp(z,"-echo")==0 ){
data.echoOn = 1;
}else if( strcmp(z,"-version")==0 ){
- printf("%s\n", sqlite_version);
+ printf("%s\n", sqlite_libversion());
+ return 1;
+ }else if( strcmp(z,"-encoding")==0 ){
+ printf("%s\n", sqlite_libencoding());
return 1;
}else if( strcmp(z,"-help")==0 ){
usage(1);
@@ -1330,9 +1334,9 @@
char *zHome;
char *zHistory = 0;
printf(
- "SQLite version %s\n"
+ "SQLite version %s encoding %s\n"
"Enter \".help\" for instructions\n",
- sqlite_version
+ sqlite_libversion(), sqlite_libencoding()
);
zHome = find_home_dir();
if( zHome && (zHistory = malloc(strlen(zHome)+20))!=0 ){
EOD
# use open file dialog when no database name given
# need to link with -lcomdlg32 when enabled
true || patch sqlite/src/shell.c <<'EOD'
--- sqlite.orig/src/shell.c 2006-07-23 11:18:13.000000000 +0200
+++ sqlite/src/shell.c 2006-07-23 11:30:26.000000000 +0200
@@ -20,6 +20,10 @@
#include "sqlite.h"
#include <ctype.h>
+#if defined(_WIN32) && defined(DRIVER_VER_INFO)
+# include <windows.h>
+#endif
+
#if !defined(_WIN32) && !defined(WIN32) && !defined(__MACOS__)
# include <signal.h>
# include <pwd.h>
@@ -1246,6 +1250,17 @@
if( i<argc ){
data.zDbFilename = argv[i++];
}else{
+#if defined(_WIN32) && defined(DRIVER_VER_INFO)
+ static OPENFILENAME ofn;
+ static char zDbFn[1024];
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFile = (LPTSTR) zDbFn;
+ ofn.nMaxFile = sizeof(zDbFn);
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
+ if( GetOpenFileName(&ofn) ){
+ data.zDbFilename = zDbFn;
+ } else
+#endif
data.zDbFilename = ":memory:";
}
if( i<argc ){
EOD
# same but new module libshell.c
$nov2 || patch sqlite/main.mk <<'EOD'
--- sqlite.orig/main.mk 2007-01-10 19:30:52.000000000 +0100
+++ sqlite/main.mk 2007-01-10 19:33:39.000000000 +0100
@@ -54,7 +54,7 @@
# Object files for the SQLite library.
#
-LIBOBJ = attach.o auth.o btree.o btree_rb.o build.o copy.o date.o delete.o \
+LIBOBJ += attach.o auth.o btree.o btree_rb.o build.o copy.o date.o delete.o \
expr.o func.o hash.o insert.o encode.o \
main.o opcodes.o os.o pager.o parse.o pragma.o printf.o random.o \
select.o table.o tokenize.o trigger.o update.o util.o \
EOD
$nov2 || cp -p sqlite/src/shell.c sqlite/src/libshell.c
$nov2 || patch sqlite/src/libshell.c <<'EOD'
--- sqlite.orig/src/libshell.c 2007-01-10 19:13:01.000000000 +0100
+++ sqlite/src/libshell.c 2007-01-10 19:25:56.000000000 +0100
@@ -20,6 +20,10 @@
#include "sqlite.h"
#include <ctype.h>
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
#if !defined(_WIN32) && !defined(WIN32) && !defined(__MACOS__)
# include <signal.h>
# include <pwd.h>
@@ -1205,7 +1209,7 @@
strcpy(continuePrompt," ...> ");
}
-int main(int argc, char **argv){
+int sqlite_main(int argc, char **argv){
char *zErrMsg = 0;
struct callback_data data;
const char *zInitFile = 0;
@@ -1246,6 +1250,17 @@
if( i<argc ){
data.zDbFilename = argv[i++];
}else{
+#if defined(_WIN32) && !defined(__TINYC__)
+ static OPENFILENAME ofn;
+ static char zDbFn[1024];
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFile = (LPTSTR) zDbFn;
+ ofn.nMaxFile = sizeof(zDbFn);
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
+ if( GetOpenFileName(&ofn) ){
+ data.zDbFilename = zDbFn;
+ } else
+#endif
data.zDbFilename = ":memory:";
}
if( i<argc ){
EOD
$nov2 || rm -f sqlite/src/minshell.c
$nov2 || touch sqlite/src/minshell.c
$nov2 || patch sqlite/src/minshell.c <<'EOD'
--- sqlite.orig/src/minshell.c 2007-01-10 18:46:47.000000000 +0100
+++ sqlite/src/minshell.c 2007-01-10 18:46:47.000000000 +0100
@@ -0,0 +1,20 @@
+/*
+** 2001 September 15
+**
+** The author disclaims copyright to this source code. In place of
+** a legal notice, here is a blessing:
+**
+** May you do good and not evil.
+** May you find forgiveness for yourself and forgive others.
+** May you share freely, never taking more than you give.
+**
+*************************************************************************
+** This file contains code to implement the "sqlite" command line
+** utility for accessing SQLite databases.
+*/
+
+int sqlite_main(int argc, char **argv);
+
+int main(int argc, char **argv){
+ return sqlite_main(argc, argv);
+}
EOD
echo "====================="
echo "Preparing sqlite3 ..."
echo "====================="
test -r sqlite-src-${VER3X}.zip || \
wget -c http://www.sqlite.org/sqlite-src-${VER3X}.zip
test -r sqlite-src-${VER3X}.zip || exit 1
test -r extension-functions.c ||
wget -O extension-functions.c -c \
'http://www.sqlite.org/contrib/download/extension-functions.c?get=25'
if test -r extension-functions.c ; then
cp extension-functions.c extfunc.c
patch < extfunc.patch
fi
test -r extfunc.c || exit 1
rm -f sqlite3
rm -rf sqlite-src-${VER3X}
unzip sqlite-src-${VER3X}.zip
ln -sf sqlite-src-${VER3X} sqlite3
patch sqlite3/main.mk <<'EOD'
--- sqlite3.orig/main.mk 2007-03-31 14:32:21.000000000 +0200
+++ sqlite3/main.mk 2007-04-02 11:04:50.000000000 +0200
@@ -67,7 +67,7 @@
# All of the source code files.
#
-SRC = \
+SRC += \
$(TOP)/src/alter.c \
$(TOP)/src/analyze.c \
$(TOP)/src/attach.c \
EOD
# use open file dialog when no database name given
# need to link with -lcomdlg32 when enabled
true || patch sqlite3/src/shell.c <<'EOD'
--- sqlite3.orig/src/shell.c 2006-06-06 14:32:21.000000000 +0200
+++ sqlite3/src/shell.c 2006-07-23 11:04:50.000000000 +0200
@@ -21,6 +21,10 @@
#include <ctype.h>
#include <stdarg.h>
+#if defined(_WIN32) && defined(DRIVER_VER_INFO)
+# include <windows.h>
+#endif
+
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__)
# include <signal.h>
# include <pwd.h>
@@ -1676,6 +1676,17 @@
if( i<argc ){
data.zDbFilename = argv[i++];
}else{
+#if defined(_WIN32) && defined(DRIVER_VER_INFO)
+ static OPENFILENAME ofn;
+ static char zDbFn[1024];
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFile = (LPTSTR) zDbFn;
+ ofn.nMaxFile = sizeof(zDbFn);
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
+ if( GetOpenFileName(&ofn) ){
+ data.zDbFilename = zDbFn;
+ } else
+#endif
#ifndef SQLITE_OMIT_MEMORYDB
data.zDbFilename = ":memory:";
#else
EOD
# SQLite 3.5.1 Win32 mutex fix
test "$VER3" != "3.5.1" || patch sqlite3/src/mutex_w32.c <<'EOD'
--- sqlite3.orig/src/mutex_w32.c 2007-08-30 14:10:30
+++ sqlite3/src/mutex_w32.c 2007-09-04 22:31:3
@@ -141,6 +141,12 @@
p->nRef++;
}
int sqlite3_mutex_try(sqlite3_mutex *p){
+ /* The TryEnterCriticalSection() interface is not available on all
+ ** windows systems. Since sqlite3_mutex_try() is only used as an
+ ** optimization, we can skip it on windows. */
+ return SQLITE_BUSY;
+
+#if 0 /* Not Available */
int rc;
assert( p );
assert( p->id==SQLITE_MUTEX_RECURSIVE || sqlite3_mutex_notheld(p) );
@@ -152,6 +158,7 @@
rc = SQLITE_BUSY;
}
return rc;
+#endif
}
/*
EOD
# same but new module libshell.c
cp -p sqlite3/src/shell.c sqlite3/src/libshell.c
test "$VER3" != "3.7.14" -a "$VER3" != "3.7.14.1" -a "$VER3" != "3.7.15"
-a "$VER3" != "3.7.15.1" -a "$VER3" != "3.7.15.2" -a "$VER3" != "3.7.16" \
-a "$VER3" != "3.7.16.1" \
&& patch sqlite3/src/libshell.c <<'EOD'
--- sqlite3.orig/src/libshell.c 2007-01-08 23:40:05.000000000 +0100
+++ sqlite3/src/libshell.c 2007-01-10 18:35:43.000000000 +0100
@@ -21,6 +21,10 @@
#include <ctype.h>
#include <stdarg.h>
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__)
# include <signal.h>
# include <pwd.h>
@@ -1774,7 +1778,7 @@
strcpy(continuePrompt," ...> ");
}
-int main(int argc, char **argv){
+int sqlite3_main(int argc, char **argv){
char *zErrMsg = 0;
struct callback_data data;
const char *zInitFile = 0;
@@ -1816,6 +1820,17 @@
if( i<argc ){
data.zDbFilename = argv[i++];
}else{
+#if defined(_WIN32) && !defined(__TINYC__)
+ static OPENFILENAME ofn;
+ static char zDbFn[1024];
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFile = (LPTSTR) zDbFn;
+ ofn.nMaxFile = sizeof(zDbFn);
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
+ if( GetOpenFileName(&ofn) ){
+ data.zDbFilename = zDbFn;
+ } else
+#endif
#ifndef SQLITE_OMIT_MEMORYDB
data.zDbFilename = ":memory:";
#else
EOD
test "$VER3" = "3.7.14" -o "$VER3" = "3.7.14.1" \
&& patch sqlite3/src/libshell.c <<'EOD'
--- sqlite3.orig/src/libshell.c 2007-01-08 23:40:05.000000000 +0100
+++ sqlite3/src/libshell.c 2007-01-10 18:35:43.000000000 +0100
@@ -21,6 +21,10 @@
#include <ctype.h>
#include <stdarg.h>
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
#if !defined(_WIN32) && !defined(WIN32)
# include <signal.h>
# include <pwd.h>
@@ -1774,7 +1778,7 @@
strcpy(continuePrompt," ...> ");
}
-int main(int argc, char **argv){
+int sqlite3_main(int argc, char **argv){
char *zErrMsg = 0;
struct callback_data data;
const char *zInitFile = 0;
@@ -1816,6 +1820,17 @@
if( i<argc ){
data.zDbFilename = argv[i++];
}else{
+#if defined(_WIN32) && !defined(__TINYC__)
+ static OPENFILENAME ofn;
+ static char zDbFn[1024];
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFile = (LPTSTR) zDbFn;
+ ofn.nMaxFile = sizeof(zDbFn);
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
+ if( GetOpenFileName(&ofn) ){
+ data.zDbFilename = zDbFn;
+ } else
+#endif
#ifndef SQLITE_OMIT_MEMORYDB
data.zDbFilename = ":memory:";
#else
EOD
test "$VER3" = "3.7.15" -o "$VER3" = "3.7.15.1" -o "$VER3" = "3.7.15.2" \
-o "$VER3" = "3.7.16" -o "$VER3" = "3.7.16.1" \
&& patch sqlite3/src/libshell.c <<'EOD'
--- sqlite3.orig/src/libshell.c 2012-12-12 14:42:10.000000000 +0100
+++ sqlite3/src/libshell.c 2012-12-13 12:14:57.000000000 +0100
@@ -36,6 +36,10 @@
#include <ctype.h>
#include <stdarg.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
#if !defined(_WIN32) && !defined(WIN32)
# include <signal.h>
# if !defined(__RTP__) && !defined(_WRS_KERNEL)
@@ -2894,7 +2898,7 @@
return argv[i];
}
-int main(int argc, char **argv){
+int sqlite3_main(int argc, char **argv){
char *zErrMsg = 0;
struct callback_data data;
const char *zInitFile = 0;
@@ -2996,6 +3000,17 @@
}
}
if( data.zDbFilename==0 ){
+#if defined(_WIN32) && !defined(__TINYC__)
+ static OPENFILENAME ofn;
+ static char zDbFn[1024];
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFile = (LPTSTR) zDbFn;
+ ofn.nMaxFile = sizeof(zDbFn);
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
+ if( GetOpenFileName(&ofn) ){
+ data.zDbFilename = zDbFn;
+ } else
+#endif
#ifndef SQLITE_OMIT_MEMORYDB
data.zDbFilename = ":memory:";
#else
EOD
rm -f sqlite3/src/minshell.c
touch sqlite3/src/minshell.c
patch sqlite3/src/minshell.c <<'EOD'
--- sqlite3.orig/src/minshell.c 2007-01-10 18:46:47.000000000 +0100
+++ sqlite3/src/minshell.c 2007-01-10 18:46:47.000000000 +0100
@@ -0,0 +1,20 @@
+/*
+** 2001 September 15
+**
+** The author disclaims copyright to this source code. In place of
+** a legal notice, here is a blessing:
+**
+** May you do good and not evil.
+** May you find forgiveness for yourself and forgive others.
+** May you share freely, never taking more than you give.
+**
+*************************************************************************
+** This file contains code to implement the "sqlite" command line
+** utility for accessing SQLite databases.
+*/
+
+int sqlite3_main(int argc, char **argv);
+
+int main(int argc, char **argv){
+ return sqlite3_main(argc, argv);
+}
EOD
# amalgamation: add libshell.c
test "$VER3" != "3.5.6" && test -r sqlite3/tool/mksqlite3c.tcl && patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/tool/mksqlite3c.tcl 2007-04-02 14:20:10.000000000 +0200
+++ sqlite3/tool/mksqlite3c.tcl 2007-04-03 09:42:03.000000000 +0200
@@ -194,6 +194,7 @@
where.c
parse.c
+ libshell.c
tokenize.c
complete.c
EOD
test "$VER3" = "3.5.6" && test -r sqlite3/tool/mksqlite3c.tcl && patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/tool/mksqlite3c.tcl 2007-04-02 14:20:10.000000000 +0200
+++ sqlite3/tool/mksqlite3c.tcl 2007-04-03 09:42:03.000000000 +0200
@@ -200,6 +200,7 @@
main.c
+ libshell.c
fts3.c
fts3_hash.c
fts3_porter.c
EOD
# patch: parse foreign key constraints on virtual tables
test "$VER3" != "3.6.15" -a "$VER3" != "3.6.16" -a "$VER3" != "3.6.17" \
-a "$VER3" != "3.6.18" -a "$VER3" != "3.6.19" -a "$VER3" != "3.6.20" \
-a "$VER3" != "3.6.21" -a "$VER3" != "3.6.22" -a "$VER3" != "3.6.23" \
-a "$VER3" != "3.6.23.1" -a "$VER3" != "3.7.0" -a "$VER3" != "3.7.0.1" \
-a "$VER3" != "3.7.1" -a "$VER3" != "3.7.2" -a "$VER3" != "3.7.3" \
-a "$VER3" != "3.7.4" -a "$VER3" != "3.7.5" -a "$VER3" != "3.7.6" \
-a "$VER3" != "3.7.6.1" -a "$VER3" != "3.7.6.2" -a "$VER3" != "3.7.6.3" \
-a "$VER3" != "3.7.7" -a "$VER3" != "3.7.7.1" -a "$VER3" != "3.7.8" \
-a "$VER3" != "3.7.9" -a "$VER3" != "3.7.10" -a "$VER3" != "3.7.11" \
-a "$VER3" != "3.7.12" -a "$VER3" != "3.7.12.1" -a "$VER3" != "3.7.13" \
-a "$VER3" != "3.7.14" -a "$VER3" != "3.7.14.1" -a "$VER3" != "3.7.15" \
-a "$VER3" != "3.7.15.1" -a "$VER3" != "3.7.15.2" -a "$VER3" != "3.7.16" \
-a "$VER3" != "3.7.16.1" \
&& patch -d sqlite3 -p1 <<'EOD'
diff -u sqlite3.orig/src/build.c sqlite3/src/build.c
--- sqlite3.orig/src/build.c 2007-01-09 14:53:04.000000000 +0100
+++ sqlite3/src/build.c 2007-01-30 08:14:41.000000000 +0100
@@ -2063,7 +2063,7 @@
char *z;
assert( pTo!=0 );
- if( p==0 || pParse->nErr || IN_DECLARE_VTAB ) goto fk_end;
+ if( p==0 || pParse->nErr ) goto fk_end;
if( pFromCol==0 ){
int iCol = p->nCol-1;
if( iCol<0 ) goto fk_end;
diff -u sqlite3.orig/src/pragma.c sqlite3/src/pragma.c
--- sqlite3.orig/src/pragma.c 2007-01-27 03:24:56.000000000 +0100
+++ sqlite3/src/pragma.c 2007-01-30 09:19:30.000000000 +0100
@@ -589,6 +589,9 @@
pTab = sqlite3FindTable(db, zRight, zDb);
if( pTab ){
v = sqlite3GetVdbe(pParse);
+#ifndef SQLITE_OMIT_VIRTUAL_TABLE
+ if( pTab->pVtab ) sqlite3ViewGetColumnNames(pParse, pTab);
+#endif
pFK = pTab->pFKey;
if( pFK ){
int i = 0;
diff -u sqlite3.orig/src/vtab.c sqlite3/src/vtab.c
--- sqlite3.orig/src/vtab.c 2007-01-09 15:01:14.000000000 +0100
+++ sqlite3/src/vtab.c 2007-01-30 08:23:22.000000000 +0100
@@ -540,6 +540,9 @@
int rc = SQLITE_OK;
Table *pTab = db->pVTab;
char *zErr = 0;
+#ifndef SQLITE_OMIT_FOREIGN_KEYS
+ FKey *pFKey;
+#endif
sqlite3_mutex_enter(db->mutex);
pTab = db->pVTab;
@@ -568,6 +571,15 @@
}
sParse.declareVtab = 0;
+#ifndef SQLITE_OMIT_FOREIGN_KEYS
+ assert( pTab->pFKey==0 );
+ pTab->pFKey = sParse.pNewTable->pFKey;
+ sParse.pNewTable->pFKey = 0;
+ for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
+ pFKey->pFrom=pTab;
+ }
+#endif
+
if( sParse.pVdbe ){
sqlite3VdbeFinalize(sParse.pVdbe);
}
EOD
# patch: re-enable NO_TCL in tclsqlite.c (3.3.15)
patch -d sqlite3 -p1 <<'EOD'
diff -u sqlite3.orig/src/tclsqlite.c sqlite3/src/tclsqlite.c
--- sqlite3.orig/src/tclsqlite.c 2007-04-06 17:02:14.000000000 +0200
+++ sqlite3/src/tclsqlite.c 2007-04-10 07:47:49.000000000 +0200
@@ -14,6 +14,7 @@
**
** $Id: mingw-cross-build.sh,v 1.76 2013/03/30 05:16:56 chw Exp chw $
*/
+#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
#include "tcl.h"
/*
@@ -2264,3 +2265,5 @@
return 0;
}
#endif /* TCLSH */
+
+#endif /* !defined(NO_TCL) */
EOD
# patch: Win32 locking and pager unlock, for SQLite3 < 3.4.0
true || patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/src/os_win.c 2007-04-11 19:52:04.000000000 +0200
+++ sqlite3/src/os_win.c 2007-05-08 06:57:06.000000000 +0200
@@ -1237,8 +1237,8 @@
** the PENDING_LOCK byte is temporary.
*/
newLocktype = pFile->locktype;
- if( pFile->locktype==NO_LOCK
- || (locktype==EXCLUSIVE_LOCK && pFile->locktype==RESERVED_LOCK)
+ if( locktype==SHARED_LOCK
+ || (locktype==EXCLUSIVE_LOCK && pFile->locktype<PENDING_LOCK)
){
int cnt = 3;
while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
@@ -1289,6 +1289,18 @@
newLocktype = EXCLUSIVE_LOCK;
}else{
OSTRACE2("error-code = %d\n", GetLastError());
+ if( !getReadLock(pFile) ){
+ /* This should never happen. We should always be able to
+ ** reacquire the read lock */
+ OSTRACE1("could not re-get a SHARED lock.\n");
+ if( newLocktype==PENDING_LOCK || pFile->locktype==PENDING_LOCK ){
+ UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
+ }
+ if( pFile->locktype==RESERVED_LOCK ){
+ UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
+ }
+ newLocktype = NO_LOCK;
+ }
}
}
@@ -1362,6 +1374,7 @@
/* This should never happen. We should always be able to
** reacquire the read lock */
rc = SQLITE_IOERR_UNLOCK;
+ locktype = NO_LOCK;
}
}
if( type>=RESERVED_LOCK ){
EOD
# patch: Win32 locking and pager unlock, for SQLite3 >= 3.5.4 && <= 3.6.10
true || patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/src/os_win.c 2007-12-13 22:38:58.000000000 +0100
+++ sqlite3/src/os_win.c 2008-01-18 10:01:48.000000000 +0100
@@ -855,8 +855,8 @@
** the PENDING_LOCK byte is temporary.
*/
newLocktype = pFile->locktype;
- if( pFile->locktype==NO_LOCK
- || (locktype==EXCLUSIVE_LOCK && pFile->locktype==RESERVED_LOCK)
+ if( locktype==SHARED_LOCK
+ || (locktype==EXCLUSIVE_LOCK && pFile->locktype<PENDING_LOCK)
){
int cnt = 3;
while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
@@ -907,7 +907,18 @@
newLocktype = EXCLUSIVE_LOCK;
}else{
OSTRACE2("error-code = %d\n", GetLastError());
- getReadLock(pFile);
+ if( !getReadLock(pFile) ){
+ /* This should never happen. We should always be able to
+ ** reacquire the read lock */
+ OSTRACE1("could not re-get a SHARED lock.\n");
+ if( newLocktype==PENDING_LOCK || pFile->locktype==PENDING_LOCK ){
+ UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
+ }
+ if( pFile->locktype==RESERVED_LOCK ){
+ UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
+ }
+ newLocktype = NO_LOCK;
+ }
}
}
@@ -982,6 +993,7 @@
/* This should never happen. We should always be able to
** reacquire the read lock */
rc = SQLITE_IOERR_UNLOCK;
+ locktype = NO_LOCK;
}
}
if( type>=RESERVED_LOCK ){
EOD
# patch: Win32 locking and pager unlock, for SQLite3 >= 3.6.11 && < 3.7.0
true || patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/src/os_win.c 2009-02-15 14:07:09.000000000 +0100
+++ sqlite3/src/os_win.c 2009-02-20 16:39:48.000000000 +0100
@@ -922,7 +922,7 @@
newLocktype = pFile->locktype;
if( (pFile->locktype==NO_LOCK)
|| ( (locktype==EXCLUSIVE_LOCK)
- && (pFile->locktype==RESERVED_LOCK))
+ && (pFile->locktype<RESERVED_LOCK))
){
int cnt = 3;
while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
@@ -981,7 +981,18 @@
}else{
error = GetLastError();
OSTRACE2("error-code = %d\n", error);
- getReadLock(pFile);
+ if( !getReadLock(pFile) ){
+ /* This should never happen. We should always be able to
+ ** reacquire the read lock */
+ OSTRACE1("could not re-get a SHARED lock.\n");
+ if( newLocktype==PENDING_LOCK || pFile->locktype==PENDING_LOCK ){
+ UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
+ }
+ if( pFile->locktype==RESERVED_LOCK ){
+ UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
+ }
+ newLocktype = NO_LOCK;
+ }
}
}
@@ -1057,6 +1068,7 @@
/* This should never happen. We should always be able to
** reacquire the read lock */
rc = SQLITE_IOERR_UNLOCK;
+ locktype = NO_LOCK;
}
}
if( type>=RESERVED_LOCK ){
EOD
# patch: compile fix for FTS3 as extension module
test "$VER3" != "3.6.21" -a "$VER3" != "3.6.22" -a "$VER3" != "3.6.23" \
-a "$VER3" != "3.6.23.1" -a "$VER3" != "3.7.0" -a "$VER3" != "3.7.0.1" \
-a "$VER3" != "3.7.1" -a "$VER3" != "3.7.2" -a "$VER3" != "3.7.3" \
-a "$VER3" != "3.7.4" -a "$VER3" != "3.7.5" -a "$VER3" != "3.7.6" \
-a "$VER3" != "3.7.6.1" -a "$VER3" != "3.7.6.2" -a "$VER3" != "3.7.6.3" \
-a "$VER3" != "3.7.7" -a "$VER3" != "3.7.7.1" -a "$VER3" != "3.7.8" \
-a "$VER3" != "3.7.9" -a "$VER3" != "3.7.10" -a "$VER3" != "3.7.11" \
-a "$VER3" != "3.7.12" -a "$VER3" != "3.7.12.1" -a "$VER3" != "3.7.13" \
-a "$VER3" != "3.7.14" -a "$VER3" != "3.7.14.1" -a "$VER3" != "3.7.15" \
-a "$VER3" != "3.7.15.1" -a "$VER3" != "3.7.15.2" -a "$VER3" != "3.7.16" \
-a "$VER3" != "3.7.16.1" \
&& patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/ext/fts3/fts3.c 2008-02-02 17:24:34.000000000 +0100
+++ sqlite3/ext/fts3/fts3.c 2008-03-16 11:29:02.000000000 +0100
@@ -274,10 +274,6 @@
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
-#if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
-# define SQLITE_CORE 1
-#endif
-
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
@@ -6389,7 +6385,7 @@
return rc;
}
-#if !SQLITE_CORE
+#ifndef SQLITE_CORE
int sqlite3_extension_init(
sqlite3 *db,
char **pzErrMsg,
EOD
test "$VER3" = "3.6.21" -o "$VER3" = "3.6.22" -o "$VER3" = "3.6.23" \
-o "$VER3" = "3.6.23.1" -o "$VER3" = "3.7.0" -o "$VER3" = "3.7.0.1" \
-o "$VER3" = "3.7.1" -o "$VER3" = "3.7.2" -o "$VER3" = "3.7.3" \
-o "$VER3" = "3.7.4" -o "$VER3" = "3.7.5" -o "$VER3" = "3.7.6" \
-o "$VER3" = "3.7.6.1" -o "$VER3" = "3.7.6.2" -o "$VER3" = "3.7.6.3" \
&& patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/ext/fts3/fts3.c 2008-02-02 17:24:34.000000000 +0100
+++ sqlite3/ext/fts3/fts3.c 2008-03-16 11:29:02.000000000 +0100
@@ -274,10 +274,6 @@
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
-#if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
-# define SQLITE_CORE 1
-#endif
-
#include "fts3Int.h"
#include <assert.h>
@@ -6389,7 +6385,7 @@
return rc;
}
-#if !SQLITE_CORE
+#ifndef SQLITE_CORE
int sqlite3_extension_init(
sqlite3 *db,
char **pzErrMsg,
EOD
patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/ext/fts3/fts3_porter.c 2008-02-01 16:40:34.000000000 +0100
+++ sqlite3/ext/fts3/fts3_porter.c 2008-03-16 11:34:50.000000000 +0100
@@ -31,6 +31,11 @@
#include <string.h>
#include <ctype.h>
+#include "sqlite3ext.h"
+#ifndef SQLITE_CORE
+extern const sqlite3_api_routines *sqlite3_api;
+#endif
+
#include "fts3_tokenizer.h"
/*
--- sqlite3.orig/ext/fts3/fts3_tokenizer1.c 2007-11-23 18:31:18.000000000 +0100
+++ sqlite3/ext/fts3/fts3_tokenizer1.c 2008-03-16 11:35:37.000000000 +0100
@@ -31,6 +31,11 @@
#include <string.h>
#include <ctype.h>
+#include "sqlite3ext.h"
+#ifndef SQLITE_CORE
+extern const sqlite3_api_routines *sqlite3_api;
+#endif
+
#include "fts3_tokenizer.h"
typedef struct simple_tokenizer {
EOD
test "$VER3" != "3.7.8" -a "$VER3" != "3.7.9" -a "$VER3" != "3.7.10" \
-a "$VER3" != "3.7.11" -a "$VER3" != "3.7.12" -a "$VER3" != "3.7.12.1" \
-a "$VER3" != "3.7.13" -a "$VER3" != "3.7.14" -a "$VER3" != "3.7.14.1" \
-a "$VER3" != "3.7.15" -a "$VER3" != "3.7.15.1" -a "$VER3" != "3.7.15.2" \
-a "$VER3" != "3.7.16" -a "$VER3" != "3.7.16.1" \
&& patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/ext/fts3/fts3_hash.c 2007-11-24 01:41:52.000000000 +0100
+++ sqlite3/ext/fts3/fts3_hash.c 2008-03-16 11:39:57.000000000 +0100
@@ -29,6 +29,11 @@
#include <stdlib.h>
#include <string.h>
+#include "sqlite3ext.h"
+#ifndef SQLITE_CORE
+extern const sqlite3_api_routines *sqlite3_api;
+#endif
+
#include "sqlite3.h"
#include "fts3_hash.h"
EOD
test "$VER3" = "3.6.21" && patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/ext/fts3/fts3_write.c 2009-12-03 20:39:06.000000000 +0100
+++ sqlite3/ext/fts3/fts3_write.c 2010-01-05 07:59:27.000000000 +0100
@@ -20,6 +20,10 @@
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
#include "fts3Int.h"
+#include "sqlite3ext.h"
+#ifndef SQLITE_CORE
+extern const sqlite3_api_routines *sqlite3_api;
+#endif
#include <string.h>
#include <assert.h>
#include <stdlib.h>
EOD
test "$VER3" = "3.6.22" -o "$VER3" = "3.6.23" -o "$VER3" = "3.6.23.1" \
-o "$VER3" = "3.7.0" -o "$VER3" = "3.7.0.1" \
-o "$VER3" = "3.7.1" -o "$VER3" = "3.7.2" -o "$VER3" = "3.7.3" \
-o "$VER3" = "3.7.4" -o "$VER3" = "3.7.5" \
&& patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/ext/fts3/fts3_write.c 2010-01-05 09:42:19.000000000 +0100
+++ sqlite3/ext/fts3/fts3_write.c 2010-01-05 09:55:25.000000000 +0100
@@ -20,6 +20,10 @@
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
#include "fts3Int.h"
+#include "sqlite3ext.h"
+#ifndef SQLITE_CORE
+extern const sqlite3_api_routines *sqlite3_api;
+#endif
#include <string.h>
#include <assert.h>
#include <stdlib.h>
@@ -2226,7 +2230,7 @@
if( !zVal ){
return SQLITE_NOMEM;
- }else if( nVal==8 && 0==sqlite3_strnicmp(zVal, "optimize", 8) ){
+ }else if( nVal==8 && 0==strnicmp(zVal, "optimize", 8) ){
rc = fts3SegmentMerge(p, -1);
if( rc==SQLITE_DONE ){
rc = SQLITE_OK;
@@ -2234,10 +2238,10 @@
sqlite3Fts3PendingTermsClear(p);
}
#ifdef SQLITE_TEST
- }else if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){
+ }else if( nVal>9 && 0==strnicmp(zVal, "nodesize=", 9) ){
p->nNodeSize = atoi(&zVal[9]);
rc = SQLITE_OK;
- }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){
+ }else if( nVal>11 && 0==strnicmp(zVal, "maxpending=", 9) ){
p->nMaxPendingData = atoi(&zVal[11]);
rc = SQLITE_OK;
#endif
EOD
test "$VER3" = "3.7.6" -o "$VER3" = "3.7.6.1" -o "$VER3" = "3.7.6.2" \
-o "$VER3" = "3.7.6.3" \
&& patch -d sqlite3 -p1 <<'EOD'
--- sqlite3.orig/ext/fts3/fts3_write.c 2011-04-12 11:44:56.000000000 +0200
+++ sqlite3/ext/fts3/fts3_write.c 2011-04-13 08:00:51.000000000 +0200
@@ -20,6 +20,10 @@
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
#include "fts3Int.h"
+#include "sqlite3ext.h"
+#ifndef SQLITE_CORE
+extern const sqlite3_api_routines *sqlite3_api;
+#endif
#include <string.h>
#include <assert.h>
#include <stdlib.h>
@@ -2450,7 +2454,7 @@
if( !zVal ){
return SQLITE_NOMEM;
- }else if( nVal==8 && 0==sqlite3_strnicmp(zVal, "optimize", 8) ){
+ }else if( nVal==8 && 0==strnicmp(zVal, "optimize", 8) ){
rc = fts3SegmentMerge(p, FTS3_SEGCURSOR_ALL);
if( rc==SQLITE_DONE ){
rc = SQLITE_OK;
@@ -2458,10 +2462,10 @@
sqlite3Fts3PendingTermsClear(p);
}
#ifdef SQLITE_TEST
- }else if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){
+ }else if( nVal>9 && 0==strnicmp(zVal, "nodesize=", 9) ){
p->nNodeSize = atoi(&zVal[9]);
rc = SQLITE_OK;
- }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){
+ }else if( nVal>11 && 0==strnicmp(zVal, "maxpending=", 9) ){
p->nMaxPendingData = atoi(&zVal[11]);
rc = SQLITE_OK;
#endif
--- sqlite3.orig/ext/fts3/fts3_aux.c 2011-04-12 11:44:56.000000000 +0200
+++ sqlite3/ext/fts3/fts3_aux.c 2011-04-13 08:16:17.000000000 +0200
@@ -15,6 +15,10 @@
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
#include "fts3Int.h"
+#include "sqlite3ext.h"
+#ifndef SQLITE_CORE
+extern const sqlite3_api_routines *sqlite3_api;
+#endif