PageRenderTime 68ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/Community.CsharpSqlite/src/sqliteInt_h.cs

https://bitbucket.org/eumario/csharp-sqlite
C# | 4641 lines | 2167 code | 287 blank | 2187 comment | 173 complexity | bd8977b3b046f1eba7d2d8221936e2a4 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. #define SQLITE_MAX_EXPR_DEPTH
  2. using System;
  3. using System.Diagnostics;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using Bitmask = System.UInt64;
  7. using i16 = System.Int16;
  8. using i64 = System.Int64;
  9. using sqlite3_int64 = System.Int64;
  10. using u8 = System.Byte;
  11. using u16 = System.UInt16;
  12. using u32 = System.UInt32;
  13. using u64 = System.UInt64;
  14. using unsigned = System.UInt64;
  15. using Pgno = System.UInt32;
  16. #if !SQLITE_MAX_VARIABLE_NUMBER
  17. using ynVar = System.Int16;
  18. #else
  19. using ynVar = System.Int32;
  20. #endif
  21. /*
  22. ** The yDbMask datatype for the bitmask of all attached databases.
  23. */
  24. #if SQLITE_MAX_ATTACHED//>30
  25. // typedef sqlite3_uint64 yDbMask;
  26. using yDbMask = System.Int64;
  27. #else
  28. // typedef unsigned int yDbMask;
  29. using yDbMask = System.Int32;
  30. #endif
  31. namespace Community.CsharpSqlite
  32. {
  33. using sqlite3_value = Sqlite3.Mem;
  34. public partial class Sqlite3
  35. {
  36. /*
  37. ** 2001 September 15
  38. **
  39. ** The author disclaims copyright to this source code. In place of
  40. ** a legal notice, here is a blessing:
  41. **
  42. ** May you do good and not evil.
  43. ** May you find forgiveness for yourself and forgive others.
  44. ** May you share freely, never taking more than you give.
  45. **
  46. *************************************************************************
  47. ** Internal interface definitions for SQLite.
  48. **
  49. *************************************************************************
  50. ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
  51. ** C#-SQLite is an independent reimplementation of the SQLite software library
  52. **
  53. ** SQLITE_SOURCE_ID: 2011-06-23 19:49:22 4374b7e83ea0a3fbc3691f9c0c936272862f32f2
  54. **
  55. *************************************************************************
  56. */
  57. //#if !_SQLITEINT_H_
  58. //#define _SQLITEINT_H_
  59. /*
  60. ** These #defines should enable >2GB file support on POSIX if the
  61. ** underlying operating system supports it. If the OS lacks
  62. ** large file support, or if the OS is windows, these should be no-ops.
  63. **
  64. ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
  65. ** system #includes. Hence, this block of code must be the very first
  66. ** code in all source files.
  67. **
  68. ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
  69. ** on the compiler command line. This is necessary if you are compiling
  70. ** on a recent machine (ex: Red Hat 7.2) but you want your code to work
  71. ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
  72. ** without this option, LFS is enable. But LFS does not exist in the kernel
  73. ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
  74. ** portability you should omit LFS.
  75. **
  76. ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
  77. */
  78. //#if !SQLITE_DISABLE_LFS
  79. //# define _LARGE_FILE 1
  80. //# ifndef _FILE_OFFSET_BITS
  81. //# define _FILE_OFFSET_BITS 64
  82. //# endif
  83. //# define _LARGEFILE_SOURCE 1
  84. //#endif
  85. /*
  86. ** Include the configuration header output by 'configure' if we're using the
  87. ** autoconf-based build
  88. */
  89. #if _HAVE_SQLITE_CONFIG_H
  90. //#include "config.h"
  91. #endif
  92. //#include "sqliteLimit.h"
  93. /* Disable nuisance warnings on Borland compilers */
  94. //#if (__BORLANDC__)
  95. //#pragma warn -rch /* unreachable code */
  96. //#pragma warn -ccc /* Condition is always true or false */
  97. //#pragma warn -aus /* Assigned value is never used */
  98. //#pragma warn -csu /* Comparing signed and unsigned */
  99. //#pragma warn -spa /* Suspicious pointer arithmetic */
  100. //#endif
  101. /* Needed for various definitions... */
  102. //#if !_GNU_SOURCE
  103. //#define _GNU_SOURCE
  104. //#endif
  105. /*
  106. ** Include standard header files as necessary
  107. */
  108. #if HAVE_STDINT_H
  109. //#include <stdint.h>
  110. #endif
  111. #if HAVE_INTTYPES_H
  112. //#include <inttypes.h>
  113. #endif
  114. /*
  115. ** The number of samples of an index that SQLite takes in order to
  116. ** construct a histogram of the table content when running ANALYZE
  117. ** and with SQLITE_ENABLE_STAT2
  118. */
  119. //#define SQLITE_INDEX_SAMPLES 10
  120. public const int SQLITE_INDEX_SAMPLES = 10;
  121. /*
  122. ** The following macros are used to cast pointers to integers and
  123. ** integers to pointers. The way you do this varies from one compiler
  124. ** to the next, so we have developed the following set of #if statements
  125. ** to generate appropriate macros for a wide range of compilers.
  126. **
  127. ** The correct "ANSI" way to do this is to use the intptr_t type.
  128. ** Unfortunately, that typedef is not available on all compilers, or
  129. ** if it is available, it requires an #include of specific headers
  130. ** that vary from one machine to the next.
  131. **
  132. ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
  133. ** the ((void)&((char)0)[X]) construct. But MSVC chokes on ((void)(X)).
  134. ** So we have to define the macros in different ways depending on the
  135. ** compiler.
  136. */
  137. //#if (__PTRDIFF_TYPE__) /* This case should work for GCC */
  138. //# define SQLITE_INT_TO_PTR(X) ((void)(__PTRDIFF_TYPE__)(X))
  139. //# define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X))
  140. //#elif !defined(__GNUC__) /* Works for compilers other than LLVM */
  141. //# define SQLITE_INT_TO_PTR(X) ((void)&((char)0)[X])
  142. //# define SQLITE_PTR_TO_INT(X) ((int)(((char)X)-(char)0))
  143. //#elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */
  144. //# define SQLITE_INT_TO_PTR(X) ((void)(intptr_t)(X))
  145. //# define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X))
  146. //#else /* Generates a warning - but it always works */
  147. //# define SQLITE_INT_TO_PTR(X) ((void)(X))
  148. //# define SQLITE_PTR_TO_INT(X) ((int)(X))
  149. //#endif
  150. /*
  151. ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
  152. ** 0 means mutexes are permanently disable and the library is never
  153. ** threadsafe. 1 means the library is serialized which is the highest
  154. ** level of threadsafety. 2 means the libary is multithreaded - multiple
  155. ** threads can use SQLite as long as no two threads try to use the same
  156. ** database connection at the same time.
  157. **
  158. ** Older versions of SQLite used an optional THREADSAFE macro.
  159. ** We support that for legacy.
  160. */
  161. #if !SQLITE_THREADSAFE
  162. //# define SQLITE_THREADSAFE 2
  163. const int SQLITE_THREADSAFE = 2;
  164. #else
  165. const int SQLITE_THREADSAFE = 2; /* IMP: R-07272-22309 */
  166. #endif
  167. /*
  168. ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
  169. ** It determines whether or not the features related to
  170. ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
  171. ** be overridden at runtime using the sqlite3_config() API.
  172. */
  173. #if !(SQLITE_DEFAULT_MEMSTATUS)
  174. //# define SQLITE_DEFAULT_MEMSTATUS 1
  175. const int SQLITE_DEFAULT_MEMSTATUS = 0;
  176. #else
  177. const int SQLITE_DEFAULT_MEMSTATUS = 1;
  178. #endif
  179. /*
  180. ** Exactly one of the following macros must be defined in order to
  181. ** specify which memory allocation subsystem to use.
  182. **
  183. ** SQLITE_SYSTEM_MALLOC // Use normal system malloc()
  184. ** SQLITE_MEMDEBUG // Debugging version of system malloc()
  185. **
  186. ** (Historical note: There used to be several other options, but we've
  187. ** pared it down to just these two.)
  188. **
  189. ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
  190. ** the default.
  191. */
  192. //#if (SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  193. //# error "At most one of the following compile-time configuration options\
  194. // is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG"
  195. //#endif
  196. //#if (SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  197. //# define SQLITE_SYSTEM_MALLOC 1
  198. //#endif
  199. /*
  200. ** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the
  201. ** sizes of memory allocations below this value where possible.
  202. */
  203. #if !(SQLITE_MALLOC_SOFT_LIMIT)
  204. const int SQLITE_MALLOC_SOFT_LIMIT = 1024;
  205. #endif
  206. /*
  207. ** We need to define _XOPEN_SOURCE as follows in order to enable
  208. ** recursive mutexes on most Unix systems. But Mac OS X is different.
  209. ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told,
  210. ** so it is omitted there. See ticket #2673.
  211. **
  212. ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly
  213. ** implemented on some systems. So we avoid defining it at all
  214. ** if it is already defined or if it is unneeded because we are
  215. ** not doing a threadsafe build. Ticket #2681.
  216. **
  217. ** See also ticket #2741.
  218. */
  219. #if !_XOPEN_SOURCE && !__DARWIN__ && !__APPLE__ && SQLITE_THREADSAFE
  220. const int _XOPEN_SOURCE = 500;//#define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */
  221. #endif
  222. /*
  223. ** The TCL headers are only needed when compiling the TCL bindings.
  224. */
  225. #if SQLITE_TCL || TCLSH
  226. //# include <tcl.h>
  227. #endif
  228. /*
  229. ** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
  230. ** Setting NDEBUG makes the code smaller and run faster. So the following
  231. ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
  232. ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out
  233. ** feature.
  234. */
  235. #if !NDEBUG && !SQLITE_DEBUG
  236. const int NDEBUG = 1;//# define NDEBUG 1
  237. #endif
  238. /*
  239. ** The testcase() macro is used to aid in coverage testing. When
  240. ** doing coverage testing, the condition inside the argument to
  241. ** testcase() must be evaluated both true and false in order to
  242. ** get full branch coverage. The testcase() macro is inserted
  243. ** to help ensure adequate test coverage in places where simple
  244. ** condition/decision coverage is inadequate. For example, testcase()
  245. ** can be used to make sure boundary values are tested. For
  246. ** bitmask tests, testcase() can be used to make sure each bit
  247. ** is significant and used at least once. On switch statements
  248. ** where multiple cases go to the same block of code, testcase()
  249. ** can insure that all cases are evaluated.
  250. **
  251. */
  252. #if SQLITE_COVERAGE_TEST
  253. void sqlite3Coverage(int);
  254. //# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
  255. #else
  256. //# define testcase(X)
  257. static void testcase<T>( T X )
  258. {
  259. }
  260. #endif
  261. /*
  262. ** The TESTONLY macro is used to enclose variable declarations or
  263. ** other bits of code that are needed to support the arguments
  264. ** within testcase() and Debug.Assert() macros.
  265. */
  266. #if !NDEBUG || SQLITE_COVERAGE_TEST
  267. //# define TESTONLY(X) X
  268. // -- Need workaround for C#, since inline macros don't exist
  269. #else
  270. //# define TESTONLY(X)
  271. #endif
  272. /*
  273. ** Sometimes we need a small amount of code such as a variable initialization
  274. ** to setup for a later Debug.Assert() statement. We do not want this code to
  275. ** appear when Debug.Assert() is disabled. The following macro is therefore
  276. ** used to contain that setup code. The "VVA" acronym stands for
  277. ** "Verification, Validation, and Accreditation". In other words, the
  278. ** code within VVA_ONLY() will only run during verification processes.
  279. */
  280. #if !NDEBUG
  281. //# define VVA_ONLY(X) X
  282. #else
  283. //# define VVA_ONLY(X)
  284. #endif
  285. /*
  286. ** The ALWAYS and NEVER macros surround boolean expressions which
  287. ** are intended to always be true or false, respectively. Such
  288. ** expressions could be omitted from the code completely. But they
  289. ** are included in a few cases in order to enhance the resilience
  290. ** of SQLite to unexpected behavior - to make the code "self-healing"
  291. ** or "ductile" rather than being "brittle" and crashing at the first
  292. ** hint of unplanned behavior.
  293. **
  294. ** In other words, ALWAYS and NEVER are added for defensive code.
  295. **
  296. ** When doing coverage testing ALWAYS and NEVER are hard-coded to
  297. ** be true and false so that the unreachable code then specify will
  298. ** not be counted as untested code.
  299. */
  300. #if SQLITE_COVERAGE_TEST
  301. //# define ALWAYS(X) (1)
  302. //# define NEVER(X) (0)
  303. #elif !NDEBUG
  304. //# define ALWAYS(X) ((X)?1:(Debug.Assert(0),0))
  305. static bool ALWAYS( bool X )
  306. {
  307. if ( X != true )
  308. Debug.Assert( false );
  309. return true;
  310. }
  311. static int ALWAYS( int X )
  312. {
  313. if ( X == 0 )
  314. Debug.Assert( false );
  315. return 1;
  316. }
  317. static bool ALWAYS<T>( T X )
  318. {
  319. if ( X == null )
  320. Debug.Assert( false );
  321. return true;
  322. }
  323. //# define NEVER(X) ((X)?(Debug.Assert(0),1):0)
  324. static bool NEVER( bool X )
  325. {
  326. if ( X == true )
  327. Debug.Assert( false );
  328. return false;
  329. }
  330. static byte NEVER( byte X )
  331. {
  332. if ( X != 0 )
  333. Debug.Assert( false );
  334. return 0;
  335. }
  336. static int NEVER( int X )
  337. {
  338. if ( X != 0 )
  339. Debug.Assert( false );
  340. return 0;
  341. }
  342. static bool NEVER<T>( T X )
  343. {
  344. if ( X != null )
  345. Debug.Assert( false );
  346. return false;
  347. }
  348. #else
  349. //# define ALWAYS(X) (X)
  350. static bool ALWAYS(bool X) { return X; }
  351. static byte ALWAYS(byte X) { return X; }
  352. static int ALWAYS(int X) { return X; }
  353. static bool ALWAYS<T>( T X ) { return true; }
  354. //# define NEVER(X) (X)
  355. static bool NEVER(bool X) { return X; }
  356. static byte NEVER(byte X) { return X; }
  357. static int NEVER(int X) { return X; }
  358. static bool NEVER<T>(T X) { return false; }
  359. #endif
  360. /*
  361. ** Return true (non-zero) if the input is a integer that is too large
  362. ** to fit in 32-bits. This macro is used inside of various testcase()
  363. ** macros to verify that we have tested SQLite for large-file support.
  364. */
  365. static bool IS_BIG_INT( i64 X )
  366. {
  367. return ( ( ( X ) & ~(i64)0xffffffff ) != 0 );
  368. }//#define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
  369. /*
  370. ** The macro unlikely() is a hint that surrounds a boolean
  371. ** expression that is usually false. Macro likely() surrounds
  372. ** a boolean expression that is usually true. GCC is able to
  373. ** use these hints to generate better code, sometimes.
  374. */
  375. #if (__GNUC__) && FALSE
  376. //# define likely(X) __builtin_expect((X),1)
  377. //# define unlikely(X) __builtin_expect((X),0)
  378. #else
  379. //# define likely(X) !!(X)
  380. static bool likely( bool X )
  381. {
  382. return !!X;
  383. }
  384. //# define unlikely(X) !!(X)
  385. static bool unlikely( bool X )
  386. {
  387. return !!X;
  388. }
  389. #endif
  390. //#include "sqlite3.h"
  391. //#include "hash.h"
  392. //#include "parse.h"
  393. //#include <stdio.h>
  394. //#include <stdlib.h>
  395. //#include <string.h>
  396. //#include <assert.h>
  397. //#include <stddef.h>
  398. /*
  399. ** If compiling for a processor that lacks floating point support,
  400. ** substitute integer for floating-point
  401. */
  402. #if SQLITE_OMIT_FLOATING_POINT
  403. //# define double sqlite_int64
  404. //# define float sqlite_int64
  405. //# define LONGDOUBLE_TYPE sqlite_int64
  406. //#if !SQLITE_BIG_DBL
  407. //# define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
  408. //# endif
  409. //# define SQLITE_OMIT_DATETIME_FUNCS 1
  410. //# define SQLITE_OMIT_TRACE 1
  411. //# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
  412. //# undef SQLITE_HAVE_ISNAN
  413. #endif
  414. #if !SQLITE_BIG_DBL
  415. const double SQLITE_BIG_DBL = ( ( (sqlite3_int64)1 ) << 60 );//# define SQLITE_BIG_DBL (1e99)
  416. #endif
  417. /*
  418. ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
  419. ** afterward. Having this macro allows us to cause the C compiler
  420. ** to omit code used by TEMP tables without messy #if !statements.
  421. */
  422. #if SQLITE_OMIT_TEMPDB
  423. //#define OMIT_TEMPDB 1
  424. #else
  425. static int OMIT_TEMPDB = 0;
  426. #endif
  427. /*
  428. ** The "file format" number is an integer that is incremented whenever
  429. ** the VDBE-level file format changes. The following macros define the
  430. ** the default file format for new databases and the maximum file format
  431. ** that the library can read.
  432. */
  433. static public int SQLITE_MAX_FILE_FORMAT = 4;//#define SQLITE_MAX_FILE_FORMAT 4
  434. //#if !SQLITE_DEFAULT_FILE_FORMAT
  435. static int SQLITE_DEFAULT_FILE_FORMAT = 1;//# define SQLITE_DEFAULT_FILE_FORMAT 1
  436. //#endif
  437. /*
  438. ** Determine whether triggers are recursive by default. This can be
  439. ** changed at run-time using a pragma.
  440. */
  441. #if !SQLITE_DEFAULT_RECURSIVE_TRIGGERS
  442. //# define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0
  443. static public bool SQLITE_DEFAULT_RECURSIVE_TRIGGERS = false;
  444. #else
  445. static public bool SQLITE_DEFAULT_RECURSIVE_TRIGGERS = true;
  446. #endif
  447. /*
  448. ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
  449. ** on the command-line
  450. */
  451. //#if !SQLITE_TEMP_STORE
  452. static int SQLITE_TEMP_STORE = 1;//#define SQLITE_TEMP_STORE 1
  453. //#endif
  454. /*
  455. ** GCC does not define the offsetof() macro so we'll have to do it
  456. ** ourselves.
  457. */
  458. #if !offsetof
  459. //#define offsetof(STRUCTURE,FIELD) ((int)((char)&((STRUCTURE)0)->FIELD))
  460. #endif
  461. /*
  462. ** Check to see if this machine uses EBCDIC. (Yes, believe it or
  463. ** not, there are still machines out there that use EBCDIC.)
  464. */
  465. #if FALSE //'A' == '\301'
  466. //# define SQLITE_EBCDIC 1
  467. #else
  468. const int SQLITE_ASCII = 1;//#define SQLITE_ASCII 1
  469. #endif
  470. /*
  471. ** Integers of known sizes. These typedefs might change for architectures
  472. ** where the sizes very. Preprocessor macros are available so that the
  473. ** types can be conveniently redefined at compile-type. Like this:
  474. **
  475. ** cc '-Du32PTR_TYPE=long long int' ...
  476. */
  477. //#if !u32_TYPE
  478. //# ifdef HAVE_u32_T
  479. //# define u32_TYPE u32_t
  480. //# else
  481. //# define u32_TYPE unsigned int
  482. //# endif
  483. //#endif
  484. //#if !u3216_TYPE
  485. //# ifdef HAVE_u3216_T
  486. //# define u3216_TYPE u3216_t
  487. //# else
  488. //# define u3216_TYPE unsigned short int
  489. //# endif
  490. //#endif
  491. //#if !INT16_TYPE
  492. //# ifdef HAVE_INT16_T
  493. //# define INT16_TYPE int16_t
  494. //# else
  495. //# define INT16_TYPE short int
  496. //# endif
  497. //#endif
  498. //#if !u328_TYPE
  499. //# ifdef HAVE_u328_T
  500. //# define u328_TYPE u328_t
  501. //# else
  502. //# define u328_TYPE unsigned char
  503. //# endif
  504. //#endif
  505. //#if !INT8_TYPE
  506. //# ifdef HAVE_INT8_T
  507. //# define INT8_TYPE int8_t
  508. //# else
  509. //# define INT8_TYPE signed char
  510. //# endif
  511. //#endif
  512. //#if !LONGDOUBLE_TYPE
  513. //# define LONGDOUBLE_TYPE long double
  514. //#endif
  515. //typedef sqlite_int64 i64; /* 8-byte signed integer */
  516. //typedef sqlite_u3264 u64; /* 8-byte unsigned integer */
  517. //typedef u32_TYPE u32; /* 4-byte unsigned integer */
  518. //typedef u3216_TYPE u16; /* 2-byte unsigned integer */
  519. //typedef INT16_TYPE i16; /* 2-byte signed integer */
  520. //typedef u328_TYPE u8; /* 1-byte unsigned integer */
  521. //typedef INT8_TYPE i8; /* 1-byte signed integer */
  522. /*
  523. ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
  524. ** that can be stored in a u32 without loss of data. The value
  525. ** is 0x00000000ffffffff. But because of quirks of some compilers, we
  526. ** have to specify the value in the less intuitive manner shown:
  527. */
  528. //#define SQLITE_MAX_U32 ((((u64)1)<<32)-1)
  529. const u32 SQLITE_MAX_U32 = (u32)( ( ( (u64)1 ) << 32 ) - 1 );
  530. /*
  531. ** Macros to determine whether the machine is big or little endian,
  532. ** evaluated at runtime.
  533. */
  534. #if SQLITE_AMALGAMATION
  535. //const int sqlite3one = 1;
  536. #else
  537. const bool sqlite3one = true;
  538. #endif
  539. #if i386 || __i386__ || _M_IX86
  540. const int ;//#define SQLITE_BIGENDIAN 0
  541. const int ;//#define SQLITE_LITTLEENDIAN 1
  542. const int ;//#define SQLITE_UTF16NATIVE SQLITE_UTF16LE
  543. #else
  544. static u8 SQLITE_BIGENDIAN = 0;//#define SQLITE_BIGENDIAN (*(char )(&sqlite3one)==0)
  545. static u8 SQLITE_LITTLEENDIAN = 1;//#define SQLITE_LITTLEENDIAN (*(char )(&sqlite3one)==1)
  546. static u8 SQLITE_UTF16NATIVE = ( SQLITE_BIGENDIAN != 0 ? SQLITE_UTF16BE : SQLITE_UTF16LE );//#define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
  547. #endif
  548. /*
  549. ** Constants for the largest and smallest possible 64-bit signed integers.
  550. ** These macros are designed to work correctly on both 32-bit and 64-bit
  551. ** compilers.
  552. */
  553. //#define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
  554. //#define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
  555. const i64 LARGEST_INT64 = i64.MaxValue;//( 0xffffffff | ( ( (i64)0x7fffffff ) << 32 ) );
  556. const i64 SMALLEST_INT64 = i64.MinValue;//( ( ( i64 ) - 1 ) - LARGEST_INT64 );
  557. /*
  558. ** Round up a number to the next larger multiple of 8. This is used
  559. ** to force 8-byte alignment on 64-bit architectures.
  560. */
  561. //#define ROUND8(x) (((x)+7)&~7)
  562. static int ROUND8( int x )
  563. {
  564. return ( x + 7 ) & ~7;
  565. }
  566. /*
  567. ** Round down to the nearest multiple of 8
  568. */
  569. //#define ROUNDDOWN8(x) ((x)&~7)
  570. static int ROUNDDOWN8( int x )
  571. {
  572. return x & ~7;
  573. }
  574. /*
  575. ** Assert that the pointer X is aligned to an 8-byte boundary. This
  576. ** macro is used only within Debug.Assert() to verify that the code gets
  577. ** all alignment restrictions correct.
  578. **
  579. ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
  580. ** underlying malloc() implemention might return us 4-byte aligned
  581. ** pointers. In that case, only verify 4-byte alignment.
  582. */
  583. //#if SQLITE_4_BYTE_ALIGNED_MALLOC
  584. //# define EIGHT_BYTE_ALIGNMENT(X) ((((char)(X) - (char)0)&3)==0)
  585. //#else
  586. //# define EIGHT_BYTE_ALIGNMENT(X) ((((char)(X) - (char)0)&7)==0)
  587. //#endif
  588. /*
  589. ** An instance of the following structure is used to store the busy-handler
  590. ** callback for a given sqlite handle.
  591. **
  592. ** The sqlite.busyHandler member of the sqlite struct contains the busy
  593. ** callback for the database handle. Each pager opened via the sqlite
  594. ** handle is passed a pointer to sqlite.busyHandler. The busy-handler
  595. ** callback is currently invoked only from within pager.c.
  596. */
  597. //typedef struct BusyHandler BusyHandler;
  598. public class BusyHandler
  599. {
  600. public dxBusy xFunc;//)(void *,int); /* The busy callback */
  601. public object pArg; /* First arg to busy callback */
  602. public int nBusy; /* Incremented with each busy call */
  603. };
  604. /*
  605. ** Name of the master database table. The master database table
  606. ** is a special table that holds the names and attributes of all
  607. ** user tables and indices.
  608. */
  609. const string MASTER_NAME = "sqlite_master";//#define MASTER_NAME "sqlite_master"
  610. const string TEMP_MASTER_NAME = "sqlite_temp_master";//#define TEMP_MASTER_NAME "sqlite_temp_master"
  611. /*
  612. ** The root-page of the master database table.
  613. */
  614. const int MASTER_ROOT = 1;//#define MASTER_ROOT 1
  615. /*
  616. ** The name of the schema table.
  617. */
  618. static string SCHEMA_TABLE( int x ) //#define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
  619. {
  620. return ( ( OMIT_TEMPDB == 0 ) && ( x == 1 ) ? TEMP_MASTER_NAME : MASTER_NAME );
  621. }
  622. /*
  623. ** A convenience macro that returns the number of elements in
  624. ** an array.
  625. */
  626. //#define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0])))
  627. static int ArraySize<T>( T[] x )
  628. {
  629. return x.Length;
  630. }
  631. /*
  632. ** The following value as a destructor means to use sqlite3DbFree().
  633. ** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT.
  634. */
  635. //#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3DbFree)
  636. static dxDel SQLITE_DYNAMIC;
  637. /*
  638. ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
  639. ** not support Writable Static Data (WSD) such as global and static variables.
  640. ** All variables must either be on the stack or dynamically allocated from
  641. ** the heap. When WSD is unsupported, the variable declarations scattered
  642. ** throughout the SQLite code must become constants instead. The SQLITE_WSD
  643. ** macro is used for this purpose. And instead of referencing the variable
  644. ** directly, we use its constant as a key to lookup the run-time allocated
  645. ** buffer that holds real variable. The constant is also the initializer
  646. ** for the run-time allocated buffer.
  647. **
  648. ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
  649. ** macros become no-ops and have zero performance impact.
  650. */
  651. #if SQLITE_OMIT_WSD
  652. //#define SQLITE_WSD const
  653. //#define GLOBAL(t,v) (*(t)sqlite3_wsd_find((void)&(v), sizeof(v)))
  654. //#define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
  655. int sqlite3_wsd_init(int N, int J);
  656. void *sqlite3_wsd_find(void *K, int L);
  657. #else
  658. //#define SQLITE_WSD
  659. //#define GLOBAL(t,v) v
  660. //#define sqlite3GlobalConfig sqlite3Config
  661. static Sqlite3Config sqlite3GlobalConfig;
  662. #endif
  663. /*
  664. ** The following macros are used to suppress compiler warnings and to
  665. ** make it clear to human readers when a function parameter is deliberately
  666. ** left unused within the body of a function. This usually happens when
  667. ** a function is called via a function pointer. For example the
  668. ** implementation of an SQL aggregate step callback may not use the
  669. ** parameter indicating the number of arguments passed to the aggregate,
  670. ** if it knows that this is enforced elsewhere.
  671. **
  672. ** When a function parameter is not used at all within the body of a function,
  673. ** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
  674. ** However, these macros may also be used to suppress warnings related to
  675. ** parameters that may or may not be used depending on compilation options.
  676. ** For example those parameters only used in Debug.Assert() statements. In these
  677. ** cases the parameters are named as per the usual conventions.
  678. */
  679. //#define UNUSED_PARAMETER(x) (void)(x)
  680. static void UNUSED_PARAMETER<T>( T x )
  681. {
  682. }
  683. //#define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y)
  684. static void UNUSED_PARAMETER2<T1, T2>( T1 x, T2 y )
  685. {
  686. UNUSED_PARAMETER( x );
  687. UNUSED_PARAMETER( y );
  688. }
  689. /*
  690. ** Forward references to structures
  691. */
  692. //typedef struct AggInfo AggInfo;
  693. //typedef struct AuthContext AuthContext;
  694. //typedef struct AutoincInfo AutoincInfo;
  695. //typedef struct Bitvec Bitvec;
  696. //typedef struct CollSeq CollSeq;
  697. //typedef struct Column Column;
  698. //typedef struct Db Db;
  699. //typedef struct Schema Schema;
  700. //typedef struct Expr Expr;
  701. //typedef struct ExprList ExprList;
  702. //typedef struct ExprSpan ExprSpan;
  703. //typedef struct FKey FKey;
  704. //typedef struct FuncDestructor FuncDestructor;
  705. //typedef struct FuncDef FuncDef;
  706. //typedef struct IdList IdList;
  707. //typedef struct Index Index;
  708. //typedef struct IndexSample IndexSample;
  709. //typedef struct KeyClass KeyClass;
  710. //typedef struct KeyInfo KeyInfo;
  711. //typedef struct Lookaside Lookaside;
  712. //typedef struct LookasideSlot LookasideSlot;
  713. //typedef struct Module Module;
  714. //typedef struct NameContext NameContext;
  715. //typedef struct Parse Parse;
  716. //typedef struct RowSet RowSet;
  717. //typedef struct Savepoint Savepoint;
  718. //typedef struct Select Select;
  719. //typedef struct SrcList SrcList;
  720. //typedef struct StrAccum StrAccum;
  721. //typedef struct Table Table;
  722. //typedef struct TableLock TableLock;
  723. //typedef struct Token Token;
  724. //typedef struct Trigger Trigger;
  725. //typedef struct TriggerPrg TriggerPrg;
  726. //typedef struct TriggerStep TriggerStep;
  727. //typedef struct UnpackedRecord UnpackedRecord;
  728. //typedef struct VTable VTable;
  729. //typedef struct VtabCtx VtabCtx;
  730. //typedef struct Walker Walker;
  731. //typedef struct WherePlan WherePlan;
  732. //typedef struct WhereInfo WhereInfo;
  733. //typedef struct WhereLevel WhereLevel;
  734. /*
  735. ** Defer sourcing vdbe.h and btree.h until after the "u8" and
  736. ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
  737. ** pointer types (i.e. FuncDef) defined above.
  738. */
  739. //#include "btree.h"
  740. //#include "vdbe.h"
  741. //#include "pager.h"
  742. //#include "pcache_g.h"
  743. //#include "os.h"
  744. //#include "mutex.h"
  745. /*
  746. ** Each database file to be accessed by the system is an instance
  747. ** of the following structure. There are normally two of these structures
  748. ** in the sqlite.aDb[] array. aDb[0] is the main database file and
  749. ** aDb[1] is the database file used to hold temporary tables. Additional
  750. ** databases may be attached.
  751. */
  752. public class Db
  753. {
  754. public string zName; /* Name of this database */
  755. public Btree pBt; /* The B Tree structure for this database file */
  756. public u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */
  757. public u8 safety_level; /* How aggressive at syncing data to disk */
  758. public Schema pSchema; /* Pointer to database schema (possibly shared) */
  759. };
  760. /*
  761. ** An instance of the following structure stores a database schema.
  762. **
  763. ** Most Schema objects are associated with a Btree. The exception is
  764. ** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing.
  765. ** In shared cache mode, a single Schema object can be shared by multiple
  766. ** Btrees that refer to the same underlying BtShared object.
  767. **
  768. ** Schema objects are automatically deallocated when the last Btree that
  769. ** references them is destroyed. The TEMP Schema is manually freed by
  770. ** sqlite3_close().
  771. *
  772. ** A thread must be holding a mutex on the corresponding Btree in order
  773. ** to access Schema content. This implies that the thread must also be
  774. ** holding a mutex on the sqlite3 connection pointer that owns the Btree.
  775. ** For a TEMP Schema, only the connection mutex is required.
  776. */
  777. public class Schema
  778. {
  779. public int schema_cookie; /* Database schema version number for this file */
  780. public u32 iGeneration; /* Generation counter. Incremented with each change */
  781. public Hash tblHash = new Hash(); /* All tables indexed by name */
  782. public Hash idxHash = new Hash(); /* All (named) indices indexed by name */
  783. public Hash trigHash = new Hash();/* All triggers indexed by name */
  784. public Hash fkeyHash = new Hash();/* All foreign keys by referenced table name */
  785. public Table pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
  786. public u8 file_format; /* Schema format version for this file */
  787. public u8 enc; /* Text encoding used by this database */
  788. public u16 flags; /* Flags associated with this schema */
  789. public int cache_size; /* Number of pages to use in the cache */
  790. public Schema Copy()
  791. {
  792. if ( this == null )
  793. return null;
  794. else
  795. {
  796. Schema cp = (Schema)MemberwiseClone();
  797. return cp;
  798. }
  799. }
  800. public void Clear()
  801. {
  802. if ( this != null )
  803. {
  804. schema_cookie = 0;
  805. tblHash = new Hash();
  806. idxHash = new Hash();
  807. trigHash = new Hash();
  808. fkeyHash = new Hash();
  809. pSeqTab = null;
  810. }
  811. }
  812. };
  813. /*
  814. ** These macros can be used to test, set, or clear bits in the
  815. ** Db.pSchema->flags field.
  816. */
  817. //#define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))==(P))
  818. static bool DbHasProperty( sqlite3 D, int I, ushort P )
  819. {
  820. return ( D.aDb[I].pSchema.flags & P ) == P;
  821. }
  822. //#define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))!=0)
  823. //#define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->flags|=(P)
  824. static void DbSetProperty( sqlite3 D, int I, ushort P )
  825. {
  826. D.aDb[I].pSchema.flags = (u16)( D.aDb[I].pSchema.flags | P );
  827. }
  828. //#define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->flags&=~(P)
  829. static void DbClearProperty( sqlite3 D, int I, ushort P )
  830. {
  831. D.aDb[I].pSchema.flags = (u16)( D.aDb[I].pSchema.flags & ~P );
  832. }
  833. /*
  834. ** Allowed values for the DB.pSchema->flags field.
  835. **
  836. ** The DB_SchemaLoaded flag is set after the database schema has been
  837. ** read into internal hash tables.
  838. **
  839. ** DB_UnresetViews means that one or more views have column names that
  840. ** have been filled out. If the schema changes, these column names might
  841. ** changes and so the view will need to be reset.
  842. */
  843. //#define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
  844. //#define DB_UnresetViews 0x0002 /* Some views have defined column names */
  845. //#define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
  846. const u16 DB_SchemaLoaded = 0x0001;
  847. const u16 DB_UnresetViews = 0x0002;
  848. const u16 DB_Empty = 0x0004;
  849. /*
  850. ** The number of different kinds of things that can be limited
  851. ** using the sqlite3_limit() interface.
  852. */
  853. //#define SQLITE_N_LIMIT (SQLITE_LIMIT_TRIGGER_DEPTH+1)
  854. const int SQLITE_N_LIMIT = SQLITE_LIMIT_TRIGGER_DEPTH + 1;
  855. /*
  856. ** Lookaside malloc is a set of fixed-size buffers that can be used
  857. ** to satisfy small transient memory allocation requests for objects
  858. ** associated with a particular database connection. The use of
  859. ** lookaside malloc provides a significant performance enhancement
  860. ** (approx 10%) by avoiding numerous malloc/free requests while parsing
  861. ** SQL statements.
  862. **
  863. ** The Lookaside structure holds configuration information about the
  864. ** lookaside malloc subsystem. Each available memory allocation in
  865. ** the lookaside subsystem is stored on a linked list of LookasideSlot
  866. ** objects.
  867. **
  868. ** Lookaside allocations are only allowed for objects that are associated
  869. ** with a particular database connection. Hence, schema information cannot
  870. ** be stored in lookaside because in shared cache mode the schema information
  871. ** is shared by multiple database connections. Therefore, while parsing
  872. ** schema information, the Lookaside.bEnabled flag is cleared so that
  873. ** lookaside allocations are not used to construct the schema objects.
  874. */
  875. public class Lookaside
  876. {
  877. public int sz; /* Size of each buffer in bytes */
  878. public u8 bEnabled; /* False to disable new lookaside allocations */
  879. public bool bMalloced; /* True if pStart obtained from sqlite3_malloc() */
  880. public int nOut; /* Number of buffers currently checked out */
  881. public int mxOut; /* Highwater mark for nOut */
  882. public int[] anStat = new int[3]; /* 0: hits. 1: size misses. 2: full misses */
  883. public LookasideSlot pFree; /* List of available buffers */
  884. public int pStart; /* First byte of available memory space */
  885. public int pEnd; /* First byte past end of available space */
  886. };
  887. public class LookasideSlot
  888. {
  889. public LookasideSlot pNext; /* Next buffer in the list of free buffers */
  890. };
  891. /*
  892. ** A hash table for function definitions.
  893. **
  894. ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots.
  895. ** Collisions are on the FuncDef.pHash chain.
  896. */
  897. public class FuncDefHash
  898. {
  899. public FuncDef[] a = new FuncDef[23]; /* Hash table for functions */
  900. };
  901. /*
  902. ** Each database connection is an instance of the following structure.
  903. **
  904. ** The sqlite.lastRowid records the last insert rowid generated by an
  905. ** insert statement. Inserts on views do not affect its value. Each
  906. ** trigger has its own context, so that lastRowid can be updated inside
  907. ** triggers as usual. The previous value will be restored once the trigger
  908. ** exits. Upon entering a before or instead of trigger, lastRowid is no
  909. ** longer (since after version 2.8.12) reset to -1.
  910. **
  911. ** The sqlite.nChange does not count changes within triggers and keeps no
  912. ** context. It is reset at start of sqlite3_exec.
  913. ** The sqlite.lsChange represents the number of changes made by the last
  914. ** insert, update, or delete statement. It remains constant throughout the
  915. ** length of a statement and is then updated by OP_SetCounts. It keeps a
  916. ** context stack just like lastRowid so that the count of changes
  917. ** within a trigger is not seen outside the trigger. Changes to views do not
  918. ** affect the value of lsChange.
  919. ** The sqlite.csChange keeps track of the number of current changes (since
  920. ** the last statement) and is used to update sqlite_lsChange.
  921. **
  922. ** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16
  923. ** store the most recent error code and, if applicable, string. The
  924. ** internal function sqlite3Error() is used to set these variables
  925. ** consistently.
  926. */
  927. public class sqlite3
  928. {
  929. public sqlite3_vfs pVfs; /* OS Interface */
  930. public int nDb; /* Number of backends currently in use */
  931. public Db[] aDb = new Db[SQLITE_MAX_ATTACHED]; /* All backends */
  932. public int flags; /* Miscellaneous flags. See below */
  933. public int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
  934. public int errCode; /* Most recent error code (SQLITE_) */
  935. public int errMask; /* & result codes with this before returning */
  936. public u8 autoCommit; /* The auto-commit flag. */
  937. public u8 temp_store; /* 1: file 2: memory 0: default */
  938. // Cannot happen under C#
  939. // public u8 mallocFailed; /* True if we have seen a malloc failure */
  940. public u8 dfltLockMode; /* Default locking-mode for attached dbs */
  941. public int nextAutovac; /* Autovac setting after VACUUM if >=0 */
  942. public u8 suppressErr; /* Do not issue error messages if true */
  943. public u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
  944. public int nextPagesize; /* Pagesize after VACUUM if >0 */
  945. public int nTable; /* Number of tables in the database */
  946. public CollSeq pDfltColl; /* The default collating sequence (BINARY) */
  947. public i64 lastRowid; /* ROWID of most recent insert (see above) */
  948. public u32 magic; /* Magic number for detect library misuse */
  949. public int nChange; /* Value returned by sqlite3_changes() */
  950. public int nTotalChange; /* Value returned by sqlite3_total_changes() */
  951. public sqlite3_mutex mutex; /* Connection mutex */
  952. public int[] aLimit = new int[SQLITE_N_LIMIT]; /* Limits */
  953. public class sqlite3InitInfo
  954. { /* Information used during initialization */
  955. public int iDb; /* When back is being initialized */
  956. public int newTnum; /* Rootpage of table being initialized */
  957. public u8 busy; /* TRUE if currently initializing */
  958. public u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
  959. };
  960. public sqlite3InitInfo init = new sqlite3InitInfo();
  961. public int nExtension; /* Number of loaded extensions */
  962. public object[] aExtension; /* Array of shared library handles */
  963. public Vdbe pVdbe; /* List of active virtual machines */
  964. public int activeVdbeCnt; /* Number of VDBEs currently executing */
  965. public int writeVdbeCnt; /* Number of active VDBEs that are writing */
  966. public int vdbeExecCnt; /* Number of nested calls to VdbeExec() */
  967. public dxTrace xTrace;//)(void*,const char); /* Trace function */
  968. public object pTraceArg; /* Argument to the trace function */
  969. public dxProfile xProfile;//)(void*,const char*,u64); /* Profiling function */
  970. public object pProfileArg; /* Argument to profile function */
  971. public object pCommitArg; /* Argument to xCommitCallback() */
  972. public dxCommitCallback xCommitCallback;//)(void); /* Invoked at every commit. */
  973. public object pRollbackArg; /* Argument to xRollbackCallback() */
  974. public dxRollbackCallback xRollbackCallback;//)(void); /* Invoked at every commit. */
  975. public object pUpdateArg;
  976. public dxUpdateCallback xUpdateCallback;//)(void*,int, const char*,const char*,sqlite_int64);
  977. #if !SQLITE_OMIT_WAL
  978. //int (*xWalCallback)(void *, sqlite3 *, string , int);
  979. //void *pWalArg;
  980. #endif
  981. public dxCollNeeded xCollNeeded;//)(void*,sqlite3*,int eTextRep,const char);
  982. public dxCollNeeded xCollNeeded16;//)(void*,sqlite3*,int eTextRep,const void);
  983. public object pCollNeededArg;
  984. public sqlite3_value pErr; /* Most recent error message */
  985. public string zErrMsg; /* Most recent error message (UTF-8 encoded) */
  986. public string zErrMsg16; /* Most recent error message (UTF-16 encoded) */
  987. public struct _u1
  988. {
  989. public bool isInterrupted; /* True if sqlite3_interrupt has been called */
  990. public double notUsed1; /* Spacer */
  991. }
  992. public _u1 u1;
  993. public Lookaside lookaside = new Lookaside(); /* Lookaside malloc configuration */
  994. #if !SQLITE_OMIT_AUTHORIZATION
  995. public dxAuth xAuth;//)(void*,int,const char*,const char*,const char*,const char);
  996. /* Access authorization function */
  997. public object pAuthArg; /* 1st argument to the access auth function */
  998. #endif
  999. #if !SQLITE_OMIT_PROGRESS_CALLBACK
  1000. public dxProgress xProgress;//)(void ); /* The progress callback */
  1001. public object pProgressArg; /* Argument to the progress callback */
  1002. public int nProgressOps; /* Number of opcodes for progress callback */
  1003. #endif
  1004. #if !SQLITE_OMIT_VIRTUALTABLE
  1005. public Hash aModule; /* populated by sqlite3_create_module() */
  1006. public VtabCtx pVtabCtx; /* Context for active vtab connect/create */
  1007. public VTable[] aVTrans; /* Virtual tables with open transactions */
  1008. public int nVTrans; /* Allocated size of aVTrans */
  1009. public VTable pDisconnect; /* Disconnect these in next sqlite3_prepare() */
  1010. #endif
  1011. public FuncDefHash aFunc = new FuncDefHash(); /* Hash table of connection functions */
  1012. public Hash aCollSeq = new Hash(); /* All collating sequences */
  1013. public BusyHandler busyHandler = new BusyHandler(); /* Busy callback */
  1014. public int busyTimeout; /* Busy handler timeout, in msec */
  1015. public Db[] aDbStatic = new Db[] { new Db(), new Db() }; /* Static space for the 2 default backends */
  1016. public Savepoint pSavepoint; /* List of active savepoints */
  1017. public int nSavepoint; /* Number of non-transaction savepoints */
  1018. public int nStatement; /* Number of nested statement-transactions */
  1019. public u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
  1020. public i64 nDeferredCons; /* Net deferred constraints this transaction. */
  1021. public int pnBytesFreed; /* If not NULL, increment this in DbFree() */
  1022. #if SQLITE_ENABLE_UNLOCK_NOTIFY
  1023. /* The following variables are all protected by the STATIC_MASTER
  1024. ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
  1025. **
  1026. ** When X.pUnlockConnection==Y, that means that X is waiting for Y to
  1027. ** unlock so that it can proceed.
  1028. **
  1029. ** When X.pBlockingConnection==Y, that means that something that X tried
  1030. ** tried to do recently failed with an SQLITE_LOCKED error due to locks
  1031. ** held by Y.
  1032. */
  1033. sqlite3 *pBlockingConnection; /* Connection that caused SQLITE_LOCKED */
  1034. sqlite3 *pUnlockConnection; /* Connection to watch for unlock */
  1035. void *pUnlockArg; /* Argument to xUnlockNotify */
  1036. void (*xUnlockNotify)(void **, int); /* Unlock notify callback */
  1037. sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
  1038. #endif
  1039. };
  1040. /*
  1041. ** A macro to discover the encoding of a database.
  1042. */
  1043. //#define ENC(db) ((db)->aDb[0].pSchema->enc)
  1044. static u8 ENC( sqlite3 db )
  1045. {
  1046. return db.aDb[0].pSchema.enc;
  1047. }
  1048. /*
  1049. ** Possible values for the sqlite3.flags.
  1050. */
  1051. //#define SQLITE_VdbeTrace 0x00000100 /* True to trace VDBE execution */
  1052. //#define SQLITE_InternChanges 0x00000200 /* Uncommitted Hash table changes */
  1053. //#define SQLITE_FullColNames 0x00000400 /* Show full column names on SELECT */
  1054. //#define SQLITE_ShortColNames 0x00000800 /* Show short columns names */
  1055. //#define SQLITE_CountRows 0x00001000 /* Count rows changed by INSERT, */
  1056. // /* DELETE, or UPDATE and return */
  1057. // /* the count using a callback. */
  1058. //#define SQLITE_NullCallback 0x00002000 /* Invoke the callback once if the */
  1059. // /* result set is empty */
  1060. //#define SQLITE_SqlTrace 0x00004000 /* Debug print SQL as it executes */
  1061. //#define SQLITE_VdbeListing 0x00008000 /* Debug listings of VDBE programs */
  1062. //#define SQLITE_WriteSchema 0x00010000 /* OK to update SQLITE_MASTER */
  1063. //#define SQLITE_NoReadlock 0x00020000 /* Readlocks are omitted when
  1064. // ** accessing read-only databases */
  1065. //#define SQLITE_IgnoreChecks 0x00040000 /* Do not enforce check constraints */
  1066. //#define SQLITE_ReadUncommitted 0x0080000 /* For shared-cache mode */
  1067. //#define SQLITE_LegacyFileFmt 0x00100000 /* Create new databases in format 1 */
  1068. //#define SQLITE_FullFSync 0x00200000 /* Use full fsync on the backend */
  1069. //#define SQLITE_CkptFullFSync 0x00400000 /* Use full fsync for checkpoint */
  1070. //#define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */
  1071. //#define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */
  1072. //#define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
  1073. //#define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
  1074. //#define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
  1075. //#define SQLITE_PreferBuiltin 0x10000000 /* Preference to built-in funcs */
  1076. //#define SQLITE_LoadExtension 0x20000000 /* Enable load_extension */
  1077. //define SQLITE_EnableTrigger 0x40000000 /* True to enable triggers */
  1078. const int SQLITE_VdbeTrace = 0x00000100;
  1079. const int SQLITE_InternChanges = 0x00000200;
  1080. const int SQLITE_FullColNames = 0x00000400;
  1081. const int SQLITE_ShortColNames = 0x00000800;
  1082. const int SQLITE_CountRows = 0x00001000;
  1083. const int SQLITE_NullCallback = 0x00002000;
  1084. const int SQLITE_SqlTrace = 0x00004000;
  1085. const int SQLITE_VdbeListing = 0x00008000;
  1086. const int SQLITE_WriteSchema = 0x00010000;
  1087. const int SQLITE_NoReadlock = 0x00020000;
  1088. const int SQLITE_IgnoreChecks = 0x00040000;
  1089. const int SQLITE_ReadUncommitted = 0x0080000;
  1090. const int SQLITE_LegacyFileFmt = 0x00100000;
  1091. const int SQLITE_FullFSync = 0x00200000;
  1092. const int SQLITE_CkptFullFSync = 0x00400000;
  1093. const int SQLITE_RecoveryMode = 0x00800000;
  1094. const int SQLITE_ReverseOrder = 0x01000000;
  1095. const int SQLITE_RecTriggers = 0x02000000;
  1096. const int SQLITE_ForeignKeys = 0x04000000;
  1097. const int SQLITE_AutoIndex = 0x08000000;
  1098. const int SQLITE_PreferBuiltin = 0x10000000;
  1099. const int SQLITE_LoadExtension = 0x20000000;
  1100. const int SQLITE_EnableTrigger = 0x40000000;
  1101. /*
  1102. ** Bits of the sqlite3.flags field that are used by the
  1103. ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
  1104. ** These must be the low-order bits of the flags field.
  1105. */
  1106. //#define SQLITE_QueryFlattener 0x01 /* Disable query flattening */
  1107. //#define SQLITE_ColumnCache 0x02 /* Disable the column cache */
  1108. //#define SQLITE_IndexSort 0x04 /* Disable indexes for sorting */
  1109. //#define SQLITE_IndexSearch 0x08 /* Disable indexes for searching */
  1110. //#define SQLITE_IndexCover 0x10 /* Disable index covering table */
  1111. //#define SQLITE_GroupByOrder 0x20 /* Disable GROUPBY cover of ORDERBY */
  1112. //#define SQLITE_FactorOutConst 0x40 /* Disable factoring out constants */
  1113. //#define SQLITE_IdxRealAsInt 0x80 /* Store REAL as INT in indices */
  1114. //#define SQLITE_OptMask 0xff /* Mask of all disablable opts */
  1115. const int SQLITE_QueryFlattener = 0x01;
  1116. const int SQLITE_ColumnCache = 0x02;
  1117. const int SQLITE_IndexSort = 0x04;
  1118. const int SQLITE_IndexSearch = 0x08;
  1119. const int SQLITE_IndexCover = 0x10;
  1120. const int SQLITE_GroupByOrder = 0x20;
  1121. const int SQLITE_FactorOutConst = 0x40;
  1122. const int SQLITE_IdxRealAsInt = 0x80;
  1123. const int SQLITE_OptMask = 0xff;
  1124. /*
  1125. ** Possible values for the sqlite.magic field.
  1126. ** The numbers are obtained at random and have no special meaning, other
  1127. ** than being distinct from one another.
  1128. */
  1129. const int SQLITE_MAGIC_OPEN = 0x1029a697; //#define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */
  1130. const int SQLITE_MAGIC_CLOSED = 0x2f3c2d33; //#define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */
  1131. const int SQLITE_MAGIC_SICK = 0x3b771290; //#define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */
  1132. const int SQLITE_MAGIC_BUSY = 0x403b7906; //#define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
  1133. const int SQLITE_MAGIC_ERROR = 0x55357930; //#define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */
  1134. /*
  1135. ** Each SQL function is defined by an instance of the following
  1136. ** structure. A pointer to this structure is stored in the sqlite.aFunc
  1137. ** hash table. When multiple functions have the same name, the hash table
  1138. ** points to a linked list of these structures.
  1139. */
  1140. public class FuncDef
  1141. {
  1142. public i16 nArg; /* Number of arguments. -1 means unliā€¦

Large files files are truncated, but you can click here to view the full file