PageRenderTime 67ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  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 unlimited */
  1143. public u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
  1144. public u8 flags; /* Some combination of SQLITE_FUNC_* */
  1145. public object pUserData; /* User data parameter */
  1146. public FuncDef pNext; /* Next function with same name */
  1147. public dxFunc xFunc;//)(sqlite3_context*,int,sqlite3_value*); /* Regular function */
  1148. public dxStep xStep;//)(sqlite3_context*,int,sqlite3_value*); /* Aggregate step */
  1149. public dxFinal xFinalize;//)(sqlite3_context); /* Aggregate finalizer */
  1150. public string zName; /* SQL name of the function. */
  1151. public FuncDef pHash; /* Next with a different name but the same hash */
  1152. public FuncDestructor pDestructor; /* Reference counted destructor function */
  1153. public FuncDef()
  1154. {
  1155. }
  1156. public FuncDef( i16 nArg, u8 iPrefEnc, u8 iflags, object pUserData, FuncDef pNext, dxFunc xFunc, dxStep xStep, dxFinal xFinalize, string zName, FuncDef pHash, FuncDestructor pDestructor )
  1157. {
  1158. this.nArg = nArg;
  1159. this.iPrefEnc = iPrefEnc;
  1160. this.flags = iflags;
  1161. this.pUserData = pUserData;
  1162. this.pNext = pNext;
  1163. this.xFunc = xFunc;
  1164. this.xStep = xStep;
  1165. this.xFinalize = xFinalize;
  1166. this.zName = zName;
  1167. this.pHash = pHash;
  1168. this.pDestructor = pDestructor;
  1169. }
  1170. public FuncDef( string zName, u8 iPrefEnc, i16 nArg, int iArg, u8 iflags, dxFunc xFunc )
  1171. {
  1172. this.nArg = nArg;
  1173. this.iPrefEnc = iPrefEnc;
  1174. this.flags = iflags;
  1175. this.pUserData = iArg;
  1176. this.pNext = null;
  1177. this.xFunc = xFunc;
  1178. this.xStep = null;
  1179. this.xFinalize = null;
  1180. this.zName = zName;
  1181. }
  1182. public FuncDef( string zName, u8 iPrefEnc, i16 nArg, int iArg, u8 iflags, dxStep xStep, dxFinal xFinal )
  1183. {
  1184. this.nArg = nArg;
  1185. this.iPrefEnc = iPrefEnc;
  1186. this.flags = iflags;
  1187. this.pUserData = iArg;
  1188. this.pNext = null;
  1189. this.xFunc = null;
  1190. this.xStep = xStep;
  1191. this.xFinalize = xFinal;
  1192. this.zName = zName;
  1193. }
  1194. public FuncDef( string zName, u8 iPrefEnc, i16 nArg, object arg, dxFunc xFunc, u8 flags )
  1195. {
  1196. this.nArg = nArg;
  1197. this.iPrefEnc = iPrefEnc;
  1198. this.flags = flags;
  1199. this.pUserData = arg;
  1200. this.pNext = null;
  1201. this.xFunc = xFunc;
  1202. this.xStep = null;
  1203. this.xFinalize = null;
  1204. this.zName = zName;
  1205. }
  1206. public FuncDef Copy()
  1207. {
  1208. FuncDef c = new FuncDef();
  1209. c.nArg = nArg;
  1210. c.iPrefEnc = iPrefEnc;
  1211. c.flags = flags;
  1212. c.pUserData = pUserData;
  1213. c.pNext = pNext;
  1214. c.xFunc = xFunc;
  1215. c.xStep = xStep;
  1216. c.xFinalize = xFinalize;
  1217. c.zName = zName;
  1218. c.pHash = pHash;
  1219. c.pDestructor = pDestructor;
  1220. return c;
  1221. }
  1222. };
  1223. /*
  1224. ** This structure encapsulates a user-function destructor callback (as
  1225. ** configured using create_function_v2()) and a reference counter. When
  1226. ** create_function_v2() is called to create a function with a destructor,
  1227. ** a single object of this type is allocated. FuncDestructor.nRef is set to
  1228. ** the number of FuncDef objects created (either 1 or 3, depending on whether
  1229. ** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor
  1230. ** member of each of the new FuncDef objects is set to point to the allocated
  1231. ** FuncDestructor.
  1232. **
  1233. ** Thereafter, when one of the FuncDef objects is deleted, the reference
  1234. ** count on this object is decremented. When it reaches 0, the destructor
  1235. ** is invoked and the FuncDestructor structure freed.
  1236. */
  1237. //struct FuncDestructor {
  1238. // int nRef;
  1239. // void (*xDestroy)(void );
  1240. // void *pUserData;
  1241. //};
  1242. public class FuncDestructor
  1243. {
  1244. public int nRef;
  1245. public dxFDestroy xDestroy;// (*xDestroy)(void );
  1246. public object pUserData;
  1247. };
  1248. /*
  1249. ** Possible values for FuncDef.flags
  1250. */
  1251. //#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
  1252. //#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
  1253. //#define SQLITE_FUNC_EPHEM 0x04 /* Ephemeral. Delete with VDBE */
  1254. //#define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
  1255. //#define SQLITE_FUNC_PRIVATE 0x10 /* Allowed for internal use only */
  1256. //#define SQLITE_FUNC_COUNT 0x20 /* Built-in count() aggregate */
  1257. //#define SQLITE_FUNC_COALESCE 0x40 /* Built-in coalesce() or ifnull() function */
  1258. const int SQLITE_FUNC_LIKE = 0x01; /* Candidate for the LIKE optimization */
  1259. const int SQLITE_FUNC_CASE = 0x02; /* Case-sensitive LIKE-type function */
  1260. const int SQLITE_FUNC_EPHEM = 0x04; /* Ephermeral. Delete with VDBE */
  1261. const int SQLITE_FUNC_NEEDCOLL = 0x08;/* sqlite3GetFuncCollSeq() might be called */
  1262. const int SQLITE_FUNC_PRIVATE = 0x10; /* Allowed for internal use only */
  1263. const int SQLITE_FUNC_COUNT = 0x20; /* Built-in count() aggregate */
  1264. const int SQLITE_FUNC_COALESCE = 0x40;/* Built-in coalesce() or ifnull() function */
  1265. /*
  1266. ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
  1267. ** used to create the initializers for the FuncDef structures.
  1268. **
  1269. ** FUNCTION(zName, nArg, iArg, bNC, xFunc)
  1270. ** Used to create a scalar function definition of a function zName
  1271. ** implemented by C function xFunc that accepts nArg arguments. The
  1272. ** value passed as iArg is cast to a (void) and made available
  1273. ** as the user-data (sqlite3_user_data()) for the function. If
  1274. ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
  1275. **
  1276. ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
  1277. ** Used to create an aggregate function definition implemented by
  1278. ** the C functions xStep and xFinal. The first four parameters
  1279. ** are interpreted in the same way as the first 4 parameters to
  1280. ** FUNCTION().
  1281. **
  1282. ** LIKEFUNC(zName, nArg, pArg, flags)
  1283. ** Used to create a scalar function definition of a function zName
  1284. ** that accepts nArg arguments and is implemented by a call to C
  1285. ** function likeFunc. Argument pArg is cast to a (void ) and made
  1286. ** available as the function user-data (sqlite3_user_data()). The
  1287. ** FuncDef.flags variable is set to the value passed as the flags
  1288. ** parameter.
  1289. */
  1290. //#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
  1291. // {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
  1292. //SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
  1293. static FuncDef FUNCTION( string zName, i16 nArg, int iArg, u8 bNC, dxFunc xFunc )
  1294. {
  1295. return new FuncDef( zName, SQLITE_UTF8, nArg, iArg, (u8)( bNC * SQLITE_FUNC_NEEDCOLL ), xFunc );
  1296. }
  1297. //#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
  1298. // {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
  1299. //pArg, 0, xFunc, 0, 0, #zName, 0, 0}
  1300. //#define LIKEFUNC(zName, nArg, arg, flags) \
  1301. // {nArg, SQLITE_UTF8, flags, (void )arg, 0, likeFunc, 0, 0, #zName, 0, 0}
  1302. static FuncDef LIKEFUNC( string zName, i16 nArg, object arg, u8 flags )
  1303. {
  1304. return new FuncDef( zName, SQLITE_UTF8, nArg, arg, likeFunc, flags );
  1305. }
  1306. //#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
  1307. // {nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
  1308. //SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
  1309. static FuncDef AGGREGATE( string zName, i16 nArg, int arg, u8 nc, dxStep xStep, dxFinal xFinal )
  1310. {
  1311. return new FuncDef( zName, SQLITE_UTF8, nArg, arg, (u8)( nc * SQLITE_FUNC_NEEDCOLL ), xStep, xFinal );
  1312. }
  1313. /*
  1314. ** All current savepoints are stored in a linked list starting at
  1315. ** sqlite3.pSavepoint. The first element in the list is the most recently
  1316. ** opened savepoint. Savepoints are added to the list by the vdbe
  1317. ** OP_Savepoint instruction.
  1318. */
  1319. //struct Savepoint {
  1320. // string zName; /* Savepoint name (nul-terminated) */
  1321. // i64 nDeferredCons; /* Number of deferred fk violations */
  1322. // Savepoint *pNext; /* Parent savepoint (if any) */
  1323. //};
  1324. public class Savepoint
  1325. {
  1326. public string zName; /* Savepoint name (nul-terminated) */
  1327. public i64 nDeferredCons; /* Number of deferred fk violations */
  1328. public Savepoint pNext; /* Parent savepoint (if any) */
  1329. };
  1330. /*
  1331. ** The following are used as the second parameter to sqlite3Savepoint(),
  1332. ** and as the P1 argument to the OP_Savepoint instruction.
  1333. */
  1334. const int SAVEPOINT_BEGIN = 0; //#define SAVEPOINT_BEGIN 0
  1335. const int SAVEPOINT_RELEASE = 1; //#define SAVEPOINT_RELEASE 1
  1336. const int SAVEPOINT_ROLLBACK = 2; //#define SAVEPOINT_ROLLBACK 2
  1337. /*
  1338. ** Each SQLite module (virtual table definition) is defined by an
  1339. ** instance of the following structure, stored in the sqlite3.aModule
  1340. ** hash table.
  1341. */
  1342. public class Module
  1343. {
  1344. public sqlite3_module pModule; /* Callback pointers */
  1345. public string zName; /* Name passed to create_module() */
  1346. public object pAux; /* pAux passed to create_module() */
  1347. public smdxDestroy xDestroy;//)(void );/* Module destructor function */
  1348. };
  1349. /*
  1350. ** information about each column of an SQL table is held in an instance
  1351. ** of this structure.
  1352. */
  1353. public class Column
  1354. {
  1355. public string zName; /* Name of this column */
  1356. public Expr pDflt; /* Default value of this column */
  1357. public string zDflt; /* Original text of the default value */
  1358. public string zType; /* Data type for this column */
  1359. public string zColl; /* Collating sequence. If NULL, use the default */
  1360. public u8 notNull; /* True if there is a NOT NULL constraint */
  1361. public u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
  1362. public char affinity; /* One of the SQLITE_AFF_... values */
  1363. #if !SQLITE_OMIT_VIRTUALTABLE
  1364. public u8 isHidden; /* True if this column is 'hidden' */
  1365. #endif
  1366. public Column Copy()
  1367. {
  1368. Column cp = (Column)MemberwiseClone();
  1369. if ( cp.pDflt != null )
  1370. cp.pDflt = pDflt.Copy();
  1371. return cp;
  1372. }
  1373. };
  1374. /*
  1375. ** A "Collating Sequence" is defined by an instance of the following
  1376. ** structure. Conceptually, a collating sequence consists of a name and
  1377. ** a comparison routine that defines the order of that sequence.
  1378. **
  1379. ** There may two separate implementations of the collation function, one
  1380. ** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that
  1381. ** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine
  1382. ** native byte order. When a collation sequence is invoked, SQLite selects
  1383. ** the version that will require the least expensive encoding
  1384. ** translations, if any.
  1385. **
  1386. ** The CollSeq.pUser member variable is an extra parameter that passed in
  1387. ** as the first argument to the UTF-8 comparison function, xCmp.
  1388. ** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function,
  1389. ** xCmp16.
  1390. **
  1391. ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
  1392. ** collating sequence is undefined. Indices built on an undefined
  1393. ** collating sequence may not be read or written.
  1394. */
  1395. public class CollSeq
  1396. {
  1397. public string zName; /* Name of the collating sequence, UTF-8 encoded */
  1398. public u8 enc; /* Text encoding handled by xCmp() */
  1399. public u8 type; /* One of the SQLITE_COLL_... values below */
  1400. public object pUser; /* First argument to xCmp() */
  1401. public dxCompare xCmp;//)(void*,int, const void*, int, const void);
  1402. public dxDelCollSeq xDel;//)(void); /* Destructor for pUser */
  1403. public CollSeq Copy()
  1404. {
  1405. if ( this == null )
  1406. return null;
  1407. else
  1408. {
  1409. CollSeq cp = (CollSeq)MemberwiseClone();
  1410. return cp;
  1411. }
  1412. }
  1413. };
  1414. /*
  1415. ** Allowed values of CollSeq.type:
  1416. */
  1417. const int SQLITE_COLL_BINARY = 1;//#define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */
  1418. const int SQLITE_COLL_NOCASE = 2;//#define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */
  1419. const int SQLITE_COLL_REVERSE = 3;//#define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */
  1420. const int SQLITE_COLL_USER = 0;//#define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */
  1421. /*
  1422. ** A sort order can be either ASC or DESC.
  1423. */
  1424. const int SQLITE_SO_ASC = 0;//#define SQLITE_SO_ASC 0 /* Sort in ascending order */
  1425. const int SQLITE_SO_DESC = 1;//#define SQLITE_SO_DESC 1 /* Sort in ascending order */
  1426. /*
  1427. ** Column affinity types.
  1428. **
  1429. ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
  1430. ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
  1431. ** the speed a little by numbering the values consecutively.
  1432. **
  1433. ** But rather than start with 0 or 1, we begin with 'a'. That way,
  1434. ** when multiple affinity types are concatenated into a string and
  1435. ** used as the P4 operand, they will be more readable.
  1436. **
  1437. ** Note also that the numeric types are grouped together so that testing
  1438. ** for a numeric type is a single comparison.
  1439. */
  1440. const char SQLITE_AFF_TEXT = 'a';//#define SQLITE_AFF_TEXT 'a'
  1441. const char SQLITE_AFF_NONE = 'b';//#define SQLITE_AFF_NONE 'b'
  1442. const char SQLITE_AFF_NUMERIC = 'c';//#define SQLITE_AFF_NUMERIC 'c'
  1443. const char SQLITE_AFF_INTEGER = 'd';//#define SQLITE_AFF_INTEGER 'd'
  1444. const char SQLITE_AFF_REAL = 'e';//#define SQLITE_AFF_REAL 'e'
  1445. //#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
  1446. /*
  1447. ** The SQLITE_AFF_MASK values masks off the significant bits of an
  1448. ** affinity value.
  1449. */
  1450. const int SQLITE_AFF_MASK = 0x67;//#define SQLITE_AFF_MASK 0x67
  1451. /*
  1452. ** Additional bit values that can be ORed with an affinity without
  1453. ** changing the affinity.
  1454. */
  1455. const int SQLITE_JUMPIFNULL = 0x08; //#define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
  1456. const int SQLITE_STOREP2 = 0x10; //#define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
  1457. const int SQLITE_NULLEQ = 0x80; //#define SQLITE_NULLEQ 0x80 /* NULL=NULL */
  1458. /*
  1459. ** An object of this type is created for each virtual table present in
  1460. ** the database schema.
  1461. **
  1462. ** If the database schema is shared, then there is one instance of this
  1463. ** structure for each database connection (sqlite3) that uses the shared
  1464. ** schema. This is because each database connection requires its own unique
  1465. ** instance of the sqlite3_vtab* handle used to access the virtual table
  1466. ** implementation. sqlite3_vtab* handles can not be shared between
  1467. ** database connections, even when the rest of the in-memory database
  1468. ** schema is shared, as the implementation often stores the database
  1469. ** connection handle passed to it via the xConnect() or xCreate() method
  1470. ** during initialization internally. This database connection handle may
  1471. ** then be used by the virtual table implementation to access real tables
  1472. ** within the database. So that they appear as part of the callers
  1473. ** transaction, these accesses need to be made via the same database
  1474. ** connection as that used to execute SQL operations on the virtual table.
  1475. **
  1476. ** All VTable objects that correspond to a single table in a shared
  1477. ** database schema are initially stored in a linked-list pointed to by
  1478. ** the Table.pVTable member variable of the corresponding Table object.
  1479. ** When an sqlite3_prepare() operation is required to access the virtual
  1480. ** table, it searches the list for the VTable that corresponds to the
  1481. ** database connection doing the preparing so as to use the correct
  1482. ** sqlite3_vtab* handle in the compiled query.
  1483. **
  1484. ** When an in-memory Table object is deleted (for example when the
  1485. ** schema is being reloaded for some reason), the VTable objects are not
  1486. ** deleted and the sqlite3_vtab* handles are not xDisconnect()ed
  1487. ** immediately. Instead, they are moved from the Table.pVTable list to
  1488. ** another linked list headed by the sqlite3.pDisconnect member of the
  1489. ** corresponding sqlite3 structure. They are then deleted/xDisconnected
  1490. ** next time a statement is prepared using said sqlite3*. This is done
  1491. ** to avoid deadlock issues involving multiple sqlite3.mutex mutexes.
  1492. ** Refer to comments above function sqlite3VtabUnlockList() for an
  1493. ** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect
  1494. ** list without holding the corresponding sqlite3.mutex mutex.
  1495. **
  1496. ** The memory for objects of this type is always allocated by
  1497. ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
  1498. ** the first argument.
  1499. */
  1500. public class VTable
  1501. {
  1502. public sqlite3 db; /* Database connection associated with this table */
  1503. public Module pMod; /* Pointer to module implementation */
  1504. public sqlite3_vtab pVtab; /* Pointer to vtab instance */
  1505. public int nRef; /* Number of pointers to this structure */
  1506. public u8 bConstraint; /* True if constraints are supported */
  1507. public int iSavepoint; /* Depth of the SAVEPOINT stack */
  1508. public VTable pNext; /* Next in linked list (see above) */
  1509. };
  1510. /*
  1511. ** Each SQL table is represented in memory by an instance of the
  1512. ** following structure.
  1513. **
  1514. ** Table.zName is the name of the table. The case of the original
  1515. ** CREATE TABLE statement is stored, but case is not significant for
  1516. ** comparisons.
  1517. **
  1518. ** Table.nCol is the number of columns in this table. Table.aCol is a
  1519. ** pointer to an array of Column structures, one for each column.
  1520. **
  1521. ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
  1522. ** the column that is that key. Otherwise Table.iPKey is negative. Note
  1523. ** that the datatype of the PRIMARY KEY must be INTEGER for this field to
  1524. ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
  1525. ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
  1526. ** is generated for each row of the table. TF_HasPrimaryKey is set if
  1527. ** the table has any PRIMARY KEY, INTEGER or otherwise.
  1528. **
  1529. ** Table.tnum is the page number for the root BTree page of the table in the
  1530. ** database file. If Table.iDb is the index of the database table backend
  1531. ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
  1532. ** holds temporary tables and indices. If TF_Ephemeral is set
  1533. ** then the table is stored in a file that is automatically deleted
  1534. ** when the VDBE cursor to the table is closed. In this case Table.tnum
  1535. ** refers VDBE cursor number that holds the table open, not to the root
  1536. ** page number. Transient tables are used to hold the results of a
  1537. ** sub-query that appears instead of a real table name in the FROM clause
  1538. ** of a SELECT statement.
  1539. */
  1540. public class Table
  1541. {
  1542. public string zName; /* Name of the table or view */
  1543. public int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
  1544. public int nCol; /* Number of columns in this table */
  1545. public Column[] aCol; /* Information about each column */
  1546. public Index pIndex; /* List of SQL indexes on this table. */
  1547. public int tnum; /* Root BTree node for this table (see note above) */
  1548. public u32 nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
  1549. public Select pSelect; /* NULL for tables. Points to definition if a view. */
  1550. public u16 nRef; /* Number of pointers to this Table */
  1551. public u8 tabFlags; /* Mask of TF_* values */
  1552. public u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
  1553. public FKey pFKey; /* Linked list of all foreign keys in this table */
  1554. public string zColAff; /* String defining the affinity of each column */
  1555. #if !SQLITE_OMIT_CHECK
  1556. public Expr pCheck; /* The AND of all CHECK constraints */
  1557. #endif
  1558. #if !SQLITE_OMIT_ALTERTABLE
  1559. public int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
  1560. #endif
  1561. #if !SQLITE_OMIT_VIRTUALTABLE
  1562. public VTable pVTable; /* List of VTable objects. */
  1563. public int nModuleArg; /* Number of arguments to the module */
  1564. public string[] azModuleArg;/* Text of all module args. [0] is module name */
  1565. #endif
  1566. public Trigger pTrigger; /* List of SQL triggers on this table */
  1567. public Schema pSchema; /* Schema that contains this table */
  1568. public Table pNextZombie; /* Next on the Parse.pZombieTab list */
  1569. public Table Copy()
  1570. {
  1571. if ( this == null )
  1572. return null;
  1573. else
  1574. {
  1575. Table cp = (Table)MemberwiseClone();
  1576. if ( pIndex != null )
  1577. cp.pIndex = pIndex.Copy();
  1578. if ( pSelect != null )
  1579. cp.pSelect = pSelect.Copy();
  1580. if ( pTrigger != null )
  1581. cp.pTrigger = pTrigger.Copy();
  1582. if ( pFKey != null )
  1583. cp.pFKey = pFKey.Copy();
  1584. #if !SQLITE_OMIT_CHECK
  1585. // Don't Clone Checks, only copy reference via Memberwise Clone above --
  1586. //if ( pCheck != null ) cp.pCheck = pCheck.Copy();
  1587. #endif
  1588. // Don't Clone Schema, only copy reference via Memberwise Clone above --
  1589. // if ( pSchema != null ) cp.pSchema=pSchema.Copy();
  1590. // Don't Clone pNextZombie, only copy reference via Memberwise Clone above --
  1591. // if ( pNextZombie != null ) cp.pNextZombie=pNextZombie.Copy();
  1592. return cp;
  1593. }
  1594. }
  1595. };
  1596. /*
  1597. ** Allowed values for Tabe.tabFlags.
  1598. */
  1599. //#define TF_Readonly 0x01 /* Read-only system table */
  1600. //#define TF_Ephemeral 0x02 /* An ephemeral table */
  1601. //#define TF_HasPrimaryKey 0x04 /* Table has a primary key */
  1602. //#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
  1603. //#define TF_Virtual 0x10 /* Is a virtual table */
  1604. //#define TF_NeedMetadata 0x20 /* aCol[].zType and aCol[].pColl missing */
  1605. /*
  1606. ** Allowed values for Tabe.tabFlags.
  1607. */
  1608. const int TF_Readonly = 0x01; /* Read-only system table */
  1609. const int TF_Ephemeral = 0x02; /* An ephemeral table */
  1610. const int TF_HasPrimaryKey = 0x04; /* Table has a primary key */
  1611. const int TF_Autoincrement = 0x08; /* Integer primary key is autoincrement */
  1612. const int TF_Virtual = 0x10; /* Is a virtual table */
  1613. const int TF_NeedMetadata = 0x20; /* aCol[].zType and aCol[].pColl missing */
  1614. /*
  1615. ** Test to see whether or not a table is a virtual table. This is
  1616. ** done as a macro so that it will be optimized out when virtual
  1617. ** table support is omitted from the build.
  1618. */
  1619. #if !SQLITE_OMIT_VIRTUALTABLE
  1620. //# define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)
  1621. static bool IsVirtual( Table X )
  1622. {
  1623. return ( X.tabFlags & TF_Virtual ) != 0;
  1624. }
  1625. //# define IsHiddenColumn(X) ((X)->isHidden)
  1626. static bool IsHiddenColumn( Column X )
  1627. {
  1628. return X.isHidden != 0;
  1629. }
  1630. #else
  1631. //# define IsVirtual(X) 0
  1632. static bool IsVirtual( Table T )
  1633. {
  1634. return false;
  1635. }
  1636. //# define IsHiddenColumn(X) 0
  1637. static bool IsHiddenColumn( Column C )
  1638. {
  1639. return false;
  1640. }
  1641. #endif
  1642. /*
  1643. ** Each foreign key constraint is an instance of the following structure.
  1644. **
  1645. ** A foreign key is associated with two tables. The "from" table is
  1646. ** the table that contains the REFERENCES clause that creates the foreign
  1647. ** key. The "to" table is the table that is named in the REFERENCES clause.
  1648. ** Consider this example:
  1649. **
  1650. ** CREATE TABLE ex1(
  1651. ** a INTEGER PRIMARY KEY,
  1652. ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
  1653. ** );
  1654. **
  1655. ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
  1656. **
  1657. ** Each REFERENCES clause generates an instance of the following structure
  1658. ** which is attached to the from-table. The to-table need not exist when
  1659. ** the from-table is created. The existence of the to-table is not checked.
  1660. */
  1661. public class FKey
  1662. {
  1663. public Table pFrom; /* Table containing the REFERENCES clause (aka: Child) */
  1664. public FKey pNextFrom; /* Next foreign key in pFrom */
  1665. public string zTo; /* Name of table that the key points to (aka: Parent) */
  1666. public FKey pNextTo; /* Next foreign key on table named zTo */
  1667. public FKey pPrevTo; /* Previous foreign key on table named zTo */
  1668. public int nCol; /* Number of columns in this key */
  1669. /* EV: R-30323-21917 */
  1670. public u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
  1671. public u8[] aAction = new u8[2]; /* ON DELETE and ON UPDATE actions, respectively */
  1672. public Trigger[] apTrigger = new Trigger[2];/* Triggers for aAction[] actions */
  1673. public class sColMap
  1674. { /* Mapping of columns in pFrom to columns in zTo */
  1675. public int iFrom; /* Index of column in pFrom */
  1676. public string zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */
  1677. };
  1678. public sColMap[] aCol; /* One entry for each of nCol column s */
  1679. public FKey Copy()
  1680. {
  1681. if ( this == null )
  1682. return null;
  1683. else
  1684. {
  1685. FKey cp = (FKey)MemberwiseClone();
  1686. return cp;
  1687. }
  1688. }
  1689. };
  1690. /*
  1691. ** SQLite supports many different ways to resolve a constraint
  1692. ** error. ROLLBACK processing means that a constraint violation
  1693. ** causes the operation in process to fail and for the current transaction
  1694. ** to be rolled back. ABORT processing means the operation in process
  1695. ** fails and any prior changes from that one operation are backed out,
  1696. ** but the transaction is not rolled back. FAIL processing means that
  1697. ** the operation in progress stops and returns an error code. But prior
  1698. ** changes due to the same operation are not backed out and no rollback
  1699. ** occurs. IGNORE means that the particular row that caused the constraint
  1700. ** error is not inserted or updated. Processing continues and no error
  1701. ** is returned. REPLACE means that preexisting database rows that caused
  1702. ** a UNIQUE constraint violation are removed so that the new insert or
  1703. ** update can proceed. Processing continues and no error is reported.
  1704. **
  1705. ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
  1706. ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
  1707. ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign
  1708. ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the
  1709. ** referenced table row is propagated into the row that holds the
  1710. ** foreign key.
  1711. **
  1712. ** The following symbolic values are used to record which type
  1713. ** of action to take.
  1714. */
  1715. const int OE_None = 0;//#define OE_None 0 /* There is no constraint to check */
  1716. const int OE_Rollback = 1;//#define OE_Rollback 1 /* Fail the operation and rollback the transaction */
  1717. const int OE_Abort = 2;//#define OE_Abort 2 /* Back out changes but do no rollback transaction */
  1718. const int OE_Fail = 3;//#define OE_Fail 3 /* Stop the operation but leave all prior changes */
  1719. const int OE_Ignore = 4;//#define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */
  1720. const int OE_Replace = 5;//#define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */
  1721. const int OE_Restrict = 6;//#define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
  1722. const int OE_SetNull = 7;//#define OE_SetNull 7 /* Set the foreign key value to NULL */
  1723. const int OE_SetDflt = 8;//#define OE_SetDflt 8 /* Set the foreign key value to its default */
  1724. const int OE_Cascade = 9;//#define OE_Cascade 9 /* Cascade the changes */
  1725. const int OE_Default = 99;//#define OE_Default 99 /* Do whatever the default action is */
  1726. /*
  1727. ** An instance of the following structure is passed as the first
  1728. ** argument to sqlite3VdbeKeyCompare and is used to control the
  1729. ** comparison of the two index keys.
  1730. */
  1731. public class KeyInfo
  1732. {
  1733. public sqlite3 db; /* The database connection */
  1734. public u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
  1735. public u16 nField; /* Number of entries in aColl[] */
  1736. public u8[] aSortOrder; /* Sort order for each column. May be NULL */
  1737. public CollSeq[] aColl = new CollSeq[1]; /* Collating sequence for each term of the key */
  1738. public KeyInfo Copy()
  1739. {
  1740. return (KeyInfo)MemberwiseClone();
  1741. }
  1742. };
  1743. /*
  1744. ** An instance of the following structure holds information about a
  1745. ** single index record that has already been parsed out into individual
  1746. ** values.
  1747. **
  1748. ** A record is an object that contains one or more fields of data.
  1749. ** Records are used to store the content of a table row and to store
  1750. ** the key of an index. A blob encoding of a record is created by
  1751. ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
  1752. ** OP_Column opcode.
  1753. **
  1754. ** This structure holds a record that has already been disassembled
  1755. ** into its constituent fields.
  1756. */
  1757. public class UnpackedRecord
  1758. {
  1759. public KeyInfo pKeyInfo; /* Collation and sort-order information */
  1760. public u16 nField; /* Number of entries in apMem[] */
  1761. public u16 flags; /* Boolean settings. UNPACKED_... below */
  1762. public i64 rowid; /* Used by UNPACKED_PREFIX_SEARCH */
  1763. public Mem[] aMem; /* Values */
  1764. };
  1765. /*
  1766. ** Allowed values of UnpackedRecord.flags
  1767. */
  1768. //#define UNPACKED_NEED_FREE 0x0001 /* Memory is from sqlite3Malloc() */
  1769. //#define UNPACKED_NEED_DESTROY 0x0002 /* apMem[]s should all be destroyed */
  1770. //#define UNPACKED_IGNORE_ROWID 0x0004 /* Ignore trailing rowid on key1 */
  1771. //#define UNPACKED_INCRKEY 0x0008 /* Make this key an epsilon larger */
  1772. //#define UNPACKED_PREFIX_MATCH 0x0010 /* A prefix match is considered OK */
  1773. //#define UNPACKED_PREFIX_SEARCH 0x0020 /* A prefix match is considered OK */
  1774. const int UNPACKED_NEED_FREE = 0x0001; /* Memory is from sqlite3Malloc() */
  1775. const int UNPACKED_NEED_DESTROY = 0x0002; /* apMem[]s should all be destroyed */
  1776. const int UNPACKED_IGNORE_ROWID = 0x0004; /* Ignore trailing rowid on key1 */
  1777. const int UNPACKED_INCRKEY = 0x0008; /* Make this key an epsilon larger */
  1778. const int UNPACKED_PREFIX_MATCH = 0x0010; /* A prefix match is considered OK */
  1779. const int UNPACKED_PREFIX_SEARCH = 0x0020; /* A prefix match is considered OK */
  1780. /*
  1781. ** Each SQL index is represented in memory by an
  1782. ** instance of the following structure.
  1783. **
  1784. ** The columns of the table that are to be indexed are described
  1785. ** by the aiColumn[] field of this structure. For example, suppose
  1786. ** we have the following table and index:
  1787. **
  1788. ** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
  1789. ** CREATE INDEX Ex2 ON Ex1(c3,c1);
  1790. **
  1791. ** In the Table structure describing Ex1, nCol==3 because there are
  1792. ** three columns in the table. In the Index structure describing
  1793. ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
  1794. ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the
  1795. ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
  1796. ** The second column to be indexed (c1) has an index of 0 in
  1797. ** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
  1798. **
  1799. ** The Index.onError field determines whether or not the indexed columns
  1800. ** must be unique and what to do if they are not. When Index.onError=OE_None,
  1801. ** it means this is not a unique index. Otherwise it is a unique index
  1802. ** and the value of Index.onError indicate the which conflict resolution
  1803. ** algorithm to employ whenever an attempt is made to insert a non-unique
  1804. ** element.
  1805. */
  1806. public class Index
  1807. {
  1808. public string zName; /* Name of this index */
  1809. public int nColumn; /* Number of columns in the table used by this index */
  1810. public int[] aiColumn; /* Which columns are used by this index. 1st is 0 */
  1811. public int[] aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
  1812. public Table pTable; /* The SQL table being indexed */
  1813. public int tnum; /* Page containing root of this index in database file */
  1814. public u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
  1815. public u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
  1816. public u8 bUnordered; /* Use this index for == or IN queries only */
  1817. public string zColAff; /* String defining the affinity of each column */
  1818. public Index pNext; /* The next index associated with the same table */
  1819. public Schema pSchema; /* Schema containing this index */
  1820. public u8[] aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
  1821. public string[] azColl; /* Array of collation sequence names for index */
  1822. public IndexSample[] aSample; /* Array of SQLITE_INDEX_SAMPLES samples */
  1823. public Index Copy()
  1824. {
  1825. if ( this == null )
  1826. return null;
  1827. else
  1828. {
  1829. Index cp = (Index)MemberwiseClone();
  1830. return cp;
  1831. }
  1832. }
  1833. };
  1834. /*
  1835. ** Each sample stored in the sqlite_stat2 table is represented in memory
  1836. ** using a structure of this type.
  1837. */
  1838. public class IndexSample
  1839. {
  1840. public struct _u
  1841. { //union {
  1842. public string z; /* Value if eType is SQLITE_TEXT */
  1843. public byte[] zBLOB; /* Value if eType is SQLITE_BLOB */
  1844. public double r; /* Value if eType is SQLITE_FLOAT or SQLITE_INTEGER */
  1845. }
  1846. public _u u;
  1847. public u8 eType; /* SQLITE_NULL, SQLITE_INTEGER ... etc. */
  1848. public u8 nByte; /* Size in byte of text or blob. */
  1849. };
  1850. /*
  1851. ** Each token coming out of the lexer is an instance of
  1852. ** this structure. Tokens are also used as part of an expression.
  1853. **
  1854. ** Note if Token.z==0 then Token.dyn and Token.n are undefined and
  1855. ** may contain random values. Do not make any assumptions about Token.dyn
  1856. ** and Token.n when Token.z==0.
  1857. */
  1858. public class Token
  1859. {
  1860. #if DEBUG_CLASS_TOKEN || DEBUG_CLASS_ALL
  1861. public string _z; /* Text of the token. Not NULL-terminated! */
  1862. public bool dyn;// : 1; /* True for malloced memory, false for static */
  1863. public Int32 _n;// : 31; /* Number of characters in this token */
  1864. public string z
  1865. {
  1866. get { return _z; }
  1867. set { _z = value; }
  1868. }
  1869. public Int32 n
  1870. {
  1871. get { return _n; }
  1872. set { _n = value; }
  1873. }
  1874. #else
  1875. public string z; /* Text of the token. Not NULL-terminated! */
  1876. public Int32 n; /* Number of characters in this token */
  1877. #endif
  1878. public Token()
  1879. {
  1880. this.z = null;
  1881. this.n = 0;
  1882. }
  1883. public Token( string z, Int32 n )
  1884. {
  1885. this.z = z;
  1886. this.n = n;
  1887. }
  1888. public Token Copy()
  1889. {
  1890. if ( this == null )
  1891. return null;
  1892. else
  1893. {
  1894. Token cp = (Token)MemberwiseClone();
  1895. if ( z == null || z.Length == 0 )
  1896. cp.n = 0;
  1897. else
  1898. if ( n > z.Length )
  1899. cp.n = z.Length;
  1900. return cp;
  1901. }
  1902. }
  1903. }
  1904. /*
  1905. ** An instance of this structure contains information needed to generate
  1906. ** code for a SELECT that contains aggregate functions.
  1907. **
  1908. ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
  1909. ** pointer to this structure. The Expr.iColumn field is the index in
  1910. ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
  1911. ** code for that node.
  1912. **
  1913. ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
  1914. ** original Select structure that describes the SELECT statement. These
  1915. ** fields do not need to be freed when deallocating the AggInfo structure.
  1916. */
  1917. public class AggInfo_col
  1918. { /* For each column used in source tables */
  1919. public Table pTab; /* Source table */
  1920. public int iTable; /* VdbeCursor number of the source table */
  1921. public int iColumn; /* Column number within the source table */
  1922. public int iSorterColumn; /* Column number in the sorting index */
  1923. public int iMem; /* Memory location that acts as accumulator */
  1924. public Expr pExpr; /* The original expression */
  1925. };
  1926. public class AggInfo_func
  1927. { /* For each aggregate function */
  1928. public Expr pExpr; /* Expression encoding the function */
  1929. public FuncDef pFunc; /* The aggregate function implementation */
  1930. public int iMem; /* Memory location that acts as accumulator */
  1931. public int iDistinct; /* Ephemeral table used to enforce DISTINCT */
  1932. }
  1933. public class AggInfo
  1934. {
  1935. public u8 directMode; /* Direct rendering mode means take data directly
  1936. ** from source tables rather than from accumulators */
  1937. public u8 useSortingIdx; /* In direct mode, reference the sorting index rather
  1938. ** than the source table */
  1939. public int sortingIdx; /* VdbeCursor number of the sorting index */
  1940. public ExprList pGroupBy; /* The group by clause */
  1941. public int nSortingColumn; /* Number of columns in the sorting index */
  1942. public AggInfo_col[] aCol;
  1943. public int nColumn; /* Number of used entries in aCol[] */
  1944. public int nColumnAlloc; /* Number of slots allocated for aCol[] */
  1945. public int nAccumulator; /* Number of columns that show through to the output.
  1946. ** Additional columns are used only as parameters to
  1947. ** aggregate functions */
  1948. public AggInfo_func[] aFunc;
  1949. public int nFunc; /* Number of entries in aFunc[] */
  1950. public int nFuncAlloc; /* Number of slots allocated for aFunc[] */
  1951. public AggInfo Copy()
  1952. {
  1953. if ( this == null )
  1954. return null;
  1955. else
  1956. {
  1957. AggInfo cp = (AggInfo)MemberwiseClone();
  1958. if ( pGroupBy != null )
  1959. cp.pGroupBy = pGroupBy.Copy();
  1960. return cp;
  1961. }
  1962. }
  1963. };
  1964. /*
  1965. ** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
  1966. ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater
  1967. ** than 32767 we have to make it 32-bit. 16-bit is preferred because
  1968. ** it uses less memory in the Expr object, which is a big memory user
  1969. ** in systems with lots of prepared statements. And few applications
  1970. ** need more than about 10 or 20 variables. But some extreme users want
  1971. ** to have prepared statements with over 32767 variables, and for them
  1972. ** the option is available (at compile-time).
  1973. */
  1974. //#if SQLITE_MAX_VARIABLE_NUMBER<=32767
  1975. //typedef i16 ynVar;
  1976. //#else
  1977. //typedef int ynVar;
  1978. //#endif
  1979. /*
  1980. ** Each node of an expression in the parse tree is an instance
  1981. ** of this structure.
  1982. **
  1983. ** Expr.op is the opcode. The integer parser token codes are reused
  1984. ** as opcodes here. For example, the parser defines TK_GE to be an integer
  1985. ** code representing the ">=" operator. This same integer code is reused
  1986. ** to represent the greater-than-or-equal-to operator in the expression
  1987. ** tree.
  1988. **
  1989. ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
  1990. ** or TK_STRING), then Expr.token contains the text of the SQL literal. If
  1991. ** the expression is a variable (TK_VARIABLE), then Expr.token contains the
  1992. ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
  1993. ** then Expr.token contains the name of the function.
  1994. **
  1995. ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
  1996. ** binary operator. Either or both may be NULL.
  1997. **
  1998. ** Expr.x.pList is a list of arguments if the expression is an SQL function,
  1999. ** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)".
  2000. ** Expr.x.pSelect is used if the expression is a sub-select or an expression of
  2001. ** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the
  2002. ** Expr.flags mask, then Expr.x.pSelect is valid. Otherwise, Expr.x.pList is
  2003. ** valid.
  2004. **
  2005. ** An expression of the form ID or ID.ID refers to a column in a table.
  2006. ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
  2007. ** the integer cursor number of a VDBE cursor pointing to that table and
  2008. ** Expr.iColumn is the column number for the specific column. If the
  2009. ** expression is used as a result in an aggregate SELECT, then the
  2010. ** value is also stored in the Expr.iAgg column in the aggregate so that
  2011. ** it can be accessed after all aggregates are computed.
  2012. **
  2013. ** If the expression is an unbound variable marker (a question mark
  2014. ** character '?' in the original SQL) then the Expr.iTable holds the index
  2015. ** number for that variable.
  2016. **
  2017. ** If the expression is a subquery then Expr.iColumn holds an integer
  2018. ** register number containing the result of the subquery. If the
  2019. ** subquery gives a constant result, then iTable is -1. If the subquery
  2020. ** gives a different answer at different times during statement processing
  2021. ** then iTable is the address of a subroutine that computes the subquery.
  2022. **
  2023. ** If the Expr is of type OP_Column, and the table it is selecting from
  2024. ** is a disk table or the "old.*" pseudo-table, then pTab points to the
  2025. ** corresponding table definition.
  2026. **
  2027. ** ALLOCATION NOTES:
  2028. **
  2029. ** Expr objects can use a lot of memory space in database schema. To
  2030. ** help reduce memory requirements, sometimes an Expr object will be
  2031. ** truncated. And to reduce the number of memory allocations, sometimes
  2032. ** two or more Expr objects will be stored in a single memory allocation,
  2033. ** together with Expr.zToken strings.
  2034. **
  2035. ** If the EP_Reduced and EP_TokenOnly flags are set when
  2036. ** an Expr object is truncated. When EP_Reduced is set, then all
  2037. ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
  2038. ** are contained within the same memory allocation. Note, however, that
  2039. ** the subtrees in Expr.x.pList or Expr.x.pSelect are always separately
  2040. ** allocated, regardless of whether or not EP_Reduced is set.
  2041. */
  2042. public class Expr
  2043. {
  2044. #if DEBUG_CLASS_EXPR || DEBUG_CLASS_ALL
  2045. public u8 _op; /* Operation performed by this node */
  2046. public u8 op
  2047. {
  2048. get { return _op; }
  2049. set { _op = value; }
  2050. }
  2051. #else
  2052. public u8 op; /* Operation performed by this node */
  2053. #endif
  2054. public char affinity; /* The affinity of the column or 0 if not a column */
  2055. #if DEBUG_CLASS_EXPR || DEBUG_CLASS_ALL
  2056. public u16 _flags; /* Various flags. EP_* See below */
  2057. public u16 flags
  2058. {
  2059. get { return _flags; }
  2060. set { _flags = value; }
  2061. }
  2062. public struct _u
  2063. {
  2064. public string _zToken; /* Token value. Zero terminated and dequoted */
  2065. public string zToken
  2066. {
  2067. get { return _zToken; }
  2068. set { _zToken = value; }
  2069. }
  2070. public int iValue; /* Non-negative integer value if EP_IntValue */
  2071. }
  2072. #else
  2073. public struct _u
  2074. {
  2075. public string zToken; /* Token value. Zero terminated and dequoted */
  2076. public int iValue; /* Non-negative integer value if EP_IntValue */
  2077. }
  2078. public u16 flags; /* Various flags. EP_* See below */
  2079. #endif
  2080. public _u u;
  2081. /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no
  2082. ** space is allocated for the fields below this point. An attempt to
  2083. ** access them will result in a segfault or malfunction.
  2084. *********************************************************************/
  2085. public Expr pLeft; /* Left subnode */
  2086. public Expr pRight; /* Right subnode */
  2087. public struct _x
  2088. {
  2089. public ExprList pList; /* Function arguments or in "<expr> IN (<expr-list)" */
  2090. public Select pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */
  2091. }
  2092. public _x x;
  2093. public CollSeq pColl; /* The collation type of the column or 0 */
  2094. /* If the EP_Reduced flag is set in the Expr.flags mask, then no
  2095. ** space is allocated for the fields below this point. An attempt to
  2096. ** access them will result in a segfault or malfunction.
  2097. *********************************************************************/
  2098. public int iTable; /* TK_COLUMN: cursor number of table holding column
  2099. ** TK_REGISTER: register number
  2100. ** TK_TRIGGER: 1 -> new, 0 -> old */
  2101. public ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
  2102. ** TK_VARIABLE: variable number (always >= 1). */
  2103. public i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  2104. public i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
  2105. public u8 flags2; /* Second set of flags. EP2_... */
  2106. public u8 op2; /* If a TK_REGISTER, the original value of Expr.op */
  2107. public AggInfo pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  2108. public Table pTab; /* Table for TK_COLUMN expressions. */
  2109. #if SQLITE_MAX_EXPR_DEPTH //>0
  2110. public int nHeight; /* Height of the tree headed by this node */
  2111. public Table pZombieTab; /* List of Table objects to delete after code gen */
  2112. #endif
  2113. #if DEBUG_CLASS
  2114. public int op
  2115. {
  2116. get { return _op; }
  2117. set { _op = value; }
  2118. }
  2119. #endif
  2120. public void CopyFrom( Expr cf )
  2121. {
  2122. op = cf.op;
  2123. affinity = cf.affinity;
  2124. flags = cf.flags;
  2125. u = cf.u;
  2126. pColl = cf.pColl == null ? null : cf.pColl.Copy();
  2127. iTable = cf.iTable;
  2128. iColumn = cf.iColumn;
  2129. pAggInfo = cf.pAggInfo == null ? null : cf.pAggInfo.Copy();
  2130. iAgg = cf.iAgg;
  2131. iRightJoinTable = cf.iRightJoinTable;
  2132. flags2 = cf.flags2;
  2133. pTab = cf.pTab == null ? null : cf.pTab;
  2134. #if SQLITE_TEST || SQLITE_MAX_EXPR_DEPTH //SQLITE_MAX_EXPR_DEPTH>0
  2135. nHeight = cf.nHeight;
  2136. pZombieTab = cf.pZombieTab;
  2137. #endif
  2138. pLeft = cf.pLeft == null ? null : cf.pLeft.Copy();
  2139. pRight = cf.pRight == null ? null : cf.pRight.Copy();
  2140. x.pList = cf.x.pList == null ? null : cf.x.pList.Copy();
  2141. x.pSelect = cf.x.pSelect == null ? null : cf.x.pSelect.Copy();
  2142. }
  2143. public Expr Copy()
  2144. {
  2145. if ( this == null )
  2146. return null;
  2147. else
  2148. return Copy( flags );
  2149. }
  2150. public Expr Copy( int flag )
  2151. {
  2152. Expr cp = new Expr();
  2153. cp.op = op;
  2154. cp.affinity = affinity;
  2155. cp.flags = flags;
  2156. cp.u = u;
  2157. if ( ( flag & EP_TokenOnly ) != 0 )
  2158. return cp;
  2159. if ( pLeft != null )
  2160. cp.pLeft = pLeft.Copy();
  2161. if ( pRight != null )
  2162. cp.pRight = pRight.Copy();
  2163. cp.x = x;
  2164. cp.pColl = pColl;
  2165. if ( ( flag & EP_Reduced ) != 0 )
  2166. return cp;
  2167. cp.iTable = iTable;
  2168. cp.iColumn = iColumn;
  2169. cp.iAgg = iAgg;
  2170. cp.iRightJoinTable = iRightJoinTable;
  2171. cp.flags2 = flags2;
  2172. cp.op2 = op2;
  2173. cp.pAggInfo = pAggInfo;
  2174. cp.pTab = pTab;
  2175. #if SQLITE_MAX_EXPR_DEPTH //>0
  2176. cp.nHeight = nHeight;
  2177. cp.pZombieTab = pZombieTab;
  2178. #endif
  2179. return cp;
  2180. }
  2181. };
  2182. /*
  2183. ** The following are the meanings of bits in the Expr.flags field.
  2184. */
  2185. //#define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
  2186. //#define EP_Agg 0x0002 /* Contains one or more aggregate functions */
  2187. //#define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */
  2188. //#define EP_Error 0x0008 /* Expression contains one or more errors */
  2189. //#define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */
  2190. //#define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */
  2191. //#define EP_DblQuoted 0x0040 /* token.z was originally in "..." */
  2192. //#define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */
  2193. //#define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */
  2194. //#define EP_FixedDest 0x0200 /* Result needed in a specific register */
  2195. //#define EP_IntValue 0x0400 /* Integer value contained in u.iValue */
  2196. //#define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */
  2197. //#define EP_Reduced 0x1000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */
  2198. //#define EP_TokenOnly 0x2000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */
  2199. //#define EP_Static 0x4000 /* Held in memory not obtained from malloc() */
  2200. const ushort EP_FromJoin = 0x0001;
  2201. const ushort EP_Agg = 0x0002;
  2202. const ushort EP_Resolved = 0x0004;
  2203. const ushort EP_Error = 0x0008;
  2204. const ushort EP_Distinct = 0x0010;
  2205. const ushort EP_VarSelect = 0x0020;
  2206. const ushort EP_DblQuoted = 0x0040;
  2207. const ushort EP_InfixFunc = 0x0080;
  2208. const ushort EP_ExpCollate = 0x0100;
  2209. const ushort EP_FixedDest = 0x0200;
  2210. const ushort EP_IntValue = 0x0400;
  2211. const ushort EP_xIsSelect = 0x0800;
  2212. const ushort EP_Reduced = 0x1000;
  2213. const ushort EP_TokenOnly = 0x2000;
  2214. const ushort EP_Static = 0x4000;
  2215. /*
  2216. ** The following are the meanings of bits in the Expr.flags2 field.
  2217. */
  2218. //#define EP2_MallocedToken 0x0001 /* Need to sqlite3DbFree() Expr.zToken */
  2219. //#define EP2_Irreducible 0x0002 /* Cannot EXPRDUP_REDUCE this Expr */
  2220. const u8 EP2_MallocedToken = 0x0001;
  2221. const u8 EP2_Irreducible = 0x0002;
  2222. /*
  2223. ** The pseudo-routine sqlite3ExprSetIrreducible sets the EP2_Irreducible
  2224. ** flag on an expression structure. This flag is used for VV&A only. The
  2225. ** routine is implemented as a macro that only works when in debugging mode,
  2226. ** so as not to burden production code.
  2227. */
  2228. #if SQLITE_DEBUG
  2229. //# define ExprSetIrreducible(X) (X)->flags2 |= EP2_Irreducible
  2230. static void ExprSetIrreducible( Expr X )
  2231. {
  2232. X.flags2 |= EP2_Irreducible;
  2233. }
  2234. #else
  2235. //# define ExprSetIrreducible(X)
  2236. static void ExprSetIrreducible( Expr X ) { }
  2237. #endif
  2238. /*
  2239. ** These macros can be used to test, set, or clear bits in the
  2240. ** Expr.flags field.
  2241. */
  2242. //#define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
  2243. static bool ExprHasProperty( Expr E, int P )
  2244. {
  2245. return ( E.flags & P ) == P;
  2246. }
  2247. //#define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
  2248. static bool ExprHasAnyProperty( Expr E, int P )
  2249. {
  2250. return ( E.flags & P ) != 0;
  2251. }
  2252. //#define ExprSetProperty(E,P) (E)->flags|=(P)
  2253. static void ExprSetProperty( Expr E, int P )
  2254. {
  2255. E.flags = (ushort)( E.flags | P );
  2256. }
  2257. //#define ExprClearProperty(E,P) (E)->flags&=~(P)
  2258. static void ExprClearProperty( Expr E, int P )
  2259. {
  2260. E.flags = (ushort)( E.flags & ~P );
  2261. }
  2262. /*
  2263. ** Macros to determine the number of bytes required by a normal Expr
  2264. ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
  2265. ** and an Expr struct with the EP_TokenOnly flag set.
  2266. */
  2267. //#define EXPR_FULLSIZE sizeof(Expr) /* Full size */
  2268. //#define EXPR_REDUCEDSIZE offsetof(Expr,iTable) /* Common features */
  2269. //#define EXPR_TOKENONLYSIZE offsetof(Expr,pLeft) /* Fewer features */
  2270. // We don't use these in C#, but define them anyway,
  2271. const int EXPR_FULLSIZE = 48;
  2272. const int EXPR_REDUCEDSIZE = 24;
  2273. const int EXPR_TOKENONLYSIZE = 8;
  2274. /*
  2275. ** Flags passed to the sqlite3ExprDup() function. See the header comment
  2276. ** above sqlite3ExprDup() for details.
  2277. */
  2278. //#define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */
  2279. const int EXPRDUP_REDUCE = 0x0001;
  2280. /*
  2281. ** A list of expressions. Each expression may optionally have a
  2282. ** name. An expr/name combination can be used in several ways, such
  2283. ** as the list of "expr AS ID" fields following a "SELECT" or in the
  2284. ** list of "ID = expr" items in an UPDATE. A list of expressions can
  2285. ** also be used as the argument to a function, in which case the a.zName
  2286. ** field is not used.
  2287. */
  2288. public class ExprList_item
  2289. {
  2290. public Expr pExpr; /* The list of expressions */
  2291. public string zName; /* Token associated with this expression */
  2292. public string zSpan; /* Original text of the expression */
  2293. public u8 sortOrder; /* 1 for DESC or 0 for ASC */
  2294. public u8 done; /* A flag to indicate when processing is finished */
  2295. public u16 iCol; /* For ORDER BY, column number in result set */
  2296. public u16 iAlias; /* Index into Parse.aAlias[] for zName */
  2297. }
  2298. public class ExprList
  2299. {
  2300. public int nExpr; /* Number of expressions on the list */
  2301. public int nAlloc; /* Number of entries allocated below */
  2302. public int iECursor; /* VDBE VdbeCursor associated with this ExprList */
  2303. public ExprList_item[] a; /* One entry for each expression */
  2304. public ExprList Copy()
  2305. {
  2306. if ( this == null )
  2307. return null;
  2308. else
  2309. {
  2310. ExprList cp = (ExprList)MemberwiseClone();
  2311. a.CopyTo( cp.a, 0 );
  2312. return cp;
  2313. }
  2314. }
  2315. };
  2316. /*
  2317. ** An instance of this structure is used by the parser to record both
  2318. ** the parse tree for an expression and the span of input text for an
  2319. ** expression.
  2320. */
  2321. public class ExprSpan
  2322. {
  2323. public Expr pExpr; /* The expression parse tree */
  2324. public string zStart; /* First character of input text */
  2325. public string zEnd; /* One character past the end of input text */
  2326. };
  2327. /*
  2328. ** An instance of this structure can hold a simple list of identifiers,
  2329. ** such as the list "a,b,c" in the following statements:
  2330. **
  2331. ** INSERT INTO t(a,b,c) VALUES ...;
  2332. ** CREATE INDEX idx ON t(a,b,c);
  2333. ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
  2334. **
  2335. ** The IdList.a.idx field is used when the IdList represents the list of
  2336. ** column names after a table name in an INSERT statement. In the statement
  2337. **
  2338. ** INSERT INTO t(a,b,c) ...
  2339. **
  2340. ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
  2341. */
  2342. public class IdList_item
  2343. {
  2344. public string zName; /* Name of the identifier */
  2345. public int idx; /* Index in some Table.aCol[] of a column named zName */
  2346. }
  2347. public class IdList
  2348. {
  2349. public IdList_item[] a;
  2350. public int nId; /* Number of identifiers on the list */
  2351. public int nAlloc; /* Number of entries allocated for a[] below */
  2352. public IdList Copy()
  2353. {
  2354. if ( this == null )
  2355. return null;
  2356. else
  2357. {
  2358. IdList cp = (IdList)MemberwiseClone();
  2359. a.CopyTo( cp.a, 0 );
  2360. return cp;
  2361. }
  2362. }
  2363. };
  2364. /*
  2365. ** The bitmask datatype defined below is used for various optimizations.
  2366. **
  2367. ** Changing this from a 64-bit to a 32-bit type limits the number of
  2368. ** tables in a join to 32 instead of 64. But it also reduces the size
  2369. ** of the library by 738 bytes on ix86.
  2370. */
  2371. //typedef u64 Bitmask;
  2372. /*
  2373. ** The number of bits in a Bitmask. "BMS" means "BitMask Size".
  2374. */
  2375. //#define BMS ((int)(sizeof(Bitmask)*8))
  2376. const int BMS = ( (int)( sizeof( Bitmask ) * 8 ) );
  2377. /*
  2378. ** The following structure describes the FROM clause of a SELECT statement.
  2379. ** Each table or subquery in the FROM clause is a separate element of
  2380. ** the SrcList.a[] array.
  2381. **
  2382. ** With the addition of multiple database support, the following structure
  2383. ** can also be used to describe a particular table such as the table that
  2384. ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
  2385. ** such a table must be a simple name: ID. But in SQLite, the table can
  2386. ** now be identified by a database name, a dot, then the table name: ID.ID.
  2387. **
  2388. ** The jointype starts out showing the join type between the current table
  2389. ** and the next table on the list. The parser builds the list this way.
  2390. ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
  2391. ** jointype expresses the join between the table and the previous table.
  2392. **
  2393. ** In the colUsed field, the high-order bit (bit 63) is set if the table
  2394. ** contains more than 63 columns and the 64-th or later column is used.
  2395. */
  2396. public class SrcList_item
  2397. {
  2398. public string zDatabase; /* Name of database holding this table */
  2399. public string zName; /* Name of the table */
  2400. public string zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
  2401. public Table pTab; /* An SQL table corresponding to zName */
  2402. public Select pSelect; /* A SELECT statement used in place of a table name */
  2403. public u8 isPopulated; /* Temporary table associated with SELECT is populated */
  2404. public u8 jointype; /* Type of join between this able and the previous */
  2405. public u8 notIndexed; /* True if there is a NOT INDEXED clause */
  2406. #if !SQLITE_OMIT_EXPLAIN
  2407. public u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
  2408. #endif
  2409. public int iCursor; /* The VDBE cursor number used to access this table */
  2410. public Expr pOn; /* The ON clause of a join */
  2411. public IdList pUsing; /* The USING clause of a join */
  2412. public Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
  2413. public string zIndex; /* Identifier from "INDEXED BY <zIndex>" clause */
  2414. public Index pIndex; /* Index structure corresponding to zIndex, if any */
  2415. }
  2416. public class SrcList
  2417. {
  2418. public i16 nSrc; /* Number of tables or subqueries in the FROM clause */
  2419. public i16 nAlloc; /* Number of entries allocated in a[] below */
  2420. public SrcList_item[] a;/* One entry for each identifier on the list */
  2421. public SrcList Copy()
  2422. {
  2423. if ( this == null )
  2424. return null;
  2425. else
  2426. {
  2427. SrcList cp = (SrcList)MemberwiseClone();
  2428. if ( a != null )
  2429. a.CopyTo( cp.a, 0 );
  2430. return cp;
  2431. }
  2432. }
  2433. };
  2434. /*
  2435. ** Permitted values of the SrcList.a.jointype field
  2436. */
  2437. const int JT_INNER = 0x0001; //#define JT_INNER 0x0001 /* Any kind of inner or cross join */
  2438. const int JT_CROSS = 0x0002; //#define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */
  2439. const int JT_NATURAL = 0x0004; //#define JT_NATURAL 0x0004 /* True for a "natural" join */
  2440. const int JT_LEFT = 0x0008; //#define JT_LEFT 0x0008 /* Left outer join */
  2441. const int JT_RIGHT = 0x0010; //#define JT_RIGHT 0x0010 /* Right outer join */
  2442. const int JT_OUTER = 0x0020; //#define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
  2443. const int JT_ERROR = 0x0040; //#define JT_ERROR 0x0040 /* unknown or unsupported join type */
  2444. /*
  2445. ** A WherePlan object holds information that describes a lookup
  2446. ** strategy.
  2447. **
  2448. ** This object is intended to be opaque outside of the where.c module.
  2449. ** It is included here only so that that compiler will know how big it
  2450. ** is. None of the fields in this object should be used outside of
  2451. ** the where.c module.
  2452. **
  2453. ** Within the union, pIdx is only used when wsFlags&WHERE_INDEXED is true.
  2454. ** pTerm is only used when wsFlags&WHERE_MULTI_OR is true. And pVtabIdx
  2455. ** is only used when wsFlags&WHERE_VIRTUALTABLE is true. It is never the
  2456. ** case that more than one of these conditions is true.
  2457. */
  2458. public class WherePlan
  2459. {
  2460. public u32 wsFlags; /* WHERE_* flags that describe the strategy */
  2461. public u32 nEq; /* Number of == constraints */
  2462. public double nRow; /* Estimated number of rows (for EQP) */
  2463. public class _u
  2464. {
  2465. public Index pIdx; /* Index when WHERE_INDEXED is true */
  2466. public WhereTerm pTerm; /* WHERE clause term for OR-search */
  2467. public sqlite3_index_info pVtabIdx; /* Virtual table index to use */
  2468. }
  2469. public _u u = new _u();
  2470. public void Clear()
  2471. {
  2472. wsFlags = 0;
  2473. nEq = 0;
  2474. nRow = 0;
  2475. u.pIdx = null;
  2476. u.pTerm = null;
  2477. u.pVtabIdx = null;
  2478. }
  2479. };
  2480. /*
  2481. ** For each nested loop in a WHERE clause implementation, the WhereInfo
  2482. ** structure contains a single instance of this structure. This structure
  2483. ** is intended to be private the the where.c module and should not be
  2484. ** access or modified by other modules.
  2485. **
  2486. ** The pIdxInfo field is used to help pick the best index on a
  2487. ** virtual table. The pIdxInfo pointer contains indexing
  2488. ** information for the i-th table in the FROM clause before reordering.
  2489. ** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
  2490. ** All other information in the i-th WhereLevel object for the i-th table
  2491. ** after FROM clause ordering.
  2492. */
  2493. public class InLoop
  2494. {
  2495. public int iCur; /* The VDBE cursor used by this IN operator */
  2496. public int addrInTop; /* Top of the IN loop */
  2497. }
  2498. public class WhereLevel
  2499. {
  2500. public WherePlan plan = new WherePlan(); /* query plan for this element of the FROM clause */
  2501. public int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
  2502. public int iTabCur; /* The VDBE cursor used to access the table */
  2503. public int iIdxCur; /* The VDBE cursor used to access pIdx */
  2504. public int addrBrk; /* Jump here to break out of the loop */
  2505. public int addrNxt; /* Jump here to start the next IN combination */
  2506. public int addrCont; /* Jump here to continue with the next loop cycle */
  2507. public int addrFirst; /* First instruction of interior of the loop */
  2508. public u8 iFrom; /* Which entry in the FROM clause */
  2509. public u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
  2510. public int p1, p2; /* Operands of the opcode used to ends the loop */
  2511. public class _u
  2512. {
  2513. public class __in /* Information that depends on plan.wsFlags */
  2514. {
  2515. public int nIn; /* Number of entries in aInLoop[] */
  2516. public InLoop[] aInLoop; /* Information about each nested IN operator */
  2517. }
  2518. public __in _in = new __in(); /* Used when plan.wsFlags&WHERE_IN_ABLE */
  2519. }
  2520. public _u u = new _u();
  2521. /* The following field is really not part of the current level. But
  2522. ** we need a place to cache virtual table index information for each
  2523. ** virtual table in the FROM clause and the WhereLevel structure is
  2524. ** a convenient place since there is one WhereLevel for each FROM clause
  2525. ** element.
  2526. */
  2527. public sqlite3_index_info pIdxInfo; /* Index info for n-th source table */
  2528. };
  2529. /*
  2530. ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
  2531. ** and the WhereInfo.wctrlFlags member.
  2532. */
  2533. //#define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
  2534. //#define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
  2535. //#define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
  2536. //#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
  2537. //#define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
  2538. //#define WHERE_OMIT_OPEN 0x0010 /* Table cursors are already open */
  2539. //#define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
  2540. //#define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
  2541. //#define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
  2542. const int WHERE_ORDERBY_NORMAL = 0x0000;
  2543. const int WHERE_ORDERBY_MIN = 0x0001;
  2544. const int WHERE_ORDERBY_MAX = 0x0002;
  2545. const int WHERE_ONEPASS_DESIRED = 0x0004;
  2546. const int WHERE_DUPLICATES_OK = 0x0008;
  2547. const int WHERE_OMIT_OPEN = 0x0010;
  2548. const int WHERE_OMIT_CLOSE = 0x0020;
  2549. const int WHERE_FORCE_TABLE = 0x0040;
  2550. const int WHERE_ONETABLE_ONLY = 0x0080;
  2551. /*
  2552. ** The WHERE clause processing routine has two halves. The
  2553. ** first part does the start of the WHERE loop and the second
  2554. ** half does the tail of the WHERE loop. An instance of
  2555. ** this structure is returned by the first half and passed
  2556. ** into the second half to give some continuity.
  2557. */
  2558. public class WhereInfo
  2559. {
  2560. public Parse pParse; /* Parsing and code generating context */
  2561. public u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
  2562. public u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE or DELETE */
  2563. public u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
  2564. public SrcList pTabList; /* List of tables in the join */
  2565. public int iTop; /* The very beginning of the WHERE loop */
  2566. public int iContinue; /* Jump here to continue with next record */
  2567. public int iBreak; /* Jump here to break out of the loop */
  2568. public int nLevel; /* Number of nested loop */
  2569. public WhereClause pWC; /* Decomposition of the WHERE clause */
  2570. public double savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
  2571. public double nRowOut; /* Estimated number of output rows */
  2572. public WhereLevel[] a = new WhereLevel[] { new WhereLevel() }; /* Information about each nest loop in the WHERE */
  2573. };
  2574. /*
  2575. ** A NameContext defines a context in which to resolve table and column
  2576. ** names. The context consists of a list of tables (the pSrcList) field and
  2577. ** a list of named expression (pEList). The named expression list may
  2578. ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or
  2579. ** to the table being operated on by INSERT, UPDATE, or DELETE. The
  2580. ** pEList corresponds to the result set of a SELECT and is NULL for
  2581. ** other statements.
  2582. **
  2583. ** NameContexts can be nested. When resolving names, the inner-most
  2584. ** context is searched first. If no match is found, the next outer
  2585. ** context is checked. If there is still no match, the next context
  2586. ** is checked. This process continues until either a match is found
  2587. ** or all contexts are check. When a match is found, the nRef member of
  2588. ** the context containing the match is incremented.
  2589. **
  2590. ** Each subquery gets a new NameContext. The pNext field points to the
  2591. ** NameContext in the parent query. Thus the process of scanning the
  2592. ** NameContext list corresponds to searching through successively outer
  2593. ** subqueries looking for a match.
  2594. */
  2595. public class NameContext
  2596. {
  2597. public Parse pParse; /* The parser */
  2598. public SrcList pSrcList; /* One or more tables used to resolve names */
  2599. public ExprList pEList; /* Optional list of named expressions */
  2600. public int nRef; /* Number of names resolved by this context */
  2601. public int nErr; /* Number of errors encountered while resolving names */
  2602. public u8 allowAgg; /* Aggregate functions allowed here */
  2603. public u8 hasAgg; /* True if aggregates are seen */
  2604. public u8 isCheck; /* True if resolving names in a CHECK constraint */
  2605. public int nDepth; /* Depth of subquery recursion. 1 for no recursion */
  2606. public AggInfo pAggInfo; /* Information about aggregates at this level */
  2607. public NameContext pNext; /* Next outer name context. NULL for outermost */
  2608. };
  2609. /*
  2610. ** An instance of the following structure contains all information
  2611. ** needed to generate code for a single SELECT statement.
  2612. **
  2613. ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.
  2614. ** If there is a LIMIT clause, the parser sets nLimit to the value of the
  2615. ** limit and nOffset to the value of the offset (or 0 if there is not
  2616. ** offset). But later on, nLimit and nOffset become the memory locations
  2617. ** in the VDBE that record the limit and offset counters.
  2618. **
  2619. ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.
  2620. ** These addresses must be stored so that we can go back and fill in
  2621. ** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor
  2622. ** the number of columns in P2 can be computed at the same time
  2623. ** as the OP_OpenEphm instruction is coded because not
  2624. ** enough information about the compound query is known at that point.
  2625. ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
  2626. ** for the result set. The KeyInfo for addrOpenTran[2] contains collating
  2627. ** sequences for the ORDER BY clause.
  2628. */
  2629. public class Select
  2630. {
  2631. public ExprList pEList; /* The fields of the result */
  2632. public u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
  2633. public char affinity; /* MakeRecord with this affinity for SRT_Set */
  2634. public u16 selFlags; /* Various SF_* values */
  2635. public SrcList pSrc; /* The FROM clause */
  2636. public Expr pWhere; /* The WHERE clause */
  2637. public ExprList pGroupBy; /* The GROUP BY clause */
  2638. public Expr pHaving; /* The HAVING clause */
  2639. public ExprList pOrderBy; /* The ORDER BY clause */
  2640. public Select pPrior; /* Prior select in a compound select statement */
  2641. public Select pNext; /* Next select to the left in a compound */
  2642. public Select pRightmost; /* Right-most select in a compound select statement */
  2643. public Expr pLimit; /* LIMIT expression. NULL means not used. */
  2644. public Expr pOffset; /* OFFSET expression. NULL means not used. */
  2645. public int iLimit;
  2646. public int iOffset; /* Memory registers holding LIMIT & OFFSET counters */
  2647. public int[] addrOpenEphm = new int[3]; /* OP_OpenEphem opcodes related to this select */
  2648. public double nSelectRow; /* Estimated number of result rows */
  2649. public Select Copy()
  2650. {
  2651. if ( this == null )
  2652. return null;
  2653. else
  2654. {
  2655. Select cp = (Select)MemberwiseClone();
  2656. if ( pEList != null )
  2657. cp.pEList = pEList.Copy();
  2658. if ( pSrc != null )
  2659. cp.pSrc = pSrc.Copy();
  2660. if ( pWhere != null )
  2661. cp.pWhere = pWhere.Copy();
  2662. if ( pGroupBy != null )
  2663. cp.pGroupBy = pGroupBy.Copy();
  2664. if ( pHaving != null )
  2665. cp.pHaving = pHaving.Copy();
  2666. if ( pOrderBy != null )
  2667. cp.pOrderBy = pOrderBy.Copy();
  2668. if ( pPrior != null )
  2669. cp.pPrior = pPrior.Copy();
  2670. if ( pNext != null )
  2671. cp.pNext = pNext.Copy();
  2672. if ( pRightmost != null )
  2673. cp.pRightmost = pRightmost.Copy();
  2674. if ( pLimit != null )
  2675. cp.pLimit = pLimit.Copy();
  2676. if ( pOffset != null )
  2677. cp.pOffset = pOffset.Copy();
  2678. return cp;
  2679. }
  2680. }
  2681. };
  2682. /*
  2683. ** Allowed values for Select.selFlags. The "SF" prefix stands for
  2684. ** "Select Flag".
  2685. */
  2686. //#define SF_Distinct 0x0001 /* Output should be DISTINCT */
  2687. //#define SF_Resolved 0x0002 /* Identifiers have been resolved */
  2688. //#define SF_Aggregate 0x0004 /* Contains aggregate functions */
  2689. //#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
  2690. //#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
  2691. //#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
  2692. const int SF_Distinct = 0x0001; /* Output should be DISTINCT */
  2693. const int SF_Resolved = 0x0002; /* Identifiers have been resolved */
  2694. const int SF_Aggregate = 0x0004; /* Contains aggregate functions */
  2695. const int SF_UsesEphemeral = 0x0008; /* Uses the OpenEphemeral opcode */
  2696. const int SF_Expanded = 0x0010; /* sqlite3SelectExpand() called on this */
  2697. const int SF_HasTypeInfo = 0x0020; /* FROM subqueries have Table metadata */
  2698. /*
  2699. ** The results of a select can be distributed in several ways. The
  2700. ** "SRT" prefix means "SELECT Result Type".
  2701. */
  2702. const int SRT_Union = 1;//#define SRT_Union 1 /* Store result as keys in an index */
  2703. const int SRT_Except = 2;//#define SRT_Except 2 /* Remove result from a UNION index */
  2704. const int SRT_Exists = 3;//#define SRT_Exists 3 /* Store 1 if the result is not empty */
  2705. const int SRT_Discard = 4;//#define SRT_Discard 4 /* Do not save the results anywhere */
  2706. /* The ORDER BY clause is ignored for all of the above */
  2707. //#define IgnorableOrderby(X) ((X->eDest)<=SRT_Discard)
  2708. const int SRT_Output = 5;//#define SRT_Output 5 /* Output each row of result */
  2709. const int SRT_Mem = 6;//#define SRT_Mem 6 /* Store result in a memory cell */
  2710. const int SRT_Set = 7;//#define SRT_Set 7 /* Store results as keys in an index */
  2711. const int SRT_Table = 8;//#define SRT_Table 8 /* Store result as data with an automatic rowid */
  2712. const int SRT_EphemTab = 9;//#define SRT_EphemTab 9 /* Create transient tab and store like SRT_Table /
  2713. const int SRT_Coroutine = 10;//#define SRT_Coroutine 10 /* Generate a single row of result */
  2714. /*
  2715. ** A structure used to customize the behavior of sqlite3Select(). See
  2716. ** comments above sqlite3Select() for details.
  2717. */
  2718. //typedef struct SelectDest SelectDest;
  2719. public class SelectDest
  2720. {
  2721. public u8 eDest; /* How to dispose of the results */
  2722. public char affinity; /* Affinity used when eDest==SRT_Set */
  2723. public int iParm; /* A parameter used by the eDest disposal method */
  2724. public int iMem; /* Base register where results are written */
  2725. public int nMem; /* Number of registers allocated */
  2726. public SelectDest()
  2727. {
  2728. this.eDest = 0;
  2729. this.affinity = '\0';
  2730. this.iParm = 0;
  2731. this.iMem = 0;
  2732. this.nMem = 0;
  2733. }
  2734. public SelectDest( u8 eDest, char affinity, int iParm )
  2735. {
  2736. this.eDest = eDest;
  2737. this.affinity = affinity;
  2738. this.iParm = iParm;
  2739. this.iMem = 0;
  2740. this.nMem = 0;
  2741. }
  2742. public SelectDest( u8 eDest, char affinity, int iParm, int iMem, int nMem )
  2743. {
  2744. this.eDest = eDest;
  2745. this.affinity = affinity;
  2746. this.iParm = iParm;
  2747. this.iMem = iMem;
  2748. this.nMem = nMem;
  2749. }
  2750. };
  2751. /*
  2752. ** During code generation of statements that do inserts into AUTOINCREMENT
  2753. ** tables, the following information is attached to the Table.u.autoInc.p
  2754. ** pointer of each autoincrement table to record some side information that
  2755. ** the code generator needs. We have to keep per-table autoincrement
  2756. ** information in case inserts are down within triggers. Triggers do not
  2757. ** normally coordinate their activities, but we do need to coordinate the
  2758. ** loading and saving of autoincrement information.
  2759. */
  2760. public class AutoincInfo
  2761. {
  2762. public AutoincInfo pNext; /* Next info block in a list of them all */
  2763. public Table pTab; /* Table this info block refers to */
  2764. public int iDb; /* Index in sqlite3.aDb[] of database holding pTab */
  2765. public int regCtr; /* Memory register holding the rowid counter */
  2766. };
  2767. /*
  2768. ** Size of the column cache
  2769. */
  2770. #if !SQLITE_N_COLCACHE
  2771. //# define SQLITE_N_COLCACHE 10
  2772. const int SQLITE_N_COLCACHE = 10;
  2773. #endif
  2774. /*
  2775. ** At least one instance of the following structure is created for each
  2776. ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
  2777. ** statement. All such objects are stored in the linked list headed at
  2778. ** Parse.pTriggerPrg and deleted once statement compilation has been
  2779. ** completed.
  2780. **
  2781. ** A Vdbe sub-program that implements the body and WHEN clause of trigger
  2782. ** TriggerPrg.pTrigger, assuming a default ON CONFLICT clause of
  2783. ** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable.
  2784. ** The Parse.pTriggerPrg list never contains two entries with the same
  2785. ** values for both pTrigger and orconf.
  2786. **
  2787. ** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns
  2788. ** accessed (or set to 0 for triggers fired as a result of INSERT
  2789. ** statements). Similarly, the TriggerPrg.aColmask[1] variable is set to
  2790. ** a mask of new.* columns used by the program.
  2791. */
  2792. public class TriggerPrg
  2793. {
  2794. public Trigger pTrigger; /* Trigger this program was coded from */
  2795. public int orconf; /* Default ON CONFLICT policy */
  2796. public SubProgram pProgram; /* Program implementing pTrigger/orconf */
  2797. public u32[] aColmask = new u32[2]; /* Masks of old.*, new.* columns accessed */
  2798. public TriggerPrg pNext; /* Next entry in Parse.pTriggerPrg list */
  2799. };
  2800. /*
  2801. ** The yDbMask datatype for the bitmask of all attached databases.
  2802. */
  2803. //#if SQLITE_MAX_ATTACHED>30
  2804. // typedef sqlite3_uint64 yDbMask;
  2805. //#else
  2806. // typedef unsigned int yDbMask;
  2807. //#endif
  2808. /*
  2809. ** An SQL parser context. A copy of this structure is passed through
  2810. ** the parser and down into all the parser action routine in order to
  2811. ** carry around information that is global to the entire parse.
  2812. **
  2813. ** The structure is divided into two parts. When the parser and code
  2814. ** generate call themselves recursively, the first part of the structure
  2815. ** is constant but the second part is reset at the beginning and end of
  2816. ** each recursion.
  2817. **
  2818. ** The nTableLock and aTableLock variables are only used if the shared-cache
  2819. ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
  2820. ** used to store the set of table-locks required by the statement being
  2821. ** compiled. Function sqlite3TableLock() is used to add entries to the
  2822. ** list.
  2823. */
  2824. public class yColCache
  2825. {
  2826. public int iTable; /* Table cursor number */
  2827. public int iColumn; /* Table column number */
  2828. public u8 tempReg; /* iReg is a temp register that needs to be freed */
  2829. public int iLevel; /* Nesting level */
  2830. public int iReg; /* Reg with value of this column. 0 means none. */
  2831. public int lru; /* Least recently used entry has the smallest value */
  2832. }
  2833. public class Parse
  2834. {
  2835. public sqlite3 db; /* The main database structure */
  2836. public int rc; /* Return code from execution */
  2837. public string zErrMsg; /* An error message */
  2838. public Vdbe pVdbe; /* An engine for executing database bytecode */
  2839. public u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
  2840. public u8 nameClash; /* A permanent table name clashes with temp table name */
  2841. public u8 checkSchema; /* Causes schema cookie check after an error */
  2842. public u8 nested; /* Number of nested calls to the parser/code generator */
  2843. public u8 parseError; /* True after a parsing error. Ticket #1794 */
  2844. public u8 nTempReg; /* Number of temporary registers in aTempReg[] */
  2845. public u8 nTempInUse; /* Number of aTempReg[] currently checked out */
  2846. public int[] aTempReg; /* Holding area for temporary registers */
  2847. public int nRangeReg; /* Size of the temporary register block */
  2848. public int iRangeReg; /* First register in temporary register block */
  2849. public int nErr; /* Number of errors seen */
  2850. public int nTab; /* Number of previously allocated VDBE cursors */
  2851. public int nMem; /* Number of memory cells used so far */
  2852. public int nSet; /* Number of sets used so far */
  2853. public int ckBase; /* Base register of data during check constraints */
  2854. public int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
  2855. public int iCacheCnt; /* Counter used to generate aColCache[].lru values */
  2856. public u8 nColCache; /* Number of entries in the column cache */
  2857. public u8 iColCache; /* Next entry of the cache to replace */
  2858. public yColCache[] aColCache;/* One for each valid column cache entry */
  2859. public yDbMask writeMask; /* Start a write transaction on these databases */
  2860. public yDbMask cookieMask; /* Bitmask of schema verified databases */
  2861. public u8 isMultiWrite; /* True if statement may affect/insert multiple rows */
  2862. public u8 mayAbort; /* True if statement may throw an ABORT exception */
  2863. public int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
  2864. public int[] cookieValue; /* Values of cookies to verify */
  2865. #if !SQLITE_OMIT_SHARED_CACHE
  2866. public int nTableLock; /* Number of locks in aTableLock */
  2867. public TableLock[] aTableLock; /* Required table locks for shared-cache mode */
  2868. #endif
  2869. public int regRowid; /* Register holding rowid of CREATE TABLE entry */
  2870. public int regRoot; /* Register holding root page number for new objects */
  2871. public AutoincInfo pAinc; /* Information about AUTOINCREMENT counters */
  2872. public int nMaxArg; /* Max args passed to user function by sub-program */
  2873. /* Information used while coding trigger programs. */
  2874. public Parse pToplevel; /* Parse structure for main program (or NULL) */
  2875. public Table pTriggerTab; /* Table triggers are being coded for */
  2876. public u32 oldmask; /* Mask of old.* columns referenced */
  2877. public u32 newmask; /* Mask of new.* columns referenced */
  2878. public u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
  2879. public u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
  2880. public u8 disableTriggers; /* True to disable triggers */
  2881. public double nQueryLoop; /* Estimated number of iterations of a query */
  2882. /* Above is constant between recursions. Below is reset before and after
  2883. ** each recursion */
  2884. public int nVar; /* Number of '?' variables seen in the SQL so far */
  2885. public int nzVar; /* Number of available slots in azVar[] */
  2886. public string[] azVar; /* Pointers to names of parameters */
  2887. public Vdbe pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
  2888. public int nAlias; /* Number of aliased result set columns */
  2889. public int nAliasAlloc; /* Number of allocated slots for aAlias[] */
  2890. public int[] aAlias; /* Register used to hold aliased result */
  2891. public u8 explain; /* True if the EXPLAIN flag is found on the query */
  2892. public Token sNameToken; /* Token with unqualified schema object name */
  2893. public Token sLastToken; /* The last token parsed */
  2894. public StringBuilder zTail; /* All SQL text past the last semicolon parsed */
  2895. public Table pNewTable; /* A table being constructed by CREATE TABLE */
  2896. public Trigger pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
  2897. public string zAuthContext; /* The 6th parameter to db.xAuth callbacks */
  2898. #if !SQLITE_OMIT_VIRTUALTABLE
  2899. public Token sArg; /* Complete text of a module argument */
  2900. public u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
  2901. public int nVtabLock; /* Number of virtual tables to lock */
  2902. public Table[] apVtabLock; /* Pointer to virtual tables needing locking */
  2903. #endif
  2904. public int nHeight; /* Expression tree height of current sub-select */
  2905. public Table pZombieTab; /* List of Table objects to delete after code gen */
  2906. public TriggerPrg pTriggerPrg; /* Linked list of coded triggers */
  2907. #if !SQLITE_OMIT_EXPLAIN
  2908. public int iSelectId;
  2909. public int iNextSelectId;
  2910. #endif
  2911. // We need to create instances of the col cache
  2912. public Parse()
  2913. {
  2914. aTempReg = new int[8]; /* Holding area for temporary registers */
  2915. aColCache = new yColCache[SQLITE_N_COLCACHE]; /* One for each valid column cache entry */
  2916. for ( int i = 0; i < this.aColCache.Length; i++ )
  2917. {
  2918. this.aColCache[i] = new yColCache();
  2919. }
  2920. cookieValue = new int[SQLITE_MAX_ATTACHED + 2]; /* Values of cookies to verify */
  2921. sLastToken = new Token(); /* The last token parsed */
  2922. #if !SQLITE_OMIT_VIRTUALTABLE
  2923. sArg = new Token();
  2924. #endif
  2925. }
  2926. public void ResetMembers() // Need to clear all the following variables during each recursion
  2927. {
  2928. nVar = 0;
  2929. nzVar = 0;
  2930. azVar = null;
  2931. nAlias = 0;
  2932. nAliasAlloc = 0;
  2933. aAlias = null;
  2934. explain = 0;
  2935. sNameToken = new Token();
  2936. sLastToken = new Token();
  2937. zTail.Length = 0;
  2938. pNewTable = null;
  2939. pNewTrigger = null;
  2940. zAuthContext = null;
  2941. #if !SQLITE_OMIT_VIRTUALTABLE
  2942. sArg = new Token();
  2943. declareVtab = 0;
  2944. nVtabLock = 0;
  2945. apVtabLock = null;
  2946. #endif
  2947. nHeight = 0;
  2948. pZombieTab = null;
  2949. pTriggerPrg = null;
  2950. }
  2951. Parse[] SaveBuf = new Parse[10]; //For Recursion Storage
  2952. public void RestoreMembers() // Need to clear all the following variables during each recursion
  2953. {
  2954. if ( SaveBuf[nested] != null )
  2955. {
  2956. nVar = SaveBuf[nested].nVar;
  2957. nzVar = SaveBuf[nested].nzVar;
  2958. azVar = SaveBuf[nested].azVar;
  2959. nAlias = SaveBuf[nested].nAlias;
  2960. nAliasAlloc = SaveBuf[nested].nAliasAlloc;
  2961. aAlias = SaveBuf[nested].aAlias;
  2962. explain = SaveBuf[nested].explain;
  2963. sNameToken = SaveBuf[nested].sNameToken;
  2964. sLastToken = SaveBuf[nested].sLastToken;
  2965. zTail = SaveBuf[nested].zTail;
  2966. pNewTable = SaveBuf[nested].pNewTable;
  2967. pNewTrigger = SaveBuf[nested].pNewTrigger;
  2968. zAuthContext = SaveBuf[nested].zAuthContext;
  2969. #if !SQLITE_OMIT_VIRTUALTABLE
  2970. sArg = SaveBuf[nested].sArg;
  2971. declareVtab = SaveBuf[nested].declareVtab;
  2972. nVtabLock = SaveBuf[nested].nVtabLock;
  2973. apVtabLock = SaveBuf[nested].apVtabLock;
  2974. #endif
  2975. nHeight = SaveBuf[nested].nHeight;
  2976. pZombieTab = SaveBuf[nested].pZombieTab;
  2977. pTriggerPrg = SaveBuf[nested].pTriggerPrg;
  2978. SaveBuf[nested] = null;
  2979. }
  2980. }
  2981. public void SaveMembers() // Need to clear all the following variables during each recursion
  2982. {
  2983. SaveBuf[nested] = new Parse();
  2984. SaveBuf[nested].nVar = nVar;
  2985. SaveBuf[nested].nzVar = nzVar;
  2986. SaveBuf[nested].azVar = azVar;
  2987. SaveBuf[nested].nAlias = nAlias;
  2988. SaveBuf[nested].nAliasAlloc = nAliasAlloc;
  2989. SaveBuf[nested].aAlias = aAlias;
  2990. SaveBuf[nested].explain = explain;
  2991. SaveBuf[nested].sNameToken = sNameToken;
  2992. SaveBuf[nested].sLastToken = sLastToken;
  2993. SaveBuf[nested].zTail = zTail;
  2994. SaveBuf[nested].pNewTable = pNewTable;
  2995. SaveBuf[nested].pNewTrigger = pNewTrigger;
  2996. SaveBuf[nested].zAuthContext = zAuthContext;
  2997. #if !SQLITE_OMIT_VIRTUALTABLE
  2998. SaveBuf[nested].sArg = sArg;
  2999. SaveBuf[nested].declareVtab = declareVtab;
  3000. SaveBuf[nested].nVtabLock = nVtabLock;
  3001. SaveBuf[nested].apVtabLock = apVtabLock;
  3002. #endif
  3003. SaveBuf[nested].nHeight = nHeight;
  3004. SaveBuf[nested].pZombieTab = pZombieTab;
  3005. SaveBuf[nested].pTriggerPrg = pTriggerPrg;
  3006. }
  3007. };
  3008. #if SQLITE_OMIT_VIRTUALTABLE
  3009. //#define IN_DECLARE_VTAB 0
  3010. static bool IN_DECLARE_VTAB( Parse pParse )
  3011. {
  3012. return false;
  3013. }
  3014. #else
  3015. //#define IN_DECLARE_VTAB (pParse.declareVtab)
  3016. static bool IN_DECLARE_VTAB( Parse pParse )
  3017. {
  3018. return pParse.declareVtab != 0;
  3019. }
  3020. #endif
  3021. /*
  3022. ** An instance of the following structure can be declared on a stack and used
  3023. ** to save the Parse.zAuthContext value so that it can be restored later.
  3024. */
  3025. public class AuthContext
  3026. {
  3027. public string zAuthContext; /* Put saved Parse.zAuthContext here */
  3028. public Parse pParse; /* The Parse structure */
  3029. };
  3030. /*
  3031. ** Bitfield flags for P5 value in OP_Insert and OP_Delete
  3032. */
  3033. //#define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
  3034. //#define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
  3035. //#define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
  3036. //#define OPFLAG_APPEND 0x08 /* This is likely to be an append */
  3037. //#define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
  3038. //#define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */
  3039. const byte OPFLAG_NCHANGE = 0x01;
  3040. const byte OPFLAG_LASTROWID = 0x02;
  3041. const byte OPFLAG_ISUPDATE = 0x04;
  3042. const byte OPFLAG_APPEND = 0x08;
  3043. const byte OPFLAG_USESEEKRESULT = 0x10;
  3044. const byte OPFLAG_CLEARCACHE = 0x20;
  3045. /*
  3046. * Each trigger present in the database schema is stored as an instance of
  3047. * struct Trigger.
  3048. *
  3049. * Pointers to instances of struct Trigger are stored in two ways.
  3050. * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
  3051. * database). This allows Trigger structures to be retrieved by name.
  3052. * 2. All triggers associated with a single table form a linked list, using the
  3053. * pNext member of struct Trigger. A pointer to the first element of the
  3054. * linked list is stored as the "pTrigger" member of the associated
  3055. * struct Table.
  3056. *
  3057. * The "step_list" member points to the first element of a linked list
  3058. * containing the SQL statements specified as the trigger program.
  3059. */
  3060. public class Trigger
  3061. {
  3062. public string zName; /* The name of the trigger */
  3063. public string table; /* The table or view to which the trigger applies */
  3064. public u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
  3065. public u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
  3066. public Expr pWhen; /* The WHEN clause of the expression (may be NULL) */
  3067. public IdList pColumns; /* If this is an UPDATE OF <column-list> trigger,
  3068. the <column-list> is stored here */
  3069. public Schema pSchema; /* Schema containing the trigger */
  3070. public Schema pTabSchema; /* Schema containing the table */
  3071. public TriggerStep step_list; /* Link list of trigger program steps */
  3072. public Trigger pNext; /* Next trigger associated with the table */
  3073. public Trigger Copy()
  3074. {
  3075. if ( this == null )
  3076. return null;
  3077. else
  3078. {
  3079. Trigger cp = (Trigger)MemberwiseClone();
  3080. if ( pWhen != null )
  3081. cp.pWhen = pWhen.Copy();
  3082. if ( pColumns != null )
  3083. cp.pColumns = pColumns.Copy();
  3084. if ( pSchema != null )
  3085. cp.pSchema = pSchema.Copy();
  3086. if ( pTabSchema != null )
  3087. cp.pTabSchema = pTabSchema.Copy();
  3088. if ( step_list != null )
  3089. cp.step_list = step_list.Copy();
  3090. if ( pNext != null )
  3091. cp.pNext = pNext.Copy();
  3092. return cp;
  3093. }
  3094. }
  3095. };
  3096. /*
  3097. ** A trigger is either a BEFORE or an AFTER trigger. The following constants
  3098. ** determine which.
  3099. **
  3100. ** If there are multiple triggers, you might of some BEFORE and some AFTER.
  3101. ** In that cases, the constants below can be ORed together.
  3102. */
  3103. const u8 TRIGGER_BEFORE = 1;//#define TRIGGER_BEFORE 1
  3104. const u8 TRIGGER_AFTER = 2;//#define TRIGGER_AFTER 2
  3105. /*
  3106. * An instance of struct TriggerStep is used to store a single SQL statement
  3107. * that is a part of a trigger-program.
  3108. *
  3109. * Instances of struct TriggerStep are stored in a singly linked list (linked
  3110. * using the "pNext" member) referenced by the "step_list" member of the
  3111. * associated struct Trigger instance. The first element of the linked list is
  3112. * the first step of the trigger-program.
  3113. *
  3114. * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
  3115. * "SELECT" statement. The meanings of the other members is determined by the
  3116. * value of "op" as follows:
  3117. *
  3118. * (op == TK_INSERT)
  3119. * orconf -> stores the ON CONFLICT algorithm
  3120. * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
  3121. * this stores a pointer to the SELECT statement. Otherwise NULL.
  3122. * target -> A token holding the quoted name of the table to insert into.
  3123. * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
  3124. * this stores values to be inserted. Otherwise NULL.
  3125. * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
  3126. * statement, then this stores the column-names to be
  3127. * inserted into.
  3128. *
  3129. * (op == TK_DELETE)
  3130. * target -> A token holding the quoted name of the table to delete from.
  3131. * pWhere -> The WHERE clause of the DELETE statement if one is specified.
  3132. * Otherwise NULL.
  3133. *
  3134. * (op == TK_UPDATE)
  3135. * target -> A token holding the quoted name of the table to update rows of.
  3136. * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
  3137. * Otherwise NULL.
  3138. * pExprList -> A list of the columns to update and the expressions to update
  3139. * them to. See sqlite3Update() documentation of "pChanges"
  3140. * argument.
  3141. *
  3142. */
  3143. public class TriggerStep
  3144. {
  3145. public u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
  3146. public u8 orconf; /* OE_Rollback etc. */
  3147. public Trigger pTrig; /* The trigger that this step is a part of */
  3148. public Select pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */
  3149. public Token target; /* Target table for DELETE, UPDATE, INSERT */
  3150. public Expr pWhere; /* The WHERE clause for DELETE or UPDATE steps */
  3151. public ExprList pExprList; /* SET clause for UPDATE. VALUES clause for INSERT */
  3152. public IdList pIdList; /* Column names for INSERT */
  3153. public TriggerStep pNext; /* Next in the link-list */
  3154. public TriggerStep pLast; /* Last element in link-list. Valid for 1st elem only */
  3155. public TriggerStep()
  3156. {
  3157. target = new Token();
  3158. }
  3159. public TriggerStep Copy()
  3160. {
  3161. if ( this == null )
  3162. return null;
  3163. else
  3164. {
  3165. TriggerStep cp = (TriggerStep)MemberwiseClone();
  3166. return cp;
  3167. }
  3168. }
  3169. };
  3170. /*
  3171. ** The following structure contains information used by the sqliteFix...
  3172. ** routines as they walk the parse tree to make database references
  3173. ** explicit.
  3174. */
  3175. //typedef struct DbFixer DbFixer;
  3176. public class DbFixer
  3177. {
  3178. public Parse pParse; /* The parsing context. Error messages written here */
  3179. public string zDb; /* Make sure all objects are contained in this database */
  3180. public string zType; /* Type of the container - used for error messages */
  3181. public Token pName; /* Name of the container - used for error messages */
  3182. };
  3183. /*
  3184. ** An objected used to accumulate the text of a string where we
  3185. ** do not necessarily know how big the string will be in the end.
  3186. */
  3187. public class StrAccum
  3188. {
  3189. public sqlite3 db; /* Optional database for lookaside. Can be NULL */
  3190. //public StringBuilder zBase; /* A base allocation. Not from malloc. */
  3191. public StringBuilder zText; /* The string collected so far */
  3192. //public int nChar; /* Length of the string so far */
  3193. //public int nAlloc; /* Amount of space allocated in zText */
  3194. public int mxAlloc; /* Maximum allowed string length */
  3195. // Cannot happen under C#
  3196. //public u8 mallocFailed; /* Becomes true if any memory allocation fails */
  3197. //public u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
  3198. //public u8 tooBig; /* Becomes true if string size exceeds limits */
  3199. public Mem Context;
  3200. public StrAccum( int n )
  3201. {
  3202. db = null;
  3203. //zBase = new StringBuilder( n );
  3204. zText = new StringBuilder( n );
  3205. //nChar = 0;
  3206. //nAlloc = n;
  3207. mxAlloc = 0;
  3208. //useMalloc = 0;
  3209. //tooBig = 0;
  3210. Context = null;
  3211. }
  3212. public i64 nChar
  3213. {
  3214. get
  3215. {
  3216. return zText.Length;
  3217. }
  3218. }
  3219. public bool tooBig
  3220. {
  3221. get
  3222. {
  3223. return mxAlloc > 0 && zText.Length > mxAlloc;
  3224. }
  3225. }
  3226. };
  3227. /*
  3228. ** A pointer to this structure is used to communicate information
  3229. ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
  3230. */
  3231. public class InitData
  3232. {
  3233. public sqlite3 db; /* The database being initialized */
  3234. public int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
  3235. public string pzErrMsg; /* Error message stored here */
  3236. public int rc; /* Result code stored here */
  3237. }
  3238. /*
  3239. ** Structure containing global configuration data for the SQLite library.
  3240. **
  3241. ** This structure also contains some state information.
  3242. */
  3243. public class Sqlite3Config
  3244. {
  3245. public bool bMemstat; /* True to enable memory status */
  3246. public bool bCoreMutex; /* True to enable core mutexing */
  3247. public bool bFullMutex; /* True to enable full mutexing */
  3248. public bool bOpenUri; /* True to interpret filenames as URIs */
  3249. public int mxStrlen; /* Maximum string length */
  3250. public int szLookaside; /* Default lookaside buffer size */
  3251. public int nLookaside; /* Default lookaside buffer count */
  3252. public sqlite3_mem_methods m; /* Low-level memory allocation interface */
  3253. public sqlite3_mutex_methods mutex; /* Low-level mutex interface */
  3254. public sqlite3_pcache_methods pcache; /* Low-level page-cache interface */
  3255. public byte[] pHeap; /* Heap storage space */
  3256. public int nHeap; /* Size of pHeap[] */
  3257. public int mnReq, mxReq; /* Min and max heap requests sizes */
  3258. public byte[][] pScratch2; /* Scratch memory */
  3259. public byte[][] pScratch; /* Scratch memory */
  3260. public int szScratch; /* Size of each scratch buffer */
  3261. public int nScratch; /* Number of scratch buffers */
  3262. public MemPage pPage; /* Page cache memory */
  3263. public int szPage; /* Size of each page in pPage[] */
  3264. public int nPage; /* Number of pages in pPage[] */
  3265. public int mxParserStack; /* maximum depth of the parser stack */
  3266. public bool sharedCacheEnabled; /* true if shared-cache mode enabled */
  3267. /* The above might be initialized to non-zero. The following need to always
  3268. ** initially be zero, however. */
  3269. public int isInit; /* True after initialization has finished */
  3270. public int inProgress; /* True while initialization in progress */
  3271. public int isMutexInit; /* True after mutexes are initialized */
  3272. public int isMallocInit; /* True after malloc is initialized */
  3273. public int isPCacheInit; /* True after malloc is initialized */
  3274. public sqlite3_mutex pInitMutex; /* Mutex used by sqlite3_initialize() */
  3275. public int nRefInitMutex; /* Number of users of pInitMutex */
  3276. public dxLog xLog; //void (*xLog)(void*,int,const char); /* Function for logging */
  3277. public object pLogArg; /* First argument to xLog() */
  3278. public bool bLocaltimeFault; /* True to fail localtime() calls */
  3279. public Sqlite3Config(
  3280. int bMemstat
  3281. , int bCoreMutex
  3282. , bool bFullMutex
  3283. , bool bOpenUri
  3284. , int mxStrlen
  3285. , int szLookaside
  3286. , int nLookaside
  3287. , sqlite3_mem_methods m
  3288. , sqlite3_mutex_methods mutex
  3289. , sqlite3_pcache_methods pcache
  3290. , byte[] pHeap
  3291. , int nHeap
  3292. , int mnReq
  3293. , int mxReq
  3294. , byte[][] pScratch
  3295. , int szScratch
  3296. , int nScratch
  3297. , MemPage pPage
  3298. , int szPage
  3299. , int nPage
  3300. , int mxParserStack
  3301. , bool sharedCacheEnabled
  3302. , int isInit
  3303. , int inProgress
  3304. , int isMutexInit
  3305. , int isMallocInit
  3306. , int isPCacheInit
  3307. , sqlite3_mutex pInitMutex
  3308. , int nRefInitMutex
  3309. , dxLog xLog
  3310. , object pLogArg
  3311. , bool bLocaltimeFault
  3312. )
  3313. {
  3314. this.bMemstat = bMemstat != 0;
  3315. this.bCoreMutex = bCoreMutex != 0;
  3316. this.bOpenUri = bOpenUri;
  3317. this.bFullMutex = bFullMutex;
  3318. this.mxStrlen = mxStrlen;
  3319. this.szLookaside = szLookaside;
  3320. this.nLookaside = nLookaside;
  3321. this.m = m;
  3322. this.mutex = mutex;
  3323. this.pcache = pcache;
  3324. this.pHeap = pHeap;
  3325. this.nHeap = nHeap;
  3326. this.mnReq = mnReq;
  3327. this.mxReq = mxReq;
  3328. this.pScratch = pScratch;
  3329. this.szScratch = szScratch;
  3330. this.nScratch = nScratch;
  3331. this.pPage = pPage;
  3332. this.szPage = szPage;
  3333. this.nPage = nPage;
  3334. this.mxParserStack = mxParserStack;
  3335. this.sharedCacheEnabled = sharedCacheEnabled;
  3336. this.isInit = isInit;
  3337. this.inProgress = inProgress;
  3338. this.isMutexInit = isMutexInit;
  3339. this.isMallocInit = isMallocInit;
  3340. this.isPCacheInit = isPCacheInit;
  3341. this.pInitMutex = pInitMutex;
  3342. this.nRefInitMutex = nRefInitMutex;
  3343. this.xLog = xLog;
  3344. this.pLogArg = pLogArg;
  3345. this.bLocaltimeFault = bLocaltimeFault;
  3346. }
  3347. };
  3348. /*
  3349. ** Context pointer passed down through the tree-walk.
  3350. */
  3351. public class Walker
  3352. {
  3353. public dxExprCallback xExprCallback; //)(Walker*, Expr); /* Callback for expressions */
  3354. public dxSelectCallback xSelectCallback; //)(Walker*,Select); /* Callback for SELECTs */
  3355. public Parse pParse; /* Parser context. */
  3356. public struct uw
  3357. { /* Extra data for callback */
  3358. public NameContext pNC; /* Naming context */
  3359. public int i; /* Integer value */
  3360. }
  3361. public uw u;
  3362. };
  3363. /* Forward declarations */
  3364. //int sqlite3WalkExpr(Walker*, Expr);
  3365. //int sqlite3WalkExprList(Walker*, ExprList);
  3366. //int sqlite3WalkSelect(Walker*, Select);
  3367. //int sqlite3WalkSelectExpr(Walker*, Select);
  3368. //int sqlite3WalkSelectFrom(Walker*, Select);
  3369. /*
  3370. ** Return code from the parse-tree walking primitives and their
  3371. ** callbacks.
  3372. */
  3373. //#define WRC_Continue 0 /* Continue down into children */
  3374. //#define WRC_Prune 1 /* Omit children but continue walking siblings */
  3375. //#define WRC_Abort 2 /* Abandon the tree walk */
  3376. const int WRC_Continue = 0;
  3377. const int WRC_Prune = 1;
  3378. const int WRC_Abort = 2;
  3379. /*
  3380. ** Assuming zIn points to the first byte of a UTF-8 character,
  3381. ** advance zIn to point to the first byte of the next UTF-8 character.
  3382. */
  3383. //#define SQLITE_SKIP_UTF8(zIn) { \
  3384. // if( (*(zIn++))>=0xc0 ){ \
  3385. // while( (*zIn & 0xc0)==0x80 ){ zIn++; } \
  3386. // } \
  3387. //}
  3388. static void SQLITE_SKIP_UTF8( string zIn, ref int iz )
  3389. {
  3390. iz++;
  3391. if ( iz < zIn.Length && zIn[iz - 1] >= 0xC0 )
  3392. {
  3393. while ( iz < zIn.Length && ( zIn[iz] & 0xC0 ) == 0x80 )
  3394. {
  3395. iz++;
  3396. }
  3397. }
  3398. }
  3399. static void SQLITE_SKIP_UTF8(
  3400. byte[] zIn, ref int iz )
  3401. {
  3402. iz++;
  3403. if ( iz < zIn.Length && zIn[iz - 1] >= 0xC0 )
  3404. {
  3405. while ( iz < zIn.Length && ( zIn[iz] & 0xC0 ) == 0x80 )
  3406. {
  3407. iz++;
  3408. }
  3409. }
  3410. }
  3411. /*
  3412. ** The SQLITE_*_BKPT macros are substitutes for the error codes with
  3413. ** the same name but without the _BKPT suffix. These macros invoke
  3414. ** routines that report the line-number on which the error originated
  3415. ** using sqlite3_log(). The routines also provide a convenient place
  3416. ** to set a debugger breakpoint.
  3417. */
  3418. //int sqlite3CorruptError(int);
  3419. //int sqlite3MisuseError(int);
  3420. //int sqlite3CantopenError(int);
  3421. #if DEBUG
  3422. //#define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__)
  3423. static int SQLITE_CORRUPT_BKPT()
  3424. {
  3425. return sqlite3CorruptError( 0 );
  3426. }
  3427. //#define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__)
  3428. static int SQLITE_MISUSE_BKPT()
  3429. {
  3430. return sqlite3MisuseError( 0 );
  3431. }
  3432. //#define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__)
  3433. static int SQLITE_CANTOPEN_BKPT()
  3434. {
  3435. return sqlite3CantopenError( 0 );
  3436. }
  3437. #else
  3438. static int SQLITE_CORRUPT_BKPT() {return SQLITE_CORRUPT;}
  3439. static int SQLITE_MISUSE_BKPT() {return SQLITE_MISUSE;}
  3440. static int SQLITE_CANTOPEN_BKPT() {return SQLITE_CANTOPEN;}
  3441. #endif
  3442. /*
  3443. ** FTS4 is really an extension for FTS3. It is enabled using the
  3444. ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also all
  3445. ** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3.
  3446. */
  3447. //#if (SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
  3448. //# define SQLITE_ENABLE_FTS3
  3449. //#endif
  3450. /*
  3451. ** The ctype.h header is needed for non-ASCII systems. It is also
  3452. ** needed by FTS3 when FTS3 is included in the amalgamation.
  3453. */
  3454. //#if !defined(SQLITE_ASCII) || \
  3455. // (defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_AMALGAMATION))
  3456. //# include <ctype.h>
  3457. //#endif
  3458. /*
  3459. ** The following macros mimic the standard library functions toupper(),
  3460. ** isspace(), isalnum(), isdigit() and isxdigit(), respectively. The
  3461. ** sqlite versions only work for ASCII characters, regardless of locale.
  3462. */
  3463. #if SQLITE_ASCII
  3464. //# define sqlite3Toupper(x) ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20))
  3465. //# define sqlite3Isspace(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x01)
  3466. static bool sqlite3Isspace( byte x )
  3467. {
  3468. return ( sqlite3CtypeMap[(byte)( x )] & 0x01 ) != 0;
  3469. }
  3470. static bool sqlite3Isspace( char x )
  3471. {
  3472. return x < 256 && ( sqlite3CtypeMap[(byte)( x )] & 0x01 ) != 0;
  3473. }
  3474. //# define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
  3475. static bool sqlite3Isalnum( byte x )
  3476. {
  3477. return ( sqlite3CtypeMap[(byte)( x )] & 0x06 ) != 0;
  3478. }
  3479. static bool sqlite3Isalnum( char x )
  3480. {
  3481. return x < 256 && ( sqlite3CtypeMap[(byte)( x )] & 0x06 ) != 0;
  3482. }
  3483. //# define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
  3484. //# define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
  3485. static bool sqlite3Isdigit( byte x )
  3486. {
  3487. return ( sqlite3CtypeMap[( (byte)x )] & 0x04 ) != 0;
  3488. }
  3489. static bool sqlite3Isdigit( char x )
  3490. {
  3491. return x < 256 && ( sqlite3CtypeMap[( (byte)x )] & 0x04 ) != 0;
  3492. }
  3493. //# define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
  3494. static bool sqlite3Isxdigit( byte x )
  3495. {
  3496. return ( sqlite3CtypeMap[( (byte)x )] & 0x08 ) != 0;
  3497. }
  3498. static bool sqlite3Isxdigit( char x )
  3499. {
  3500. return x < 256 && ( sqlite3CtypeMap[( (byte)x )] & 0x08 ) != 0;
  3501. }
  3502. //# define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
  3503. #else
  3504. //# define sqlite3Toupper(x) toupper((unsigned char)(x))
  3505. //# define sqlite3Isspace(x) isspace((unsigned char)(x))
  3506. //# define sqlite3Isalnum(x) isalnum((unsigned char)(x))
  3507. //# define sqlite3Isalpha(x) isalpha((unsigned char)(x))
  3508. //# define sqlite3Isdigit(x) isdigit((unsigned char)(x))
  3509. //# define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
  3510. //# define sqlite3Tolower(x) tolower((unsigned char)(x))
  3511. #endif
  3512. /*
  3513. ** Internal function prototypes
  3514. */
  3515. //int sqlite3StrICmp(string , string );
  3516. //int sqlite3Strlen30(const char);
  3517. //#define sqlite3StrNICmp sqlite3_strnicmp
  3518. //int sqlite3MallocInit(void);
  3519. //void sqlite3MallocEnd(void);
  3520. //void *sqlite3Malloc(int);
  3521. //void *sqlite3MallocZero(int);
  3522. //void *sqlite3DbMallocZero(sqlite3*, int);
  3523. //void *sqlite3DbMallocRaw(sqlite3*, int);
  3524. //char *sqlite3DbStrDup(sqlite3*,const char);
  3525. //char *sqlite3DbStrNDup(sqlite3*,const char*, int);
  3526. //void *sqlite3Realloc(void*, int);
  3527. //void *sqlite3DbReallocOrFree(sqlite3 *, object *, int);
  3528. //void *sqlite3DbRealloc(sqlite3 *, object *, int);
  3529. //void sqlite3DbFree(sqlite3*, void);
  3530. //int sqlite3MallocSize(void);
  3531. //int sqlite3DbMallocSize(sqlite3*, void);
  3532. //void *sqlite3ScratchMalloc(int);
  3533. //void //sqlite3ScratchFree(void);
  3534. //void *sqlite3PageMalloc(int);
  3535. //void sqlite3PageFree(void);
  3536. //void sqlite3MemSetDefault(void);
  3537. //void sqlite3BenignMallocHooks(void ()(void), object ()(void));
  3538. //int sqlite3HeapNearlyFull(void);
  3539. /*
  3540. ** On systems with ample stack space and that support alloca(), make
  3541. ** use of alloca() to obtain space for large automatic objects. By default,
  3542. ** obtain space from malloc().
  3543. **
  3544. ** The alloca() routine never returns NULL. This will cause code paths
  3545. ** that deal with sqlite3StackAlloc() failures to be unreachable.
  3546. */
  3547. #if SQLITE_USE_ALLOCA
  3548. //# define sqlite3StackAllocRaw(D,N) alloca(N)
  3549. //# define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N)
  3550. //# define sqlite3StackFree(D,P)
  3551. #else
  3552. #if FALSE
  3553. //# define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N)
  3554. static void sqlite3StackAllocRaw( sqlite3 D, int N ) { sqlite3DbMallocRaw( D, N ); }
  3555. //# define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N)
  3556. static void sqlite3StackAllocZero( sqlite3 D, int N ) { sqlite3DbMallocZero( D, N ); }
  3557. //# define sqlite3StackFree(D,P) sqlite3DbFree(D,P)
  3558. static void sqlite3StackFree( sqlite3 D, object P ) {sqlite3DbFree( D, P ); }
  3559. #endif
  3560. #endif
  3561. #if SQLITE_ENABLE_MEMSYS3
  3562. const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
  3563. #endif
  3564. #if SQLITE_ENABLE_MEMSYS5
  3565. const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
  3566. #endif
  3567. #if !SQLITE_MUTEX_OMIT
  3568. // sqlite3_mutex_methods const *sqlite3DefaultMutex(void);
  3569. // sqlite3_mutex_methods const *sqlite3NoopMutex(void);
  3570. // sqlite3_mutex *sqlite3MutexAlloc(int);
  3571. // int sqlite3MutexInit(void);
  3572. // int sqlite3MutexEnd(void);
  3573. #endif
  3574. //int sqlite3StatusValue(int);
  3575. //void sqlite3StatusAdd(int, int);
  3576. //void sqlite3StatusSet(int, int);
  3577. //#if !SQLITE_OMIT_FLOATING_POINT
  3578. // int sqlite3IsNaN(double);
  3579. //#else
  3580. //# define sqlite3IsNaN(X) 0
  3581. //#endif
  3582. //void sqlite3VXPrintf(StrAccum*, int, const char*, va_list);
  3583. #if!SQLITE_OMIT_TRACE
  3584. //void sqlite3XPrintf(StrAccum*, const char*, ...);
  3585. #endif
  3586. //char *sqlite3MPrintf(sqlite3*,const char*, ...);
  3587. //char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
  3588. //char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
  3589. #if SQLITE_TEST || SQLITE_DEBUG
  3590. // void sqlite3DebugPrintf(const char*, ...);
  3591. #endif
  3592. #if SQLITE_TEST
  3593. // void *sqlite3TestTextToPtr(const char);
  3594. #endif
  3595. //void sqlite3SetString(char **, sqlite3*, const char*, ...);
  3596. //void sqlite3ErrorMsg(Parse*, const char*, ...);
  3597. //int sqlite3Dequote(char);
  3598. //int sqlite3KeywordCode(const unsigned char*, int);
  3599. //int sqlite3RunParser(Parse*, const char*, char *);
  3600. //void sqlite3FinishCoding(Parse);
  3601. //int sqlite3GetTempReg(Parse);
  3602. //void sqlite3ReleaseTempReg(Parse*,int);
  3603. //int sqlite3GetTempRange(Parse*,int);
  3604. //void sqlite3ReleaseTempRange(Parse*,int,int);
  3605. //Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
  3606. //Expr *sqlite3Expr(sqlite3*,int,const char);
  3607. //void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr);
  3608. //Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token);
  3609. //Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr);
  3610. //Expr *sqlite3ExprFunction(Parse*,ExprList*, Token);
  3611. //void sqlite3ExprAssignVarNumber(Parse*, Expr);
  3612. //void sqlite3ExprDelete(sqlite3*, Expr);
  3613. //ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr);
  3614. //void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
  3615. //void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan);
  3616. //void sqlite3ExprListDelete(sqlite3*, ExprList);
  3617. //int sqlite3Init(sqlite3*, char*);
  3618. //int sqlite3InitCallback(void*, int, char**, char*);
  3619. //void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
  3620. //void sqlite3ResetInternalSchema(sqlite3*, int);
  3621. //void sqlite3BeginParse(Parse*,int);
  3622. //void sqlite3CommitInternalChanges(sqlite3);
  3623. //Table *sqlite3ResultSetOfSelect(Parse*,Select);
  3624. //void sqlite3OpenMasterTable(Parse *, int);
  3625. //void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
  3626. //void sqlite3AddColumn(Parse*,Token);
  3627. //void sqlite3AddNotNull(Parse*, int);
  3628. //void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
  3629. //void sqlite3AddCheckConstraint(Parse*, Expr);
  3630. //void sqlite3AddColumnType(Parse*,Token);
  3631. //void sqlite3AddDefaultValue(Parse*,ExprSpan);
  3632. //void sqlite3AddCollateType(Parse*, Token);
  3633. //void sqlite3EndTable(Parse*,Token*,Token*,Select);
  3634. //int sqlite3ParseUri(const char*,const char*,unsigned int*,
  3635. // sqlite3_vfs**,char**,char *);
  3636. //Bitvec *sqlite3BitvecCreate(u32);
  3637. //int sqlite3BitvecTest(Bitvec*, u32);
  3638. //int sqlite3BitvecSet(Bitvec*, u32);
  3639. //void sqlite3BitvecClear(Bitvec*, u32, void);
  3640. //void sqlite3BitvecDestroy(Bitvec);
  3641. //u32 sqlite3BitvecSize(Bitvec);
  3642. //int sqlite3BitvecBuiltinTest(int,int);
  3643. //RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
  3644. //void sqlite3RowSetClear(RowSet);
  3645. //void sqlite3RowSetInsert(RowSet*, i64);
  3646. //int sqlite3RowSetTest(RowSet*, u8 iBatch, i64);
  3647. //int sqlite3RowSetNext(RowSet*, i64);
  3648. //void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
  3649. #if !SQLITE_OMIT_VIEW || !SQLITE_OMIT_VIRTUALTABLE
  3650. //int sqlite3ViewGetColumnNames(Parse*,Table);
  3651. #else
  3652. //# define sqlite3ViewGetColumnNames(A,B) 0
  3653. static int sqlite3ViewGetColumnNames( Parse A, Table B )
  3654. {
  3655. return 0;
  3656. }
  3657. #endif
  3658. //void sqlite3DropTable(Parse*, SrcList*, int, int);
  3659. //void sqlite3DeleteTable(sqlite3*, Table);
  3660. //#if !SQLITE_OMIT_AUTOINCREMENT
  3661. // void sqlite3AutoincrementBegin(Parse *pParse);
  3662. // void sqlite3AutoincrementEnd(Parse *pParse);
  3663. //#else
  3664. //# define sqlite3AutoincrementBegin(X)
  3665. //# define sqlite3AutoincrementEnd(X)
  3666. //#endif
  3667. //void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
  3668. //void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int);
  3669. //IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token);
  3670. //int sqlite3IdListIndex(IdList*,const char);
  3671. //SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
  3672. //SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token);
  3673. //SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
  3674. // Token*, Select*, Expr*, IdList);
  3675. //void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token );
  3676. //int sqlite3IndexedByLookup(Parse *, struct SrcList_item );
  3677. //void sqlite3SrcListShiftJoinType(SrcList);
  3678. //void sqlite3SrcListAssignCursors(Parse*, SrcList);
  3679. //void sqlite3IdListDelete(sqlite3*, IdList);
  3680. //void sqlite3SrcListDelete(sqlite3*, SrcList);
  3681. //Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
  3682. // Token*, int, int);
  3683. //void sqlite3DropIndex(Parse*, SrcList*, int);
  3684. //int sqlite3Select(Parse*, Select*, SelectDest);
  3685. //Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
  3686. // Expr*,ExprList*,int,Expr*,Expr);
  3687. //void sqlite3SelectDelete(sqlite3*, Select);
  3688. //Table *sqlite3SrcListLookup(Parse*, SrcList);
  3689. //int sqlite3IsReadOnly(Parse*, Table*, int);
  3690. //void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
  3691. #if (SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !(SQLITE_OMIT_SUBQUERY)
  3692. //Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char );
  3693. #endif
  3694. //void sqlite3DeleteFrom(Parse*, SrcList*, Expr);
  3695. //void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
  3696. //WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u16);
  3697. //void sqlite3WhereEnd(WhereInfo);
  3698. //int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int);
  3699. //void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
  3700. //void sqlite3ExprCodeMove(Parse*, int, int, int);
  3701. //void sqlite3ExprCodeCopy(Parse*, int, int, int);
  3702. //void sqlite3ExprCacheStore(Parse*, int, int, int);
  3703. //void sqlite3ExprCachePush(Parse);
  3704. //void sqlite3ExprCachePop(Parse*, int);
  3705. //void sqlite3ExprCacheRemove(Parse*, int, int);
  3706. //void sqlite3ExprCacheClear(Parse);
  3707. //void sqlite3ExprCacheAffinityChange(Parse*, int, int);
  3708. //int sqlite3ExprCode(Parse*, Expr*, int);
  3709. //int sqlite3ExprCodeTemp(Parse*, Expr*, int);
  3710. //int sqlite3ExprCodeTarget(Parse*, Expr*, int);
  3711. //int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
  3712. //void sqlite3ExprCodeConstants(Parse*, Expr);
  3713. //int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
  3714. //void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
  3715. //void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
  3716. //Table *sqlite3FindTable(sqlite3*,const char*, const char);
  3717. //Table *sqlite3LocateTable(Parse*,int isView,const char*, const char);
  3718. //Index *sqlite3FindIndex(sqlite3*,const char*, const char);
  3719. //void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char);
  3720. //void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char);
  3721. //void sqlite3Vacuum(Parse);
  3722. //int sqlite3RunVacuum(char**, sqlite3);
  3723. //char *sqlite3NameFromToken(sqlite3*, Token);
  3724. //int sqlite3ExprCompare(Expr*, Expr);
  3725. //int sqlite3ExprListCompare(ExprList*, ExprList);
  3726. //void sqlite3ExprAnalyzeAggregates(NameContext*, Expr);
  3727. //void sqlite3ExprAnalyzeAggList(NameContext*,ExprList);
  3728. //Vdbe *sqlite3GetVdbe(Parse);
  3729. //void sqlite3PrngSaveState(void);
  3730. //void sqlite3PrngRestoreState(void);
  3731. //void sqlite3PrngResetState(void);
  3732. //void sqlite3RollbackAll(sqlite3);
  3733. //void sqlite3CodeVerifySchema(Parse*, int);
  3734. //void sqlite3CodeVerifyNamedSchema(Parse*, string zDb);
  3735. //void sqlite3BeginTransaction(Parse*, int);
  3736. //void sqlite3CommitTransaction(Parse);
  3737. //void sqlite3RollbackTransaction(Parse);
  3738. //void sqlite3Savepoint(Parse*, int, Token);
  3739. //void sqlite3CloseSavepoints(sqlite3 );
  3740. //int sqlite3ExprIsConstant(Expr);
  3741. //int sqlite3ExprIsConstantNotJoin(Expr);
  3742. //int sqlite3ExprIsConstantOrFunction(Expr);
  3743. //int sqlite3ExprIsInteger(Expr*, int);
  3744. //int sqlite3ExprCanBeNull(const Expr);
  3745. //void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
  3746. //int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
  3747. //int sqlite3IsRowid(const char);
  3748. //void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int, Trigger *, int);
  3749. //void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int);
  3750. //int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int);
  3751. //void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int,
  3752. // int*,int,int,int,int,int);
  3753. //void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int);
  3754. //int sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
  3755. //void sqlite3BeginWriteOperation(Parse*, int, int);
  3756. //void sqlite3MultiWrite(Parse);
  3757. //void sqlite3MayAbort(Parse );
  3758. //void sqlite3HaltConstraint(Parse*, int, char*, int);
  3759. //Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
  3760. //ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
  3761. //SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
  3762. //IdList *sqlite3IdListDup(sqlite3*,IdList);
  3763. //Select *sqlite3SelectDup(sqlite3*,Select*,int);
  3764. //void sqlite3FuncDefInsert(FuncDefHash*, FuncDef);
  3765. //FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
  3766. //void sqlite3RegisterBuiltinFunctions(sqlite3);
  3767. //void sqlite3RegisterDateTimeFunctions(void);
  3768. //void sqlite3RegisterGlobalFunctions(void);
  3769. //int sqlite3SafetyCheckOk(sqlite3);
  3770. //int sqlite3SafetyCheckSickOrOk(sqlite3);
  3771. //void sqlite3ChangeCookie(Parse*, int);
  3772. #if !(SQLITE_OMIT_VIEW) && !(SQLITE_OMIT_TRIGGER)
  3773. //void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
  3774. #endif
  3775. #if !SQLITE_OMIT_TRIGGER
  3776. //void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
  3777. // Expr*,int, int);
  3778. //void sqlite3FinishTrigger(Parse*, TriggerStep*, Token);
  3779. //void sqlite3DropTrigger(Parse*, SrcList*, int);
  3780. //Trigger *sqlite3TriggersExist(Parse *, Table*, int, ExprList*, int *pMask);
  3781. //Trigger *sqlite3TriggerList(Parse *, Table );
  3782. // void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
  3783. // int, int, int);
  3784. //void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList);
  3785. //void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep);
  3786. //TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select);
  3787. //TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
  3788. // ExprList*,Select*,u8);
  3789. //TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8);
  3790. //TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr);
  3791. //void sqlite3DeleteTrigger(sqlite3*, Trigger);
  3792. //void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char);
  3793. // u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
  3794. //# define sqlite3ParseToplevel(p) ((p)->pToplevel ? (p)->pToplevel : (p))
  3795. static Parse sqlite3ParseToplevel( Parse p )
  3796. {
  3797. return p.pToplevel != null ? p.pToplevel : p;
  3798. }
  3799. #else
  3800. static void sqlite3BeginTrigger( Parse A, Token B, Token C, int D, int E, IdList F, SrcList G, Expr H, int I, int J )
  3801. {
  3802. }
  3803. static void sqlite3FinishTrigger( Parse P, TriggerStep TS, Token T )
  3804. {
  3805. }
  3806. static TriggerStep sqlite3TriggerSelectStep( sqlite3 A, Select B )
  3807. {
  3808. return null;
  3809. }
  3810. static TriggerStep sqlite3TriggerInsertStep( sqlite3 A, Token B, IdList C, ExprList D, Select E, u8 F )
  3811. {
  3812. return null;
  3813. }
  3814. static TriggerStep sqlite3TriggerInsertStep( sqlite3 A, Token B, IdList C, int D, Select E, u8 F )
  3815. {
  3816. return null;
  3817. }
  3818. static TriggerStep sqlite3TriggerInsertStep( sqlite3 A, Token B, IdList C, ExprList D, int E, u8 F )
  3819. {
  3820. return null;
  3821. }
  3822. static TriggerStep sqlite3TriggerUpdateStep( sqlite3 A, Token B, ExprList C, Expr D, u8 E )
  3823. {
  3824. return null;
  3825. }
  3826. static TriggerStep sqlite3TriggerDeleteStep( sqlite3 A, Token B, Expr C )
  3827. {
  3828. return null;
  3829. }
  3830. static u32 sqlite3TriggerColmask( Parse A, Trigger B, ExprList C, int D, int E, Table F, int G )
  3831. {
  3832. return 0;
  3833. }
  3834. //# define sqlite3TriggersExist(B,C,D,E,F) 0
  3835. static Trigger sqlite3TriggersExist( Parse B, Table C, int D, ExprList E, ref int F )
  3836. {
  3837. return null;
  3838. }
  3839. //# define sqlite3DeleteTrigger(A,B)
  3840. static void sqlite3DeleteTrigger( sqlite3 A, ref Trigger B )
  3841. {
  3842. }
  3843. static void sqlite3DeleteTriggerStep( sqlite3 A, ref TriggerStep B )
  3844. {
  3845. }
  3846. //# define sqlite3DropTriggerPtr(A,B)
  3847. static void sqlite3DropTriggerPtr( Parse A, Trigger B )
  3848. {
  3849. }
  3850. static void sqlite3DropTrigger( Parse A, SrcList B, int C )
  3851. {
  3852. }
  3853. //# define sqlite3UnlinkAndDeleteTrigger(A,B,C)
  3854. static void sqlite3UnlinkAndDeleteTrigger( sqlite3 A, int B, string C )
  3855. {
  3856. }
  3857. //# define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I)
  3858. static void sqlite3CodeRowTrigger( Parse A, Trigger B, int C, ExprList D, int E, Table F, int G, int H, int I )
  3859. {
  3860. }
  3861. //# define sqlite3CodeRowTriggerDirect(A,B,C,D,E,F)
  3862. static Trigger sqlite3TriggerList( Parse pParse, Table pTab )
  3863. {
  3864. return null;
  3865. } //# define sqlite3TriggerList(X, Y) 0
  3866. //# define sqlite3ParseToplevel(p) p
  3867. static Parse sqlite3ParseToplevel( Parse p )
  3868. {
  3869. return p;
  3870. }
  3871. //# define sqlite3TriggerOldmask(A,B,C,D,E,F) 0
  3872. static u32 sqlite3TriggerOldmask( Parse A, Trigger B, int C, ExprList D, Table E, int F )
  3873. {
  3874. return 0;
  3875. }
  3876. #endif
  3877. //int sqlite3JoinType(Parse*, Token*, Token*, Token);
  3878. //void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
  3879. //void sqlite3DeferForeignKey(Parse*, int);
  3880. #if !SQLITE_OMIT_AUTHORIZATION
  3881. void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList);
  3882. int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char);
  3883. void sqlite3AuthContextPush(Parse*, AuthContext*, const char);
  3884. void sqlite3AuthContextPop(AuthContext);
  3885. int sqlite3AuthReadCol(Parse*, string , string , int);
  3886. #else
  3887. //# define sqlite3AuthRead(a,b,c,d)
  3888. static void sqlite3AuthRead( Parse a, Expr b, Schema c, SrcList d )
  3889. {
  3890. }
  3891. //# define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK
  3892. static int sqlite3AuthCheck( Parse a, int b, string c, byte[] d, byte[] e )
  3893. {
  3894. return SQLITE_OK;
  3895. }
  3896. //# define sqlite3AuthContextPush(a,b,c)
  3897. static void sqlite3AuthContextPush( Parse a, AuthContext b, string c )
  3898. {
  3899. }
  3900. //# define sqlite3AuthContextPop(a) ((void)(a))
  3901. static Parse sqlite3AuthContextPop( Parse a )
  3902. {
  3903. return a;
  3904. }
  3905. #endif
  3906. //void sqlite3Attach(Parse*, Expr*, Expr*, Expr);
  3907. //void sqlite3Detach(Parse*, Expr);
  3908. //int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token);
  3909. //int sqlite3FixSrcList(DbFixer*, SrcList);
  3910. //int sqlite3FixSelect(DbFixer*, Select);
  3911. //int sqlite3FixExpr(DbFixer*, Expr);
  3912. //int sqlite3FixExprList(DbFixer*, ExprList);
  3913. //int sqlite3FixTriggerStep(DbFixer*, TriggerStep);
  3914. //sqlite3AtoF(string z, double*, int, u8)
  3915. //int sqlite3GetInt32(string , int);
  3916. //int sqlite3Atoi(string );
  3917. //int sqlite3Utf16ByteLen(const void pData, int nChar);
  3918. //int sqlite3Utf8CharLen(const char pData, int nByte);
  3919. //u32 sqlite3Utf8Read(const u8*, const u8*);
  3920. /*
  3921. ** Routines to read and write variable-length integers. These used to
  3922. ** be defined locally, but now we use the varint routines in the util.c
  3923. ** file. Code should use the MACRO forms below, as the Varint32 versions
  3924. ** are coded to assume the single byte case is already handled (which
  3925. ** the MACRO form does).
  3926. */
  3927. //int sqlite3PutVarint(unsigned char*, u64);
  3928. //int putVarint32(unsigned char*, u32);
  3929. //u8 sqlite3GetVarint(const unsigned char *, u64 );
  3930. //u8 sqlite3GetVarint32(const unsigned char *, u32 );
  3931. //int sqlite3VarintLen(u64 v);
  3932. /*
  3933. ** The header of a record consists of a sequence variable-length integers.
  3934. ** These integers are almost always small and are encoded as a single byte.
  3935. ** The following macros take advantage this fact to provide a fast encode
  3936. ** and decode of the integers in a record header. It is faster for the common
  3937. ** case where the integer is a single byte. It is a little slower when the
  3938. ** integer is two or more bytes. But overall it is faster.
  3939. **
  3940. ** The following expressions are equivalent:
  3941. **
  3942. ** x = sqlite3GetVarint32( A, B );
  3943. ** x = putVarint32( A, B );
  3944. **
  3945. ** x = getVarint32( A, B );
  3946. ** x = putVarint32( A, B );
  3947. **
  3948. */
  3949. //#define getVarint32(A,B) (u8)((*(A)<(u8)0x80) ? ((B) = (u32)*(A)),1 : sqlite3GetVarint32((A), (u32 )&(B)))
  3950. //#define putVarint32(A,B) (u8)(((u32)(B)<(u32)0x80) ? (*(A) = (unsigned char)(B)),1 : sqlite3PutVarint32((A), (B)))
  3951. //#define getVarint sqlite3GetVarint
  3952. //#define putVarint sqlite3PutVarint
  3953. //string sqlite3IndexAffinityStr(Vdbe *, Index );
  3954. //void sqlite3TableAffinityStr(Vdbe *, Table );
  3955. //char sqlite3CompareAffinity(Expr pExpr, char aff2);
  3956. //int sqlite3IndexAffinityOk(Expr pExpr, char idx_affinity);
  3957. //char sqlite3ExprAffinity(Expr pExpr);
  3958. //int sqlite3Atoi64(const char*, i64*, int, u8);
  3959. //void sqlite3Error(sqlite3*, int, const char*,...);
  3960. //void *sqlite3HexToBlob(sqlite3*, string z, int n);
  3961. //u8 sqlite3HexToInt(int h);
  3962. //int sqlite3TwoPartName(Parse *, Token *, Token *, Token *);
  3963. //string sqlite3ErrStr(int);
  3964. //int sqlite3ReadSchema(Parse pParse);
  3965. //CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
  3966. //CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
  3967. //CollSeq *sqlite3ExprCollSeq(Parse pParse, Expr pExpr);
  3968. //Expr *sqlite3ExprSetColl(Expr*, CollSeq);
  3969. //Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token);
  3970. //int sqlite3CheckCollSeq(Parse *, CollSeq );
  3971. //int sqlite3CheckObjectName(Parse *, string );
  3972. //void sqlite3VdbeSetChanges(sqlite3 *, int);
  3973. //int sqlite3AddInt64(i64*,i64);
  3974. //int sqlite3SubInt64(i64*,i64);
  3975. //int sqlite3MulInt64(i64*,i64);
  3976. //int sqlite3AbsInt32(int);
  3977. #if SQLITE_ENABLE_8_3_NAMES
  3978. //void sqlite3FileSuffix3(const char*, char);
  3979. #else
  3980. //# define sqlite3FileSuffix3(X,Y)
  3981. static void sqlite3FileSuffix3(string X, string Y){}
  3982. #endif
  3983. //u8 sqlite3GetBoolean(string z);
  3984. //const void *sqlite3ValueText(sqlite3_value*, u8);
  3985. //int sqlite3ValueBytes(sqlite3_value*, u8);
  3986. //void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
  3987. // // void()(void));
  3988. //void sqlite3ValueFree(sqlite3_value);
  3989. //sqlite3_value *sqlite3ValueNew(sqlite3 );
  3990. //char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
  3991. //#if SQLITE_ENABLE_STAT2
  3992. //char *sqlite3Utf8to16(sqlite3 *, u8, char *, int, int );
  3993. //#endif
  3994. //int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value *);
  3995. //void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
  3996. //#if !SQLITE_AMALGAMATION
  3997. //extern const unsigned char sqlite3OpcodeProperty[];
  3998. //extern const unsigned char sqlite3UpperToLower[];
  3999. //extern const unsigned char sqlite3CtypeMap[];
  4000. //extern const Token sqlite3IntTokens[];
  4001. //extern SQLITE_WSD struct Sqlite3Config sqlite3Config;
  4002. //extern SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;
  4003. //#if !SQLITE_OMIT_WSD
  4004. //extern int sqlite3PendingByte;
  4005. //#endif
  4006. //#endif
  4007. //void sqlite3RootPageMoved(sqlite3*, int, int, int);
  4008. //void sqlite3Reindex(Parse*, Token*, Token);
  4009. //void sqlite3AlterFunctions(void);
  4010. //void sqlite3AlterRenameTable(Parse*, SrcList*, Token);
  4011. //int sqlite3GetToken(const unsigned char *, int );
  4012. //void sqlite3NestedParse(Parse*, const char*, ...);
  4013. //void sqlite3ExpirePreparedStatements(sqlite3);
  4014. //int sqlite3CodeSubselect(Parse *, Expr *, int, int);
  4015. //void sqlite3SelectPrep(Parse*, Select*, NameContext);
  4016. //int sqlite3ResolveExprNames(NameContext*, Expr);
  4017. //void sqlite3ResolveSelectNames(Parse*, Select*, NameContext);
  4018. //int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char);
  4019. //void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
  4020. //void sqlite3AlterFinishAddColumn(Parse *, Token );
  4021. //void sqlite3AlterBeginAddColumn(Parse *, SrcList );
  4022. //CollSeq *sqlite3GetCollSeq(sqlite3*, u8, CollSeq *, const char);
  4023. //char sqlite3AffinityType(const char);
  4024. //void sqlite3Analyze(Parse*, Token*, Token);
  4025. //int sqlite3InvokeBusyHandler(BusyHandler);
  4026. //int sqlite3FindDb(sqlite3*, Token);
  4027. //int sqlite3FindDbName(sqlite3 *, string );
  4028. //int sqlite3AnalysisLoad(sqlite3*,int iDB);
  4029. //void sqlite3DeleteIndexSamples(sqlite3*,Index);
  4030. //void sqlite3DefaultRowEst(Index);
  4031. //void sqlite3RegisterLikeFunctions(sqlite3*, int);
  4032. //int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char);
  4033. //void sqlite3MinimumFileFormat(Parse*, int, int);
  4034. //void sqlite3SchemaClear(void );
  4035. //Schema *sqlite3SchemaGet(sqlite3 *, Btree );
  4036. //int sqlite3SchemaToIndex(sqlite3 db, Schema );
  4037. //KeyInfo *sqlite3IndexKeyinfo(Parse *, Index );
  4038. //int sqlite3CreateFunc(sqlite3 *, string , int, int, object *,
  4039. // void ()(sqlite3_context*,int,sqlite3_value *),
  4040. // void ()(sqlite3_context*,int,sqlite3_value *), object ()(sqlite3_context),
  4041. // FuncDestructor *pDestructor
  4042. //);
  4043. //int sqlite3ApiExit(sqlite3 db, int);
  4044. //int sqlite3OpenTempDatabase(Parse );
  4045. //void sqlite3StrAccumAppend(StrAccum*,const char*,int);
  4046. //char *sqlite3StrAccumFinish(StrAccum);
  4047. //void sqlite3StrAccumReset(StrAccum);
  4048. //void sqlite3SelectDestInit(SelectDest*,int,int);
  4049. //Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
  4050. //void sqlite3BackupRestart(sqlite3_backup );
  4051. //void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 );
  4052. /*
  4053. ** The interface to the LEMON-generated parser
  4054. */
  4055. //void *sqlite3ParserAlloc(void*()(size_t));
  4056. //void sqlite3ParserFree(void*, void()(void));
  4057. //void sqlite3Parser(void*, int, Token, Parse);
  4058. #if YYTRACKMAXSTACKDEPTH
  4059. int sqlite3ParserStackPeak(void);
  4060. #endif
  4061. //void sqlite3AutoLoadExtensions(sqlite3);
  4062. #if !SQLITE_OMIT_LOAD_EXTENSION
  4063. //void sqlite3CloseExtensions(sqlite3);
  4064. #else
  4065. //# define sqlite3CloseExtensions(X)
  4066. #endif
  4067. #if !SQLITE_OMIT_SHARED_CACHE
  4068. //void sqlite3TableLock(Parse *, int, int, u8, string );
  4069. #else
  4070. //#define sqlite3TableLock(v,w,x,y,z)
  4071. static void sqlite3TableLock( Parse p, int p1, int p2, u8 p3, byte[] p4 )
  4072. {
  4073. }
  4074. static void sqlite3TableLock( Parse p, int p1, int p2, u8 p3, string p4 )
  4075. {
  4076. }
  4077. #endif
  4078. #if SQLITE_TEST
  4079. ///int sqlite3Utf8To8(unsigned char);
  4080. #endif
  4081. #if SQLITE_OMIT_VIRTUALTABLE
  4082. //# define sqlite3VtabClear(D, Y)
  4083. static void sqlite3VtabClear( sqlite3 db, Table Y )
  4084. {
  4085. }
  4086. //# define sqlite3VtabSync(X,Y) SQLITE_OK
  4087. static int sqlite3VtabSync( sqlite3 X, ref string Y )
  4088. {
  4089. return SQLITE_OK;
  4090. }
  4091. //# define sqlite3VtabRollback(X)
  4092. static void sqlite3VtabRollback( sqlite3 X )
  4093. {
  4094. }
  4095. //# define sqlite3VtabCommit(X)
  4096. static void sqlite3VtabCommit( sqlite3 X )
  4097. {
  4098. }
  4099. //# define sqlite3VtabLock(X)
  4100. static void sqlite3VtabLock( VTable X )
  4101. {
  4102. }
  4103. //# define sqlite3VtabUnlock(X)
  4104. static void sqlite3VtabUnlock( VTable X )
  4105. {
  4106. }
  4107. //# define sqlite3VtabUnlockList(X)
  4108. static void sqlite3VtabUnlockList( sqlite3 X )
  4109. {
  4110. }
  4111. //# define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
  4112. static int sqlite3VtabSavepoint( sqlite3 X, int Y, int Z )
  4113. {
  4114. return SQLITE_OK;
  4115. }
  4116. //# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
  4117. static bool sqlite3VtabInSync( sqlite3 db )
  4118. {
  4119. return false;
  4120. }
  4121. //# define sqlite3VtabArgExtend(P, T)
  4122. static void sqlite3VtabArgExtend( Parse P, Token T )
  4123. {
  4124. }
  4125. //# define sqlite3VtabArgInit(P)
  4126. static void sqlite3VtabArgInit( Parse P )
  4127. {
  4128. }
  4129. //# define sqlite3VtabBeginParse(P, T, T1, T2);
  4130. static void sqlite3VtabBeginParse( Parse P, Token T, Token T1, Token T2 )
  4131. {
  4132. }
  4133. //# define sqlite3VtabFinishParse(P, T)
  4134. static void sqlite3VtabFinishParse<T>( Parse P, T t )
  4135. {
  4136. }
  4137. static VTable sqlite3GetVTable( sqlite3 db, Table T )
  4138. {
  4139. return null;
  4140. }
  4141. #else
  4142. //void sqlite3VtabClear(sqlite3 db, Table);
  4143. //int sqlite3VtabSync(sqlite3 db, int rc);
  4144. //int sqlite3VtabRollback(sqlite3 db);
  4145. //int sqlite3VtabCommit(sqlite3 db);
  4146. //void sqlite3VtabLock(VTable );
  4147. //void sqlite3VtabUnlock(VTable );
  4148. //void sqlite3VtabUnlockList(sqlite3);
  4149. //int sqlite3VtabSavepoint(sqlite3 *, int, int);
  4150. //# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
  4151. static bool sqlite3VtabInSync( sqlite3 db )
  4152. {
  4153. return ( db.nVTrans > 0 && db.aVTrans == null );
  4154. }
  4155. #endif
  4156. //void sqlite3VtabMakeWritable(Parse*,Table);
  4157. //void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token);
  4158. //void sqlite3VtabFinishParse(Parse*, Token);
  4159. //void sqlite3VtabArgInit(Parse);
  4160. //void sqlite3VtabArgExtend(Parse*, Token);
  4161. //int sqlite3VtabCallCreate(sqlite3*, int, string , char *);
  4162. //int sqlite3VtabCallConnect(Parse*, Table);
  4163. //int sqlite3VtabCallDestroy(sqlite3*, int, string );
  4164. //int sqlite3VtabBegin(sqlite3 *, VTable );
  4165. //FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr);
  4166. //void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value*);
  4167. //int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
  4168. //int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt );
  4169. //int sqlite3Reprepare(Vdbe);
  4170. //void sqlite3ExprListCheckLength(Parse*, ExprList*, const char);
  4171. //CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr );
  4172. //int sqlite3TempInMemory(const sqlite3);
  4173. //VTable *sqlite3GetVTable(sqlite3*, Table);
  4174. //string sqlite3JournalModename(int);
  4175. //int sqlite3Checkpoint(sqlite3*, int, int, int*, int);
  4176. //int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int);
  4177. /* Declarations for functions in fkey.c. All of these are replaced by
  4178. ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign
  4179. ** key functionality is available. If OMIT_TRIGGER is defined but
  4180. ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
  4181. ** this case foreign keys are parsed, but no other functionality is
  4182. ** provided (enforcement of FK constraints requires the triggers sub-system).
  4183. */
  4184. #if !(SQLITE_OMIT_FOREIGN_KEY) && !(SQLITE_OMIT_TRIGGER)
  4185. //void sqlite3FkCheck(Parse*, Table*, int, int);
  4186. //void sqlite3FkDropTable(Parse*, SrcList *, Table);
  4187. //void sqlite3FkActions(Parse*, Table*, ExprList*, int);
  4188. //int sqlite3FkRequired(Parse*, Table*, int*, int);
  4189. //u32 sqlite3FkOldmask(Parse*, Table);
  4190. //FKey *sqlite3FkReferences(vtable );
  4191. #else
  4192. //#define sqlite3FkActions(a,b,c,d)
  4193. static void sqlite3FkActions( Parse a, Table b, ExprList c, int d ) { }
  4194. //#define sqlite3FkCheck(a,b,c,d)
  4195. static void sqlite3FkCheck( Parse a, Table b, int c, int d ) { }
  4196. //#define sqlite3FkDropTable(a,b,c)
  4197. static void sqlite3FkDropTable( Parse a, SrcList b, Table c ) { }
  4198. //#define sqlite3FkOldmask(a,b) 0
  4199. static u32 sqlite3FkOldmask( Parse a, Table b ) { return 0; }
  4200. //#define sqlite3FkRequired(a,b,c,d) 0
  4201. static int sqlite3FkRequired( Parse a, Table b, int[] c, int d ) { return 0; }
  4202. #endif
  4203. #if !SQLITE_OMIT_FOREIGN_KEY
  4204. //void sqlite3FkDelete(sqlite3 *, Table);
  4205. #else
  4206. //#define sqlite3FkDelete(a, b)
  4207. static void sqlite3FkDelete(sqlite3 a, Table b) {}
  4208. #endif
  4209. /*
  4210. ** Available fault injectors. Should be numbered beginning with 0.
  4211. */
  4212. const int SQLITE_FAULTINJECTOR_MALLOC = 0;//#define SQLITE_FAULTINJECTOR_MALLOC 0
  4213. const int SQLITE_FAULTINJECTOR_COUNT = 1;//#define SQLITE_FAULTINJECTOR_COUNT 1
  4214. /*
  4215. ** The interface to the code in fault.c used for identifying "benign"
  4216. ** malloc failures. This is only present if SQLITE_OMIT_BUILTIN_TEST
  4217. ** is not defined.
  4218. */
  4219. #if !SQLITE_OMIT_BUILTIN_TEST
  4220. //void sqlite3BeginBenignMalloc(void);
  4221. //void sqlite3EndBenignMalloc(void);
  4222. #else
  4223. //#define sqlite3BeginBenignMalloc()
  4224. //#define sqlite3EndBenignMalloc()
  4225. #endif
  4226. const int IN_INDEX_ROWID = 1;//#define IN_INDEX_ROWID 1
  4227. const int IN_INDEX_EPH = 2;//#define IN_INDEX_EPH 2
  4228. const int IN_INDEX_INDEX = 3;//#define IN_INDEX_INDEX 3
  4229. //int sqlite3FindInIndex(Parse *, Expr *, int);
  4230. #if SQLITE_ENABLE_ATOMIC_WRITE
  4231. // int sqlite3JournalOpen(sqlite3_vfs *, string , sqlite3_file *, int, int);
  4232. // int sqlite3JournalSize(sqlite3_vfs );
  4233. // int sqlite3JournalCreate(sqlite3_file );
  4234. #else
  4235. //#define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
  4236. static int sqlite3JournalSize( sqlite3_vfs pVfs )
  4237. {
  4238. return pVfs.szOsFile;
  4239. }
  4240. #endif
  4241. //void sqlite3MemJournalOpen(sqlite3_file );
  4242. //int sqlite3MemJournalSize(void);
  4243. //int sqlite3IsMemJournal(sqlite3_file );
  4244. #if SQLITE_MAX_EXPR_DEPTH//>0
  4245. // void sqlite3ExprSetHeight(Parse pParse, Expr p);
  4246. // int sqlite3SelectExprHeight(Select );
  4247. //int sqlite3ExprCheckHeight(Parse*, int);
  4248. #else
  4249. //#define sqlite3ExprSetHeight(x,y)
  4250. //#define sqlite3SelectExprHeight(x) 0
  4251. //#define sqlite3ExprCheckHeight(x,y)
  4252. #endif
  4253. //u32 sqlite3Get4byte(const u8);
  4254. //void sqlite3sqlite3Put4byte(u8*, u32);
  4255. #if SQLITE_ENABLE_UNLOCK_NOTIFY
  4256. void sqlite3ConnectionBlocked(sqlite3 *, sqlite3 );
  4257. void sqlite3ConnectionUnlocked(sqlite3 db);
  4258. void sqlite3ConnectionClosed(sqlite3 db);
  4259. #else
  4260. static void sqlite3ConnectionBlocked( sqlite3 x, sqlite3 y )
  4261. {
  4262. } //#define sqlite3ConnectionBlocked(x,y)
  4263. static void sqlite3ConnectionUnlocked( sqlite3 x )
  4264. {
  4265. } //#define sqlite3ConnectionUnlocked(x)
  4266. static void sqlite3ConnectionClosed( sqlite3 x )
  4267. {
  4268. } //#define sqlite3ConnectionClosed(x)
  4269. #endif
  4270. #if SQLITE_DEBUG
  4271. // void sqlite3ParserTrace(FILE*, char );
  4272. #endif
  4273. /*
  4274. ** If the SQLITE_ENABLE IOTRACE exists then the global variable
  4275. ** sqlite3IoTrace is a pointer to a printf-like routine used to
  4276. ** print I/O tracing messages.
  4277. */
  4278. #if SQLITE_ENABLE_IOTRACE
  4279. static bool SQLite3IoTrace = false;
  4280. //#define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; }
  4281. static void IOTRACE( string X, params object[] ap ) { if ( SQLite3IoTrace ) { printf( X, ap ); } }
  4282. // void sqlite3VdbeIOTraceSql(Vdbe);
  4283. //SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...);
  4284. #else
  4285. //#define IOTRACE(A)
  4286. static void IOTRACE( string F, params object[] ap )
  4287. {
  4288. }
  4289. //#define sqlite3VdbeIOTraceSql(X)
  4290. static void sqlite3VdbeIOTraceSql( Vdbe X )
  4291. {
  4292. }
  4293. #endif
  4294. /*
  4295. ** These routines are available for the mem2.c debugging memory allocator
  4296. ** only. They are used to verify that different "types" of memory
  4297. ** allocations are properly tracked by the system.
  4298. **
  4299. ** sqlite3MemdebugSetType() sets the "type" of an allocation to one of
  4300. ** the MEMTYPE_* macros defined below. The type must be a bitmask with
  4301. ** a single bit set.
  4302. **
  4303. ** sqlite3MemdebugHasType() returns true if any of the bits in its second
  4304. ** argument match the type set by the previous sqlite3MemdebugSetType().
  4305. ** sqlite3MemdebugHasType() is intended for use inside Debug.Assert() statements.
  4306. **
  4307. ** sqlite3MemdebugNoType() returns true if none of the bits in its second
  4308. ** argument match the type set by the previous sqlite3MemdebugSetType().
  4309. **
  4310. ** Perhaps the most important point is the difference between MEMTYPE_HEAP
  4311. ** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means
  4312. ** it might have been allocated by lookaside, except the allocation was
  4313. ** too large or lookaside was already full. It is important to verify
  4314. ** that allocations that might have been satisfied by lookaside are not
  4315. ** passed back to non-lookaside free() routines. Asserts such as the
  4316. ** example above are placed on the non-lookaside free() routines to verify
  4317. ** this constraint.
  4318. **
  4319. ** All of this is no-op for a production build. It only comes into
  4320. ** play when the SQLITE_MEMDEBUG compile-time option is used.
  4321. */
  4322. #if SQLITE_MEMDEBUG
  4323. // void sqlite3MemdebugSetType(void*,u8);
  4324. // int sqlite3MemdebugHasType(void*,u8);
  4325. // int sqlite3MemdebugNoType(void*,u8);
  4326. #else
  4327. //# define sqlite3MemdebugSetType(X,Y) /* no-op */
  4328. static void sqlite3MemdebugSetType<T>( T X, int Y )
  4329. {
  4330. }
  4331. //# define sqlite3MemdebugHasType(X,Y) 1
  4332. static bool sqlite3MemdebugHasType<T>( T X, int Y )
  4333. {
  4334. return true;
  4335. }
  4336. //# define sqlite3MemdebugNoType(X,Y) 1
  4337. static bool sqlite3MemdebugNoType<T>( T X, int Y )
  4338. {
  4339. return true;
  4340. }
  4341. #endif
  4342. //#define MEMTYPE_HEAP 0x01 /* General heap allocations */
  4343. //#define MEMTYPE_LOOKASIDE 0x02 /* Might have been lookaside memory */
  4344. //#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
  4345. //#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
  4346. //#define MEMTYPE_DB 0x10 /* Uses sqlite3DbMalloc, not sqlite_malloc */
  4347. public const int MEMTYPE_HEAP = 0x01;
  4348. public const int MEMTYPE_LOOKASIDE = 0x02;
  4349. public const int MEMTYPE_SCRATCH = 0x04;
  4350. public const int MEMTYPE_PCACHE = 0x08;
  4351. public const int MEMTYPE_DB = 0x10;
  4352. //#endif //* _SQLITEINT_H_ */
  4353. }
  4354. }