-
Notifications
You must be signed in to change notification settings - Fork 376
/
sqlInt.h
4954 lines (4565 loc) · 179 KB
/
sqlInt.h
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
/*
* Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Internal interface definitions for sql.
*
*/
#ifndef sqlINT_H
#define sqlINT_H
#define IdChar(C) ((sqlCtypeMap[(unsigned char)C]&0x46)!=0)
/* Special Comments:
*
* Some comments have special meaning to the tools that measure test
* coverage:
*
* NO_TEST - The branches on this line are not
* measured by branch coverage. This is
* used on lines of code that actually
* implement parts of coverage testing.
*
* OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
* and the correct answer is still obtained,
* though perhaps more slowly.
*
* OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
* and the correct answer is still obtained,
* though perhaps more slowly.
*
* PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
* that would be harmless and undetectable
* if it did occur.
*
* In all cases, the special comment must be enclosed in the usual
* slash-asterisk...asterisk-slash comment marks, with no spaces between the
* asterisks and the comment text.
*/
#include <stdbool.h>
#include "box/field_def.h"
#include "box/sql.h"
#include "box/txn.h"
#include "trivia/util.h"
/*
* These #defines should enable >2GB file support on POSIX if the
* underlying operating system supports it. If the OS lacks
* large file support, these should be no-ops.
*
* Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
* system #includes. Hence, this block of code must be the very first
* code in all source files.
*
* Large file support can be disabled using the -Dsql_DISABLE_LFS switch
* on the compiler command line. This is necessary if you are compiling
* on a recent machine (ex: Red Hat 7.2) but you want your code to work
* on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
* without this option, LFS is enable. But LFS does not exist in the kernel
* in Red Hat 6.0, so the code won't work. Hence, for maximum binary
* portability you should omit LFS.
*
* The previous paragraph was written in 2005. (This paragraph is written
* on 2008-11-28.) These days, all Linux kernels support large files, so
* you should probably leave LFS enabled. But some embedded platforms might
* lack LFS in which case the sql_DISABLE_LFS macro might still be useful.
*
* Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
*/
#ifndef SQL_DISABLE_LFS
#define _LARGE_FILE 1
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
#endif
#define _LARGEFILE_SOURCE 1
#endif
/* What version of GCC is being used. 0 means GCC is not being used */
#ifdef __GNUC__
#define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
#else
#define GCC_VERSION 0
#endif
/* Needed for various definitions... */
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif
#include "sqlLimit.h"
/*
* Include standard header files as necessary
*/
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
/*
* The following macros are used to cast pointers to integers and
* integers to pointers. The way you do this varies from one compiler
* to the next, so we have developed the following set of #if statements
* to generate appropriate macros for a wide range of compilers.
*
* The correct "ANSI" way to do this is to use the intptr_t type.
* Unfortunately, that typedef is not available on all compilers, or
* if it is available, it requires an #include of specific headers
* that vary from one machine to the next.
*
* Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
* the ((void*)&((char*)0)[X]) construct.
*/
#if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */
#define SQL_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X))
#define SQL_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X))
#elif !defined(__GNUC__) /* Works for compilers other than LLVM */
#define SQL_INT_TO_PTR(X) ((void*)&((char*)0)[X])
#define SQL_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
#elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */
#define SQL_INT_TO_PTR(X) ((void*)(intptr_t)(X))
#define SQL_PTR_TO_INT(X) ((int)(intptr_t)(X))
#else /* Generates a warning - but it always works */
#define SQL_INT_TO_PTR(X) ((void*)(X))
#define SQL_PTR_TO_INT(X) ((int)(X))
#endif
/*
* A macro to hint to the compiler that a function should not be
* inlined.
*/
#if defined(__GNUC__)
#define SQL_NOINLINE __attribute__((noinline))
#else
#define SQL_NOINLINE
#endif
/*
* Powersafe overwrite is on by default. But can be turned off using
* the -Dsql_POWERSAFE_OVERWRITE=0 command-line option.
*/
#ifndef SQL_POWERSAFE_OVERWRITE
#define SQL_POWERSAFE_OVERWRITE 1
#endif
/*
* EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
* default unless sql is compiled with sql_DEFAULT_MEMSTATUS=0 in
* which case memory allocation statistics are disabled by default.
*/
#if !defined(SQL_DEFAULT_MEMSTATUS)
#define SQL_DEFAULT_MEMSTATUS 1
#endif
#if defined(SQL_SYSTEM_MALLOC) \
+ defined(SQL_ZERO_MALLOC) \
+ defined(SQL_MEMDEBUG)>1
#error "Two or more of the following compile-time configuration options\
are defined but at most one is allowed:\
SQL_SYSTEM_MALLOC, SQL_MEMDEBUG,\
SQL_ZERO_MALLOC"
#endif
#if defined(SQL_SYSTEM_MALLOC) \
+ defined(SQL_ZERO_MALLOC) \
+ defined(SQL_MEMDEBUG)==0
#define SQL_SYSTEM_MALLOC 1
#endif
/*
* If sql_MALLOC_SOFT_LIMIT is not zero, then try to keep the
* sizes of memory allocations below this value where possible.
*/
#if !defined(SQL_MALLOC_SOFT_LIMIT)
#define SQL_MALLOC_SOFT_LIMIT 1024
#endif
/*
* Enable sql_ENABLE_EXPLAIN_COMMENTS if sql_DEBUG is turned on.
*/
#if !defined(SQL_ENABLE_EXPLAIN_COMMENTS) && defined(SQL_DEBUG)
#define SQL_ENABLE_EXPLAIN_COMMENTS 1
#endif
/*
* The testcase() macro is used to aid in coverage testing. When
* doing coverage testing, the condition inside the argument to
* testcase() must be evaluated both true and false in order to
* get full branch coverage. The testcase() macro is inserted
* to help ensure adequate test coverage in places where simple
* condition/decision coverage is inadequate. For example, testcase()
* can be used to make sure boundary values are tested. For
* bitmask tests, testcase() can be used to make sure each bit
* is significant and used at least once. On switch statements
* where multiple cases go to the same block of code, testcase()
* can insure that all cases are evaluated.
*
*/
#ifdef SQL_COVERAGE_TEST
void sqlCoverage(int);
#define testcase(X) if( X ){ sqlCoverage(__LINE__); }
#else
#define testcase(X)
#endif
/*
* The TESTONLY macro is used to enclose variable declarations or
* other bits of code that are needed to support the arguments
* within testcase() and assert() macros.
*/
#if !defined(NDEBUG) || defined(SQL_COVERAGE_TEST)
#define TESTONLY(X) X
#else
#define TESTONLY(X)
#endif
/*
* Sometimes we need a small amount of code such as a variable initialization
* to setup for a later assert() statement. We do not want this code to
* appear when assert() is disabled. The following macro is therefore
* used to contain that setup code. The "VVA" acronym stands for
* "Verification, Validation, and Accreditation". In other words, the
* code within VVA_ONLY() will only run during verification processes.
*/
#ifndef NDEBUG
#define VVA_ONLY(X) X
#else
#define VVA_ONLY(X)
#endif
/*
* The ALWAYS and NEVER macros surround boolean expressions which
* are intended to always be true or false, respectively. Such
* expressions could be omitted from the code completely. But they
* are included in a few cases in order to enhance the resilience
* of sql to unexpected behavior - to make the code "self-healing"
* or "ductile" rather than being "brittle" and crashing at the first
* hint of unplanned behavior.
*
* In other words, ALWAYS and NEVER are added for defensive code.
*
* When doing coverage testing ALWAYS and NEVER are hard-coded to
* be true and false so that the unreachable code they specify will
* not be counted as untested code.
*/
#if defined(SQL_COVERAGE_TEST) || defined(SQL_MUTATION_TEST)
#define ALWAYS(X) (1)
#define NEVER(X) (0)
#elif !defined(NDEBUG)
#define ALWAYS(X) ((X)?1:(assert(0),0))
#define NEVER(X) ((X)?(assert(0),1):0)
#else
#define ALWAYS(X) (X)
#define NEVER(X) (X)
#endif
/*
* Return true (non-zero) if the input is an integer that is too large
* to fit in 32-bits. This macro is used inside of various testcase()
* macros to verify that we have tested sql for large-file support.
*/
#define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
#define SQL_LIKE_DOESNT_MATCH_BLOBS
#include "hash.h"
#include "parse.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stddef.h>
typedef long long int sql_int64;
typedef unsigned long long int sql_uint64;
typedef sql_int64 sql_int64;
typedef sql_uint64 sql_uint64;
typedef struct sql_stmt sql_stmt;
typedef struct sql_context sql_context;
typedef struct sql sql;
typedef struct Mem sql_value;
typedef struct sql_file sql_file;
struct sql_file {
const struct sql_io_methods *pMethods; /* Methods for an open file */
};
typedef int (*sql_callback) (void *, int, char **, char **);
typedef struct sql_vfs sql_vfs;
struct sql_vfs {
int iVersion; /* Structure version number (currently 3) */
int szOsFile; /* Size of subclassed sql_file */
int mxPathname; /* Maximum file pathname length */
sql_vfs *pNext; /* Next registered VFS */
const char *zName; /* Name of this virtual file system */
void *pAppData; /* Pointer to application-specific data */
int (*xOpen) (sql_vfs *, const char *zName, sql_file *,
int flags, int *pOutFlags);
int (*xDelete) (sql_vfs *, const char *zName, int syncDir);
int (*xRandomness) (sql_vfs *, int nByte, char *zOut);
int (*xCurrentTime) (sql_vfs *, double *);
int (*xGetLastError) (sql_vfs *, int, char *);
/*
** The methods above are in version 1 of the sql_vfs object
** definition. Those that follow are added in version 2 or later
*/
int (*xCurrentTimeInt64) (sql_vfs *, sql_int64 *);
/*
** The methods above are in versions 1 through 3 of the sql_vfs object.
** New fields may be appended in future versions. The iVersion
** value will increment whenever this happens.
*/
};
#define SQL_LIMIT_LENGTH 0
#define SQL_LIMIT_SQL_LENGTH 1
#define SQL_LIMIT_COLUMN 2
#define SQL_LIMIT_EXPR_DEPTH 3
#define SQL_LIMIT_COMPOUND_SELECT 4
#define SQL_LIMIT_VDBE_OP 5
#define SQL_LIMIT_FUNCTION_ARG 6
#define SQL_LIMIT_ATTACHED 7
#define SQL_LIMIT_LIKE_PATTERN_LENGTH 8
#define SQL_LIMIT_TRIGGER_DEPTH 9
#define SQL_LIMIT_WORKER_THREADS 10
enum sql_ret_code {
/** Result of a routine is ok. */
SQL_OK = 0,
/** Common error code. */
SQL_ERROR,
/** Access permission denied. */
SQL_PERM,
/** Callback routine requested an abort. */
SQL_ABORT,
/** The database file is locked. */
SQL_BUSY,
/** A table in the database is locked. */
SQL_LOCKED,
/** A malloc() failed. */
SQL_NOMEM,
/** Operation terminated by sql_interrupt(). */
SQL_INTERRUPT,
/** Some kind of disk I/O error occurred. */
SQL_IOERR,
/** Unknown opcode in sql_file_control(). */
SQL_NOTFOUND,
/** Insertion failed because database is full. */
SQL_FULL,
/** Unable to open the database file. */
SQL_CANTOPEN,
/** The database schema changed. */
SQL_SCHEMA,
/** String or BLOB exceeds size limit. */
SQL_TOOBIG,
/** Abort due to constraint violation. */
SQL_CONSTRAINT,
/** Data type mismatch. */
SQL_MISMATCH,
/** Library used incorrectly. */
SQL_MISUSE,
/** 2nd parameter to sql_bind out of range. */
SQL_RANGE,
SQL_TARANTOOL_ITERATOR_FAIL,
SQL_TARANTOOL_INSERT_FAIL,
SQL_TARANTOOL_DELETE_FAIL,
SQL_TARANTOOL_ERROR,
/** Warnings from sql_log(). */
SQL_WARNING,
/** sql_step() has another row ready. */
SQL_ROW,
/** sql_step() has finished executing. */
SQL_DONE,
};
void *
sql_malloc(int);
void *
sql_malloc64(sql_uint64);
void *
sql_realloc(void *, int);
void *
sql_realloc64(void *, sql_uint64);
void
sql_free(void *);
sql_uint64
sql_msize(void *);
int
sql_stricmp(const char *, const char *);
int
sql_strnicmp(const char *, const char *, int);
const void *
sql_value_blob(sql_value *);
int
sql_value_bytes(sql_value *);
double
sql_value_double(sql_value *);
int
sql_value_int(sql_value *);
/**
* Get row column subtype.
* @param stmt row data to process.
* @param i column index.
* @retval SQL subtype if any, 0 else.
*/
enum sql_subtype
sql_column_subtype(struct sql_stmt *stmt, int i);
sql_int64
sql_value_int64(sql_value *);
const unsigned char *
sql_value_text(sql_value *);
int
sql_value_type(sql_value *);
int
sql_value_numeric_type(sql_value *);
sql *
sql_context_db_handle(sql_context *);
void
sql_result_blob(sql_context *, const void *,
int, void (*)(void *));
void
sql_result_blob64(sql_context *, const void *,
sql_uint64, void (*)(void *));
void
sql_result_double(sql_context *, double);
void
sql_result_error(sql_context *, const char *,
int);
void
sql_result_error_toobig(sql_context *);
void
sql_result_error_nomem(sql_context *);
void
sql_result_error_code(sql_context *, int);
void
sql_result_int(sql_context *, int);
void
sql_result_int64(sql_context *, sql_int64);
void
sql_result_null(sql_context *);
void
sql_result_text(sql_context *, const char *,
int, void (*)(void *));
void
sql_result_text64(sql_context *, const char *,
sql_uint64, void (*)(void *));
void
sql_result_value(sql_context *,
sql_value *);
void
sql_result_zeroblob(sql_context *, int n);
int
sql_result_zeroblob64(sql_context *,
sql_uint64 n);
char *
sql_mprintf(const char *, ...);
char *
sql_vmprintf(const char *, va_list);
char *
sql_snprintf(int, char *, const char *, ...);
char *
sql_vsnprintf(int, char *, const char *, va_list);
/**
* Wildcard characters used in REGEXP-like operators.
*/
#define MATCH_ONE_WILDCARD '_'
#define MATCH_ALL_WILDCARD '%'
int
sql_strlike_cs(const char *zLike, const char *zStr, unsigned int cEsc);
int
sql_strlike_ci(const char *zLike, const char *zStr, unsigned int cEsc);
typedef void (*sql_destructor_type) (void *);
#define SQL_STATIC ((sql_destructor_type)0)
#define SQL_TRANSIENT ((sql_destructor_type)-1)
int
sql_prepare(sql * db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sql_stmt ** ppStmt, /* OUT: Statement handle */
const char **pzTail /* OUT: Pointer to unused portion of zSql */
);
int
sql_prepare_v2(sql * db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sql_stmt ** ppStmt, /* OUT: Statement handle */
const char **pzTail /* OUT: Pointer to unused portion of zSql */
);
int
sql_step(sql_stmt *);
const void *
sql_column_blob(sql_stmt *, int iCol);
int
sql_column_bytes(sql_stmt *, int iCol);
int
sql_column_bytes16(sql_stmt *, int iCol);
double
sql_column_double(sql_stmt *, int iCol);
int
sql_column_int(sql_stmt *, int iCol);
sql_int64
sql_column_int64(sql_stmt *, int iCol);
const unsigned char *
sql_column_text(sql_stmt *,
int iCol);
int
sql_column_type(sql_stmt *, int iCol);
bool
sql_column_is_unsigned(sql_stmt *, int iCol);
sql_value *
sql_column_value(sql_stmt *,
int iCol);
int
sql_finalize(sql_stmt * pStmt);
int
sql_exec(sql *, /* An open database */
const char *sql, /* SQL to be evaluated */
int (*callback) (void *, int, char **, char **), /* Callback function */
void *, /* 1st argument to callback */
char **errmsg /* Error msg written here */
);
#define SQL_IOERR_READ (SQL_IOERR | (1<<8))
#define SQL_IOERR_SHORT_READ (SQL_IOERR | (2<<8))
#define SQL_IOERR_WRITE (SQL_IOERR | (3<<8))
#define SQL_IOERR_FSYNC (SQL_IOERR | (4<<8))
#define SQL_IOERR_DIR_FSYNC (SQL_IOERR | (5<<8))
#define SQL_IOERR_TRUNCATE (SQL_IOERR | (6<<8))
#define SQL_IOERR_FSTAT (SQL_IOERR | (7<<8))
#define SQL_IOERR_UNLOCK (SQL_IOERR | (8<<8))
#define SQL_IOERR_RDLOCK (SQL_IOERR | (9<<8))
#define SQL_IOERR_DELETE (SQL_IOERR | (10<<8))
#define SQL_IOERR_BLOCKED (SQL_IOERR | (11<<8))
#define SQL_IOERR_NOMEM (SQL_IOERR | (12<<8))
#define SQL_IOERR_ACCESS (SQL_IOERR | (13<<8))
#define SQL_IOERR_CHECKRESERVEDLOCK (SQL_IOERR | (14<<8))
#define SQL_IOERR_LOCK (SQL_IOERR | (15<<8))
#define SQL_IOERR_CLOSE (SQL_IOERR | (16<<8))
#define SQL_IOERR_DIR_CLOSE (SQL_IOERR | (17<<8))
#define SQL_IOERR_SHMOPEN (SQL_IOERR | (18<<8))
#define SQL_IOERR_SHMSIZE (SQL_IOERR | (19<<8))
#define SQL_IOERR_SHMLOCK (SQL_IOERR | (20<<8))
#define SQL_IOERR_SHMMAP (SQL_IOERR | (21<<8))
#define SQL_IOERR_SEEK (SQL_IOERR | (22<<8))
#define SQL_IOERR_DELETE_NOENT (SQL_IOERR | (23<<8))
#define SQL_IOERR_MMAP (SQL_IOERR | (24<<8))
#define SQL_IOERR_GETTEMPPATH (SQL_IOERR | (25<<8))
#define SQL_IOERR_CONVPATH (SQL_IOERR | (26<<8))
#define SQL_IOERR_VNODE (SQL_IOERR | (27<<8))
#define SQL_CONSTRAINT_CHECK (SQL_CONSTRAINT | (1<<8))
#define SQL_CONSTRAINT_FOREIGNKEY (SQL_CONSTRAINT | (3<<8))
#define SQL_CONSTRAINT_FUNCTION (SQL_CONSTRAINT | (4<<8))
#define SQL_CONSTRAINT_NOTNULL (SQL_CONSTRAINT | (5<<8))
#define SQL_CONSTRAINT_PRIMARYKEY (SQL_CONSTRAINT | (6<<8))
#define SQL_CONSTRAINT_TRIGGER (SQL_CONSTRAINT | (7<<8))
#define SQL_CONSTRAINT_UNIQUE (SQL_CONSTRAINT | (8<<8))
enum sql_type {
SQL_INTEGER = 1,
SQL_FLOAT = 2,
SQL_TEXT = 3,
SQL_BLOB = 4,
SQL_NULL = 5,
};
/**
* Subtype of a main type. Allows to do some subtype specific
* things: serialization, unpacking etc.
*/
enum sql_subtype {
SQL_SUBTYPE_NO = 0,
SQL_SUBTYPE_MSGPACK = 77,
};
void
sql_randomness(int N, void *P);
/**
* Return the number of affected rows in the last SQL statement.
*/
void
sql_row_count(struct sql_context *context, MAYBE_UNUSED int unused1,
MAYBE_UNUSED sql_value **unused2);
void *
sql_user_data(sql_context *);
void
sql_log(int iErrCode, const char *zFormat, ...);
void *
sql_aggregate_context(sql_context *,
int nBytes);
int
sql_column_count(sql_stmt * pStmt);
const char *
sql_column_name(sql_stmt *, int N);
const char *
sql_column_datatype(sql_stmt *, int N);
const char *
sql_errmsg(sql *);
int
sql_initialize(void);
int
sql_os_end(void);
#define SQL_CONFIG_SCRATCH 6 /* void*, int sz, int N */
#define SQL_CONFIG_MEMSTATUS 9 /* boolean */
#define SQL_CONFIG_LOOKASIDE 13 /* int int */
#define SQL_CONFIG_LOG 16 /* xFunc, void* */
#define SQL_CONFIG_URI 17 /* int */
#define SQL_CONFIG_COVERING_INDEX_SCAN 20 /* int */
#define SQL_CONFIG_SQLLOG 21 /* xSqllog, void* */
#define SQL_CONFIG_MMAP_SIZE 22 /* sql_int64, sql_int64 */
#define SQL_CONFIG_PMASZ 24 /* unsigned int szPma */
#define SQL_CONFIG_STMTJRNL_SPILL 25 /* int nByte */
#define SQL_DBCONFIG_LOOKASIDE 1001 /* void* int int */
#define SQL_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
#define SQL_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
#define SQL_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
#define SQL_TRACE_STMT 0x01
#define SQL_TRACE_PROFILE 0x02
#define SQL_TRACE_ROW 0x04
#define SQL_TRACE_CLOSE 0x08
#define SQL_DETERMINISTIC 0x800
#define SQL_STATUS_MEMORY_USED 0
#define SQL_STATUS_PAGECACHE_USED 1
#define SQL_STATUS_PAGECACHE_OVERFLOW 2
#define SQL_STATUS_SCRATCH_USED 3
#define SQL_STATUS_SCRATCH_OVERFLOW 4
#define SQL_STATUS_MALLOC_SIZE 5
#define SQL_STATUS_PARSER_STACK 6
#define SQL_STATUS_PAGECACHE_SIZE 7
#define SQL_STATUS_SCRATCH_SIZE 8
#define SQL_STATUS_MALLOC_COUNT 9
sql_int64
sql_memory_used(void);
int
sql_create_function_v2(sql * db,
const char *zFunctionName,
enum field_type type,
int nArg,
int flags,
void *pApp,
void (*xFunc) (sql_context *,
int,
sql_value **),
void (*xStep) (sql_context *,
int,
sql_value **),
void (*xFinal)
(sql_context *),
void (*xDestroy) (void *)
);
#define SQL_OPEN_READONLY 0x00000001 /* Ok for sql_open_v2() */
#define SQL_OPEN_READWRITE 0x00000002 /* Ok for sql_open_v2() */
#define SQL_OPEN_CREATE 0x00000004 /* Ok for sql_open_v2() */
#define SQL_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
#define SQL_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
#define SQL_OPEN_AUTOPROXY 0x00000020 /* VFS only */
#define SQL_OPEN_URI 0x00000040 /* Ok for sql_open_v2() */
#define SQL_OPEN_MEMORY 0x00000080 /* Ok for sql_open_v2() */
#define SQL_OPEN_MAIN_DB 0x00000100 /* VFS only */
#define SQL_OPEN_TEMP_DB 0x00000200 /* VFS only */
#define SQL_OPEN_SHAREDCACHE 0x00020000 /* Ok for sql_open_v2() */
#define SQL_OPEN_PRIVATECACHE 0x00040000 /* Ok for sql_open_v2() */
sql_vfs *
sql_vfs_find(const char *zVfsName);
#define SQL_TESTCTRL_FIRST 5
#define SQL_TESTCTRL_PRNG_SAVE 5
#define SQL_TESTCTRL_PRNG_RESTORE 6
#define SQL_TESTCTRL_PRNG_RESET 7
#define SQL_TESTCTRL_BITVEC_TEST 8
#define SQL_TESTCTRL_FAULT_INSTALL 9
#define SQL_TESTCTRL_BENIGN_MALLOC_HOOKS 10
#define SQL_TESTCTRL_PENDING_BYTE 11
#define SQL_TESTCTRL_ASSERT 12
#define SQL_TESTCTRL_ALWAYS 13
#define SQL_TESTCTRL_RESERVE 14
#define SQL_TESTCTRL_OPTIMIZATIONS 15
#define SQL_TESTCTRL_ISKEYWORD 16
#define SQL_TESTCTRL_SCRATCHMALLOC 17
#define SQL_TESTCTRL_LOCALTIME_FAULT 18
#define SQL_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
#define SQL_TESTCTRL_ONCE_RESET_THRESHOLD 19
#define SQL_TESTCTRL_NEVER_CORRUPT 20
#define SQL_TESTCTRL_VDBE_COVERAGE 21
#define SQL_TESTCTRL_BYTEORDER 22
#define SQL_TESTCTRL_ISINIT 23
#define SQL_TESTCTRL_SORTER_MMAP 24
#define SQL_TESTCTRL_LAST 24
int
sql_status64(int op, sql_int64 * pCurrent,
sql_int64 * pHighwater,
int resetFlag);
int
sql_config(int, ...);
typedef struct sql_io_methods sql_io_methods;
struct sql_io_methods {
int iVersion;
int (*xClose) (sql_file *);
int (*xRead) (sql_file *, void *, int iAmt,
sql_int64 iOfst);
int (*xWrite) (sql_file *, const void *, int iAmt,
sql_int64 iOfst);
int (*xFileControl) (sql_file *, int op, void *pArg);
/* Methods above are valid for version 2 */
int (*xFetch) (sql_file *, sql_int64 iOfst, int iAmt,
void **pp);
int (*xUnfetch) (sql_file *, sql_int64 iOfst, void *p);
/* Methods above are valid for version 3 */
/* Additional methods may be added in future releases */
};
#define SQL_FCNTL_LOCKSTATE 1
#define SQL_FCNTL_GET_LOCKPROXYFILE 2
#define SQL_FCNTL_SET_LOCKPROXYFILE 3
#define SQL_FCNTL_LAST_ERRNO 4
#define SQL_FCNTL_SIZE_HINT 5
#define SQL_FCNTL_CHUNK_SIZE 6
#define SQL_FCNTL_FILE_POINTER 7
#define SQL_FCNTL_SYNC_OMITTED 8
#define SQL_FCNTL_OVERWRITE 10
#define SQL_FCNTL_VFSNAME 11
#define SQL_FCNTL_POWERSAFE_OVERWRITE 12
#define SQL_FCNTL_PRAGMA 13
#define SQL_FCNTL_TEMPFILENAME 15
#define SQL_FCNTL_MMAP_SIZE 16
#define SQL_FCNTL_TRACE 17
#define SQL_FCNTL_HAS_MOVED 18
#define SQL_FCNTL_SYNC 19
int
sql_os_init(void);
sql_int64
sql_soft_heap_limit64(sql_int64 N);
int
sql_limit(sql *, int id, int newVal);
#define SQL_SYNC_NORMAL 0x00002
#define SQL_SYNC_FULL 0x00003
#define SQL_SYNC_DATAONLY 0x00010
int
sql_uri_boolean(const char *zFile,
const char *zParam, int bDefault);
extern char *
sql_temp_directory;
const char *
sql_uri_parameter(const char *zFilename,
const char *zParam);
#define SQL_ACCESS_EXISTS 0
#define SQL_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
#define SQL_ACCESS_READ 2 /* Unused */
#define SQL_DBSTATUS_LOOKASIDE_USED 0
#define SQL_DBSTATUS_CACHE_USED 1
#define SQL_DBSTATUS_SCHEMA_USED 2
#define SQL_DBSTATUS_STMT_USED 3
#define SQL_DBSTATUS_LOOKASIDE_HIT 4
#define SQL_DBSTATUS_LOOKASIDE_MISS_SIZE 5
#define SQL_DBSTATUS_LOOKASIDE_MISS_FULL 6
#define SQL_DBSTATUS_CACHE_HIT 7
#define SQL_DBSTATUS_CACHE_MISS 8
#define SQL_DBSTATUS_CACHE_WRITE 9
#define SQL_DBSTATUS_DEFERRED_FKS 10
#define SQL_DBSTATUS_CACHE_USED_SHARED 11
#define SQL_DBSTATUS_MAX 11 /* Largest defined DBSTATUS */
const char *
sql_sql(sql_stmt * pStmt);
int
sql_vfs_register(sql_vfs *, int makeDflt);
#define SQL_STMTSTATUS_FULLSCAN_STEP 1
#define SQL_STMTSTATUS_SORT 2
#define SQL_STMTSTATUS_AUTOINDEX 3
#define SQL_STMTSTATUS_VM_STEP 4
void
sql_interrupt(sql *);
int
sql_bind_blob(sql_stmt *, int, const void *,
int n, void (*)(void *));
int
sql_bind_blob64(sql_stmt *, int, const void *,
sql_uint64, void (*)(void *));
int
sql_bind_double(sql_stmt *, int, double);
int
sql_bind_int(sql_stmt *, int, int);
int
sql_bind_int64(sql_stmt *, int, sql_int64);
int
sql_bind_null(sql_stmt *, int);
int
sql_bind_text(sql_stmt *, int, const char *, int,
void (*)(void *));
int
sql_bind_text64(sql_stmt *, int, const char *,
sql_uint64, void (*)(void *));
int
sql_bind_value(sql_stmt *, int,
const sql_value *);
int
sql_bind_zeroblob(sql_stmt *, int, int n);
int
sql_bind_zeroblob64(sql_stmt *, int,
sql_uint64);
int
sql_stmt_busy(sql_stmt *);
int
sql_init_db(sql **db);
int
sql_close(sql *);
/**
* Get number of the named parameter in the prepared sql
* statement.
* @param pStmt Prepared statement.
* @param zName Parameter name.
* @param nName Parameter name length.
*
* @retval > 0 Number of the parameter.
* @retval 0 Parameter is not found.
*/
int
sql_bind_parameter_lindex(sql_stmt * pStmt, const char *zName,
int nName);
/*
* If compiling for a processor that lacks floating point support,
* substitute integer for floating-point
*/
#ifdef SQL_OMIT_FLOATING_POINT
#define double sql_int64
#define float sql_int64
#define LONGDOUBLE_TYPE sql_int64
#ifndef SQL_BIG_DBL
#define SQL_BIG_DBL (((sql_int64)1)<<50)
#endif
#define SQL_OMIT_DATETIME_FUNCS 1
#define SQL_OMIT_TRACE 1
#undef SQL_MIXED_ENDIAN_64BIT_FLOAT
#undef SQL_HAVE_ISNAN
#endif
#ifndef SQL_BIG_DBL
#define SQL_BIG_DBL (1e99)
#endif
/*
* OMIT_TEMPDB is set to 1 if sql_OMIT_TEMPDB is defined, or 0
* afterward. Having this macro allows us to cause the C compiler
* to omit code used by TEMP tables without messy #ifndef statements.
*/
#ifdef SQL_OMIT_TEMPDB
#define OMIT_TEMPDB 1
#else
#define OMIT_TEMPDB 0
#endif
/*
* Determine whether triggers are recursive by default. This can be
* changed at run-time using a pragma.
*/
#ifndef SQL_DEFAULT_RECURSIVE_TRIGGERS
#define SQL_DEFAULT_RECURSIVE_TRIGGERS 0
#endif
/*
* Provide a default value for sql_TEMP_STORE in case it is not specified
* on the command-line
*/
#ifndef SQL_TEMP_STORE
#define SQL_TEMP_STORE 1
#define SQL_TEMP_STORE_xc 1 /* Exclude from ctime.c */
#endif