PageRenderTime 46ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Library/WP7/SQLiteDriver/sqlite/sqliteInt_h.cs

https://bitbucket.org/digitalizarte/coolstorage
C# | 4518 lines | 2102 code | 277 blank | 2139 comment | 174 complexity | 1f13484fd3b40b0cbf5f6932196c0383 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. namespace Community.CsharpSqlite
  22. {
  23. using sqlite3_value = Sqlite3.Mem;
  24. public partial class Sqlite3
  25. {
  26. /*
  27. ** 2001 September 15
  28. **
  29. ** The author disclaims copyright to this source code. In place of
  30. ** a legal notice, here is a blessing:
  31. **
  32. ** May you do good and not evil.
  33. ** May you find forgiveness for yourself and forgive others.
  34. ** May you share freely, never taking more than you give.
  35. **
  36. *************************************************************************
  37. ** Internal interface definitions for SQLite.
  38. **
  39. *************************************************************************
  40. ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
  41. ** C#-SQLite is an independent reimplementation of the SQLite software library
  42. **
  43. ** SQLITE_SOURCE_ID: 2011-01-28 17:03:50 ed759d5a9edb3bba5f48f243df47be29e3fe8cd7
  44. **
  45. *************************************************************************
  46. */
  47. //#if !_SQLITEINT_H_
  48. //#define _SQLITEINT_H_
  49. /*
  50. ** These #defines should enable >2GB file support on POSIX if the
  51. ** underlying operating system supports it. If the OS lacks
  52. ** large file support, or if the OS is windows, these should be no-ops.
  53. **
  54. ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
  55. ** system #includes. Hence, this block of code must be the very first
  56. ** code in all source files.
  57. **
  58. ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
  59. ** on the compiler command line. This is necessary if you are compiling
  60. ** on a recent machine (ex: Red Hat 7.2) but you want your code to work
  61. ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
  62. ** without this option, LFS is enable. But LFS does not exist in the kernel
  63. ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
  64. ** portability you should omit LFS.
  65. **
  66. ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
  67. */
  68. //#if !SQLITE_DISABLE_LFS
  69. //# define _LARGE_FILE 1
  70. //# ifndef _FILE_OFFSET_BITS
  71. //# define _FILE_OFFSET_BITS 64
  72. //# endif
  73. //# define _LARGEFILE_SOURCE 1
  74. //#endif
  75. /*
  76. ** Include the configuration header output by 'configure' if we're using the
  77. ** autoconf-based build
  78. */
  79. #if _HAVE_SQLITE_CONFIG_H
  80. //#include "config.h"
  81. #endif
  82. //#include "sqliteLimit.h"
  83. /* Disable nuisance warnings on Borland compilers */
  84. //#if (__BORLANDC__)
  85. //#pragma warn -rch /* unreachable code */
  86. //#pragma warn -ccc /* Condition is always true or false */
  87. //#pragma warn -aus /* Assigned value is never used */
  88. //#pragma warn -csu /* Comparing signed and unsigned */
  89. //#pragma warn -spa /* Suspicious pointer arithmetic */
  90. //#endif
  91. /* Needed for various definitions... */
  92. //#if !_GNU_SOURCE
  93. //#define _GNU_SOURCE
  94. //#endif
  95. /*
  96. ** Include standard header files as necessary
  97. */
  98. #if HAVE_STDINT_H
  99. //#include <stdint.h>
  100. #endif
  101. #if HAVE_INTTYPES_H
  102. //#include <inttypes.h>
  103. #endif
  104. /*
  105. ** The number of samples of an index that SQLite takes in order to
  106. ** construct a histogram of the table content when running ANALYZE
  107. ** and with SQLITE_ENABLE_STAT2
  108. */
  109. //#define SQLITE_INDEX_SAMPLES 10
  110. public const int SQLITE_INDEX_SAMPLES = 10;
  111. /*
  112. ** The following macros are used to cast pointers to integers and
  113. ** integers to pointers. The way you do this varies from one compiler
  114. ** to the next, so we have developed the following set of #if statements
  115. ** to generate appropriate macros for a wide range of compilers.
  116. **
  117. ** The correct "ANSI" way to do this is to use the intptr_t type.
  118. ** Unfortunately, that typedef is not available on all compilers, or
  119. ** if it is available, it requires an #include of specific headers
  120. ** that vary from one machine to the next.
  121. **
  122. ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
  123. ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
  124. ** So we have to define the macros in different ways depending on the
  125. ** compiler.
  126. */
  127. //#if (__PTRDIFF_TYPE__) /* This case should work for GCC */
  128. //# define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X))
  129. //# define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X))
  130. //#elif !defined(__GNUC__) /* Works for compilers other than LLVM */
  131. //# define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X])
  132. //# define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
  133. //#elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */
  134. //# define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X))
  135. //# define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X))
  136. //#else /* Generates a warning - but it always works */
  137. //# define SQLITE_INT_TO_PTR(X) ((void*)(X))
  138. //# define SQLITE_PTR_TO_INT(X) ((int)(X))
  139. //#endif
  140. /*
  141. ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
  142. ** 0 means mutexes are permanently disable and the library is never
  143. ** threadsafe. 1 means the library is serialized which is the highest
  144. ** level of threadsafety. 2 means the libary is multithreaded - multiple
  145. ** threads can use SQLite as long as no two threads try to use the same
  146. ** database connection at the same time.
  147. **
  148. ** Older versions of SQLite used an optional THREADSAFE macro.
  149. ** We support that for legacy.
  150. */
  151. #if !SQLITE_THREADSAFE
  152. //# define SQLITE_THREADSAFE 2
  153. const int SQLITE_THREADSAFE = 2;
  154. #else
  155. const int SQLITE_THREADSAFE = 2; /* IMP: R-07272-22309 */
  156. #endif
  157. /*
  158. ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
  159. ** It determines whether or not the features related to
  160. ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
  161. ** be overridden at runtime using the sqlite3_config() API.
  162. */
  163. #if !(SQLITE_DEFAULT_MEMSTATUS)
  164. //# define SQLITE_DEFAULT_MEMSTATUS 1
  165. const int SQLITE_DEFAULT_MEMSTATUS = 0;
  166. #else
  167. const int SQLITE_DEFAULT_MEMSTATUS = 1;
  168. #endif
  169. /*
  170. ** Exactly one of the following macros must be defined in order to
  171. ** specify which memory allocation subsystem to use.
  172. **
  173. ** SQLITE_SYSTEM_MALLOC // Use normal system malloc()
  174. ** SQLITE_MEMDEBUG // Debugging version of system malloc()
  175. **
  176. ** (Historical note: There used to be several other options, but we've
  177. ** pared it down to just these two.)
  178. **
  179. ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
  180. ** the default.
  181. */
  182. //#if (SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  183. //# error "At most one of the following compile-time configuration options\
  184. // is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG"
  185. //#endif
  186. //#if (SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  187. //# define SQLITE_SYSTEM_MALLOC 1
  188. //#endif
  189. /*
  190. ** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the
  191. ** sizes of memory allocations below this value where possible.
  192. */
  193. #if !(SQLITE_MALLOC_SOFT_LIMIT)
  194. const int SQLITE_MALLOC_SOFT_LIMIT = 1024;
  195. #endif
  196. /*
  197. ** We need to define _XOPEN_SOURCE as follows in order to enable
  198. ** recursive mutexes on most Unix systems. But Mac OS X is different.
  199. ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told,
  200. ** so it is omitted there. See ticket #2673.
  201. **
  202. ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly
  203. ** implemented on some systems. So we avoid defining it at all
  204. ** if it is already defined or if it is unneeded because we are
  205. ** not doing a threadsafe build. Ticket #2681.
  206. **
  207. ** See also ticket #2741.
  208. */
  209. #if !_XOPEN_SOURCE && !__DARWIN__ && !__APPLE__ && SQLITE_THREADSAFE
  210. const int _XOPEN_SOURCE = 500;//#define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */
  211. #endif
  212. /*
  213. ** The TCL headers are only needed when compiling the TCL bindings.
  214. */
  215. #if SQLITE_TCL || TCLSH
  216. //# include <tcl.h>
  217. #endif
  218. /*
  219. ** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
  220. ** Setting NDEBUG makes the code smaller and run faster. So the following
  221. ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
  222. ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out
  223. ** feature.
  224. */
  225. #if !NDEBUG && !SQLITE_DEBUG
  226. const int NDEBUG = 1;//# define NDEBUG 1
  227. #endif
  228. /*
  229. ** The testcase() macro is used to aid in coverage testing. When
  230. ** doing coverage testing, the condition inside the argument to
  231. ** testcase() must be evaluated both true and false in order to
  232. ** get full branch coverage. The testcase() macro is inserted
  233. ** to help ensure adequate test coverage in places where simple
  234. ** condition/decision coverage is inadequate. For example, testcase()
  235. ** can be used to make sure boundary values are tested. For
  236. ** bitmask tests, testcase() can be used to make sure each bit
  237. ** is significant and used at least once. On switch statements
  238. ** where multiple cases go to the same block of code, testcase()
  239. ** can insure that all cases are evaluated.
  240. **
  241. */
  242. #if SQLITE_COVERAGE_TEST
  243. void sqlite3Coverage(int);
  244. //# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
  245. #else
  246. //# define testcase(X)
  247. static void testcase<T>( T X )
  248. {
  249. }
  250. #endif
  251. /*
  252. ** The TESTONLY macro is used to enclose variable declarations or
  253. ** other bits of code that are needed to support the arguments
  254. ** within testcase() and assert() macros.
  255. */
  256. #if !NDEBUG || SQLITE_COVERAGE_TEST
  257. //# define TESTONLY(X) X
  258. // -- Need workaround for C#, since inline macros don't exist
  259. #else
  260. //# define TESTONLY(X)
  261. #endif
  262. /*
  263. ** Sometimes we need a small amount of code such as a variable initialization
  264. ** to setup for a later assert() statement. We do not want this code to
  265. ** appear when assert() is disabled. The following macro is therefore
  266. ** used to contain that setup code. The "VVA" acronym stands for
  267. ** "Verification, Validation, and Accreditation". In other words, the
  268. ** code within VVA_ONLY() will only run during verification processes.
  269. */
  270. #if !NDEBUG
  271. //# define VVA_ONLY(X) X
  272. #else
  273. //# define VVA_ONLY(X)
  274. #endif
  275. /*
  276. ** The ALWAYS and NEVER macros surround boolean expressions which
  277. ** are intended to always be true or false, respectively. Such
  278. ** expressions could be omitted from the code completely. But they
  279. ** are included in a few cases in order to enhance the resilience
  280. ** of SQLite to unexpected behavior - to make the code "self-healing"
  281. ** or "ductile" rather than being "brittle" and crashing at the first
  282. ** hint of unplanned behavior.
  283. **
  284. ** In other words, ALWAYS and NEVER are added for defensive code.
  285. **
  286. ** When doing coverage testing ALWAYS and NEVER are hard-coded to
  287. ** be true and false so that the unreachable code then specify will
  288. ** not be counted as untested code.
  289. */
  290. #if SQLITE_COVERAGE_TEST
  291. //# define ALWAYS(X) (1)
  292. //# define NEVER(X) (0)
  293. #elif !NDEBUG
  294. //# define ALWAYS(X) ((X)?1:(assert(0),0))
  295. static bool ALWAYS( bool X )
  296. {
  297. if ( X != true )
  298. Debug.Assert( false );
  299. return true;
  300. }
  301. static int ALWAYS( int X )
  302. {
  303. if ( X == 0 )
  304. Debug.Assert( false );
  305. return 1;
  306. }
  307. static bool ALWAYS<T>( T X )
  308. {
  309. if ( X == null )
  310. Debug.Assert( false );
  311. return true;
  312. }
  313. //# define NEVER(X) ((X)?(assert(0),1):0)
  314. static bool NEVER( bool X )
  315. {
  316. if ( X == true )
  317. Debug.Assert( false );
  318. return false;
  319. }
  320. static byte NEVER( byte X )
  321. {
  322. if ( X != 0 )
  323. Debug.Assert( false );
  324. return 0;
  325. }
  326. static int NEVER( int X )
  327. {
  328. if ( X != 0 )
  329. Debug.Assert( false );
  330. return 0;
  331. }
  332. static bool NEVER<T>( T X )
  333. {
  334. if ( X != null )
  335. Debug.Assert( false );
  336. return false;
  337. }
  338. #else
  339. //# define ALWAYS(X) (X)
  340. static bool ALWAYS(bool X) { return X; }
  341. static byte ALWAYS(byte X) { return X; }
  342. static int ALWAYS(int X) { return X; }
  343. static bool ALWAYS<T>( T X ) { return true; }
  344. //# define NEVER(X) (X)
  345. static bool NEVER(bool X) { return X; }
  346. static byte NEVER(byte X) { return X; }
  347. static int NEVER(int X) { return X; }
  348. static bool NEVER<T>(T X) { return false; }
  349. #endif
  350. /*
  351. ** Return true (non-zero) if the input is a integer that is too large
  352. ** to fit in 32-bits. This macro is used inside of various testcase()
  353. ** macros to verify that we have tested SQLite for large-file support.
  354. */
  355. static bool IS_BIG_INT( i64 X )
  356. {
  357. return ( ( ( X ) & ~(i64)0xffffffff ) != 0 );
  358. }//#define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
  359. /*
  360. ** The macro unlikely() is a hint that surrounds a boolean
  361. ** expression that is usually false. Macro likely() surrounds
  362. ** a boolean expression that is usually true. GCC is able to
  363. ** use these hints to generate better code, sometimes.
  364. */
  365. #if (__GNUC__) && FALSE
  366. //# define likely(X) __builtin_expect((X),1)
  367. //# define unlikely(X) __builtin_expect((X),0)
  368. #else
  369. //# define likely(X) !!(X)
  370. static bool likely( bool X )
  371. {
  372. return !!X;
  373. }
  374. //# define unlikely(X) !!(X)
  375. static bool unlikely( bool X )
  376. {
  377. return !!X;
  378. }
  379. #endif
  380. //#include "sqlite3.h"
  381. //#include "hash.h"
  382. //#include "parse.h"
  383. //#include <stdio.h>
  384. //#include <stdlib.h>
  385. //#include <string.h>
  386. //#include <assert.h>
  387. //#include <stddef.h>
  388. /*
  389. ** If compiling for a processor that lacks floating point support,
  390. ** substitute integer for floating-point
  391. */
  392. #if SQLITE_OMIT_FLOATING_POINT
  393. //# define double sqlite_int64
  394. //# define float sqlite_int64
  395. //# define LONGDOUBLE_TYPE sqlite_int64
  396. //#if !SQLITE_BIG_DBL
  397. //# define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
  398. //# endif
  399. //# define SQLITE_OMIT_DATETIME_FUNCS 1
  400. //# define SQLITE_OMIT_TRACE 1
  401. //# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
  402. //# undef SQLITE_HAVE_ISNAN
  403. #endif
  404. #if !SQLITE_BIG_DBL
  405. const double SQLITE_BIG_DBL = ( ( (sqlite3_int64)1 ) << 60 );//# define SQLITE_BIG_DBL (1e99)
  406. #endif
  407. /*
  408. ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
  409. ** afterward. Having this macro allows us to cause the C compiler
  410. ** to omit code used by TEMP tables without messy #if !statements.
  411. */
  412. #if SQLITE_OMIT_TEMPDB
  413. //#define OMIT_TEMPDB 1
  414. #else
  415. static int OMIT_TEMPDB = 0;
  416. #endif
  417. /*
  418. ** The "file format" number is an integer that is incremented whenever
  419. ** the VDBE-level file format changes. The following macros define the
  420. ** the default file format for new databases and the maximum file format
  421. ** that the library can read.
  422. */
  423. static public int SQLITE_MAX_FILE_FORMAT = 4;//#define SQLITE_MAX_FILE_FORMAT 4
  424. //#if !SQLITE_DEFAULT_FILE_FORMAT
  425. static int SQLITE_DEFAULT_FILE_FORMAT = 1;//# define SQLITE_DEFAULT_FILE_FORMAT 1
  426. //#endif
  427. /*
  428. ** Determine whether triggers are recursive by default. This can be
  429. ** changed at run-time using a pragma.
  430. */
  431. #if !SQLITE_DEFAULT_RECURSIVE_TRIGGERS
  432. //# define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0
  433. static public bool SQLITE_DEFAULT_RECURSIVE_TRIGGERS = false;
  434. #else
  435. static public bool SQLITE_DEFAULT_RECURSIVE_TRIGGERS = true;
  436. #endif
  437. /*
  438. ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
  439. ** on the command-line
  440. */
  441. //#if !SQLITE_TEMP_STORE
  442. static int SQLITE_TEMP_STORE = 1;//#define SQLITE_TEMP_STORE 1
  443. //#endif
  444. /*
  445. ** GCC does not define the offsetof() macro so we'll have to do it
  446. ** ourselves.
  447. */
  448. #if !offsetof
  449. //#define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
  450. #endif
  451. /*
  452. ** Check to see if this machine uses EBCDIC. (Yes, believe it or
  453. ** not, there are still machines out there that use EBCDIC.)
  454. */
  455. #if FALSE //'A' == '\301'
  456. //# define SQLITE_EBCDIC 1
  457. #else
  458. const int SQLITE_ASCII = 1;//#define SQLITE_ASCII 1
  459. #endif
  460. /*
  461. ** Integers of known sizes. These typedefs might change for architectures
  462. ** where the sizes very. Preprocessor macros are available so that the
  463. ** types can be conveniently redefined at compile-type. Like this:
  464. **
  465. ** cc '-Du32PTR_TYPE=long long int' ...
  466. */
  467. //#if !u32_TYPE
  468. //# ifdef HAVE_u32_T
  469. //# define u32_TYPE u32_t
  470. //# else
  471. //# define u32_TYPE unsigned int
  472. //# endif
  473. //#endif
  474. //#if !u3216_TYPE
  475. //# ifdef HAVE_u3216_T
  476. //# define u3216_TYPE u3216_t
  477. //# else
  478. //# define u3216_TYPE unsigned short int
  479. //# endif
  480. //#endif
  481. //#if !INT16_TYPE
  482. //# ifdef HAVE_INT16_T
  483. //# define INT16_TYPE int16_t
  484. //# else
  485. //# define INT16_TYPE short int
  486. //# endif
  487. //#endif
  488. //#if !u328_TYPE
  489. //# ifdef HAVE_u328_T
  490. //# define u328_TYPE u328_t
  491. //# else
  492. //# define u328_TYPE unsigned char
  493. //# endif
  494. //#endif
  495. //#if !INT8_TYPE
  496. //# ifdef HAVE_INT8_T
  497. //# define INT8_TYPE int8_t
  498. //# else
  499. //# define INT8_TYPE signed char
  500. //# endif
  501. //#endif
  502. //#if !LONGDOUBLE_TYPE
  503. //# define LONGDOUBLE_TYPE long double
  504. //#endif
  505. //typedef sqlite_int64 i64; /* 8-byte signed integer */
  506. //typedef sqlite_u3264 u64; /* 8-byte unsigned integer */
  507. //typedef u32_TYPE u32; /* 4-byte unsigned integer */
  508. //typedef u3216_TYPE u16; /* 2-byte unsigned integer */
  509. //typedef INT16_TYPE i16; /* 2-byte signed integer */
  510. //typedef u328_TYPE u8; /* 1-byte unsigned integer */
  511. //typedef INT8_TYPE i8; /* 1-byte signed integer */
  512. /*
  513. ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
  514. ** that can be stored in a u32 without loss of data. The value
  515. ** is 0x00000000ffffffff. But because of quirks of some compilers, we
  516. ** have to specify the value in the less intuitive manner shown:
  517. */
  518. //#define SQLITE_MAX_U32 ((((u64)1)<<32)-1)
  519. const u32 SQLITE_MAX_U32 = (u32)( ( ( (u64)1 ) << 32 ) - 1 );
  520. /*
  521. ** Macros to determine whether the machine is big or little endian,
  522. ** evaluated at runtime.
  523. */
  524. #if SQLITE_AMALGAMATION
  525. //const int sqlite3one = 1;
  526. #else
  527. const bool sqlite3one = true;
  528. #endif
  529. #if i386 || __i386__ || _M_IX86
  530. const int ;//#define SQLITE_BIGENDIAN 0
  531. const int ;//#define SQLITE_LITTLEENDIAN 1
  532. const int ;//#define SQLITE_UTF16NATIVE SQLITE_UTF16LE
  533. #else
  534. static u8 SQLITE_BIGENDIAN = 0;//#define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
  535. static u8 SQLITE_LITTLEENDIAN = 1;//#define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
  536. static u8 SQLITE_UTF16NATIVE = ( SQLITE_BIGENDIAN != 0 ? SQLITE_UTF16BE : SQLITE_UTF16LE );//#define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
  537. #endif
  538. /*
  539. ** Constants for the largest and smallest possible 64-bit signed integers.
  540. ** These macros are designed to work correctly on both 32-bit and 64-bit
  541. ** compilers.
  542. */
  543. //#define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
  544. //#define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
  545. const i64 LARGEST_INT64 = i64.MaxValue;//( 0xffffffff | ( ( (i64)0x7fffffff ) << 32 ) );
  546. const i64 SMALLEST_INT64 = i64.MinValue;//( ( ( i64 ) - 1 ) - LARGEST_INT64 );
  547. /*
  548. ** Round up a number to the next larger multiple of 8. This is used
  549. ** to force 8-byte alignment on 64-bit architectures.
  550. */
  551. //#define ROUND8(x) (((x)+7)&~7)
  552. static int ROUND8( int x )
  553. {
  554. return ( x + 7 ) & ~7;
  555. }
  556. /*
  557. ** Round down to the nearest multiple of 8
  558. */
  559. //#define ROUNDDOWN8(x) ((x)&~7)
  560. static int ROUNDDOWN8( int x )
  561. {
  562. return x & ~7;
  563. }
  564. /*
  565. ** Assert that the pointer X is aligned to an 8-byte boundary. This
  566. ** macro is used only within assert() to verify that the code gets
  567. ** all alignment restrictions correct.
  568. **
  569. ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
  570. ** underlying malloc() implemention might return us 4-byte aligned
  571. ** pointers. In that case, only verify 4-byte alignment.
  572. */
  573. //#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
  574. //# define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0)
  575. //#else
  576. //# define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&7)==0)
  577. //#endif
  578. /*
  579. ** An instance of the following structure is used to store the busy-handler
  580. ** callback for a given sqlite handle.
  581. **
  582. ** The sqlite.busyHandler member of the sqlite struct contains the busy
  583. ** callback for the database handle. Each pager opened via the sqlite
  584. ** handle is passed a pointer to sqlite.busyHandler. The busy-handler
  585. ** callback is currently invoked only from within pager.c.
  586. */
  587. //typedef struct BusyHandler BusyHandler;
  588. public class BusyHandler
  589. {
  590. public dxBusy xFunc;//)(void *,int); /* The busy callback */
  591. public object pArg; /* First arg to busy callback */
  592. public int nBusy; /* Incremented with each busy call */
  593. };
  594. /*
  595. ** Name of the master database table. The master database table
  596. ** is a special table that holds the names and attributes of all
  597. ** user tables and indices.
  598. */
  599. const string MASTER_NAME = "sqlite_master";//#define MASTER_NAME "sqlite_master"
  600. const string TEMP_MASTER_NAME = "sqlite_temp_master";//#define TEMP_MASTER_NAME "sqlite_temp_master"
  601. /*
  602. ** The root-page of the master database table.
  603. */
  604. const int MASTER_ROOT = 1;//#define MASTER_ROOT 1
  605. /*
  606. ** The name of the schema table.
  607. */
  608. static string SCHEMA_TABLE( int x ) //#define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
  609. {
  610. return ( ( OMIT_TEMPDB == 0 ) && ( x == 1 ) ? TEMP_MASTER_NAME : MASTER_NAME );
  611. }
  612. /*
  613. ** A convenience macro that returns the number of elements in
  614. ** an array.
  615. */
  616. //#define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0])))
  617. static int ArraySize<T>( T[] x )
  618. {
  619. return x.Length;
  620. }
  621. /*
  622. ** The following value as a destructor means to use sqlite3DbFree().
  623. ** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT.
  624. */
  625. //#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3DbFree)
  626. static dxDel SQLITE_DYNAMIC;
  627. /*
  628. ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
  629. ** not support Writable Static Data (WSD) such as global and static variables.
  630. ** All variables must either be on the stack or dynamically allocated from
  631. ** the heap. When WSD is unsupported, the variable declarations scattered
  632. ** throughout the SQLite code must become constants instead. The SQLITE_WSD
  633. ** macro is used for this purpose. And instead of referencing the variable
  634. ** directly, we use its constant as a key to lookup the run-time allocated
  635. ** buffer that holds real variable. The constant is also the initializer
  636. ** for the run-time allocated buffer.
  637. **
  638. ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
  639. ** macros become no-ops and have zero performance impact.
  640. */
  641. #if SQLITE_OMIT_WSD
  642. //#define SQLITE_WSD const
  643. //#define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
  644. //#define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
  645. int sqlite3_wsd_init(int N, int J);
  646. void *sqlite3_wsd_find(void *K, int L);
  647. #else
  648. //#define SQLITE_WSD
  649. //#define GLOBAL(t,v) v
  650. //#define sqlite3GlobalConfig sqlite3Config
  651. static Sqlite3Config sqlite3GlobalConfig;
  652. #endif
  653. /*
  654. ** The following macros are used to suppress compiler warnings and to
  655. ** make it clear to human readers when a function parameter is deliberately
  656. ** left unused within the body of a function. This usually happens when
  657. ** a function is called via a function pointer. For example the
  658. ** implementation of an SQL aggregate step callback may not use the
  659. ** parameter indicating the number of arguments passed to the aggregate,
  660. ** if it knows that this is enforced elsewhere.
  661. **
  662. ** When a function parameter is not used at all within the body of a function,
  663. ** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
  664. ** However, these macros may also be used to suppress warnings related to
  665. ** parameters that may or may not be used depending on compilation options.
  666. ** For example those parameters only used in assert() statements. In these
  667. ** cases the parameters are named as per the usual conventions.
  668. */
  669. //#define UNUSED_PARAMETER(x) (void)(x)
  670. static void UNUSED_PARAMETER<T>( T x )
  671. {
  672. }
  673. //#define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y)
  674. static void UNUSED_PARAMETER2<T1, T2>( T1 x, T2 y )
  675. {
  676. UNUSED_PARAMETER( x );
  677. UNUSED_PARAMETER( y );
  678. }
  679. /*
  680. ** Forward references to structures
  681. */
  682. //typedef struct AggInfo AggInfo;
  683. //typedef struct AuthContext AuthContext;
  684. //typedef struct AutoincInfo AutoincInfo;
  685. //typedef struct Bitvec Bitvec;
  686. //typedef struct CollSeq CollSeq;
  687. //typedef struct Column Column;
  688. //typedef struct Db Db;
  689. //typedef struct Schema Schema;
  690. //typedef struct Expr Expr;
  691. //typedef struct ExprList ExprList;
  692. //typedef struct ExprSpan ExprSpan;
  693. //typedef struct FKey FKey;
  694. //typedef struct FuncDestructor FuncDestructor;
  695. //typedef struct FuncDef FuncDef;
  696. //typedef struct IdList IdList;
  697. //typedef struct Index Index;
  698. //typedef struct IndexSample IndexSample;
  699. //typedef struct KeyClass KeyClass;
  700. //typedef struct KeyInfo KeyInfo;
  701. //typedef struct Lookaside Lookaside;
  702. //typedef struct LookasideSlot LookasideSlot;
  703. //typedef struct Module Module;
  704. //typedef struct NameContext NameContext;
  705. //typedef struct Parse Parse;
  706. //typedef struct RowSet RowSet;
  707. //typedef struct Savepoint Savepoint;
  708. //typedef struct Select Select;
  709. //typedef struct SrcList SrcList;
  710. //typedef struct StrAccum StrAccum;
  711. //typedef struct Table Table;
  712. //typedef struct TableLock TableLock;
  713. //typedef struct Token Token;
  714. //typedef struct Trigger Trigger;
  715. //typedef struct TriggerPrg TriggerPrg;
  716. //typedef struct TriggerStep TriggerStep;
  717. //typedef struct UnpackedRecord UnpackedRecord;
  718. //typedef struct VTable VTable;
  719. //typedef struct Walker Walker;
  720. //typedef struct WherePlan WherePlan;
  721. //typedef struct WhereInfo WhereInfo;
  722. //typedef struct WhereLevel WhereLevel;
  723. /*
  724. ** Defer sourcing vdbe.h and btree.h until after the "u8" and
  725. ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
  726. ** pointer types (i.e. FuncDef) defined above.
  727. */
  728. //#include "btree.h"
  729. //#include "vdbe.h"
  730. //#include "pager.h"
  731. //#include "pcache_g.h"
  732. //#include "os.h"
  733. //#include "mutex.h"
  734. /*
  735. ** Each database file to be accessed by the system is an instance
  736. ** of the following structure. There are normally two of these structures
  737. ** in the sqlite.aDb[] array. aDb[0] is the main database file and
  738. ** aDb[1] is the database file used to hold temporary tables. Additional
  739. ** databases may be attached.
  740. */
  741. public class Db
  742. {
  743. public string zName; /* Name of this database */
  744. public Btree pBt; /* The B Tree structure for this database file */
  745. public u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */
  746. public u8 safety_level; /* How aggressive at syncing data to disk */
  747. public Schema pSchema; /* Pointer to database schema (possibly shared) */
  748. };
  749. /*
  750. ** An instance of the following structure stores a database schema.
  751. */
  752. public class Schema
  753. {
  754. public int schema_cookie; /* Database schema version number for this file */
  755. public Hash tblHash = new Hash(); /* All tables indexed by name */
  756. public Hash idxHash = new Hash(); /* All (named) indices indexed by name */
  757. public Hash trigHash = new Hash();/* All triggers indexed by name */
  758. public Hash fkeyHash = new Hash();/* All foreign keys by referenced table name */
  759. public Table pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
  760. public u8 file_format; /* Schema format version for this file */
  761. public u8 enc; /* Text encoding used by this database */
  762. public u16 flags; /* Flags associated with this schema */
  763. public int cache_size; /* Number of pages to use in the cache */
  764. public Schema Copy()
  765. {
  766. if ( this == null )
  767. return null;
  768. else
  769. {
  770. Schema cp = (Schema)MemberwiseClone();
  771. return cp;
  772. }
  773. }
  774. public void Clear()
  775. {
  776. if ( this != null )
  777. {
  778. schema_cookie = 0;
  779. tblHash = new Hash();
  780. idxHash = new Hash();
  781. trigHash = new Hash();
  782. fkeyHash = new Hash();
  783. pSeqTab = null;
  784. flags = 0;
  785. }
  786. }
  787. };
  788. /*
  789. ** These macros can be used to test, set, or clear bits in the
  790. ** Db.pSchema->flags field.
  791. */
  792. //#define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))==(P))
  793. static bool DbHasProperty( sqlite3 D, int I, ushort P )
  794. {
  795. return ( D.aDb[I].pSchema.flags & P ) == P;
  796. }
  797. //#define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))!=0)
  798. //#define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->flags|=(P)
  799. static void DbSetProperty( sqlite3 D, int I, ushort P )
  800. {
  801. D.aDb[I].pSchema.flags = (u16)( D.aDb[I].pSchema.flags | P );
  802. }
  803. //#define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->flags&=~(P)
  804. static void DbClearProperty( sqlite3 D, int I, ushort P )
  805. {
  806. D.aDb[I].pSchema.flags = (u16)( D.aDb[I].pSchema.flags & ~P );
  807. }
  808. /*
  809. ** Allowed values for the DB.pSchema->flags field.
  810. **
  811. ** The DB_SchemaLoaded flag is set after the database schema has been
  812. ** read into internal hash tables.
  813. **
  814. ** DB_UnresetViews means that one or more views have column names that
  815. ** have been filled out. If the schema changes, these column names might
  816. ** changes and so the view will need to be reset.
  817. */
  818. //#define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
  819. //#define DB_UnresetViews 0x0002 /* Some views have defined column names */
  820. //#define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
  821. const u16 DB_SchemaLoaded = 0x0001;
  822. const u16 DB_UnresetViews = 0x0002;
  823. const u16 DB_Empty = 0x0004;
  824. /*
  825. ** The number of different kinds of things that can be limited
  826. ** using the sqlite3_limit() interface.
  827. */
  828. //#define SQLITE_N_LIMIT (SQLITE_LIMIT_TRIGGER_DEPTH+1)
  829. const int SQLITE_N_LIMIT = SQLITE_LIMIT_TRIGGER_DEPTH + 1;
  830. /*
  831. ** Lookaside malloc is a set of fixed-size buffers that can be used
  832. ** to satisfy small transient memory allocation requests for objects
  833. ** associated with a particular database connection. The use of
  834. ** lookaside malloc provides a significant performance enhancement
  835. ** (approx 10%) by avoiding numerous malloc/free requests while parsing
  836. ** SQL statements.
  837. **
  838. ** The Lookaside structure holds configuration information about the
  839. ** lookaside malloc subsystem. Each available memory allocation in
  840. ** the lookaside subsystem is stored on a linked list of LookasideSlot
  841. ** objects.
  842. **
  843. ** Lookaside allocations are only allowed for objects that are associated
  844. ** with a particular database connection. Hence, schema information cannot
  845. ** be stored in lookaside because in shared cache mode the schema information
  846. ** is shared by multiple database connections. Therefore, while parsing
  847. ** schema information, the Lookaside.bEnabled flag is cleared so that
  848. ** lookaside allocations are not used to construct the schema objects.
  849. */
  850. public class Lookaside
  851. {
  852. public int sz; /* Size of each buffer in bytes */
  853. public u8 bEnabled; /* False to disable new lookaside allocations */
  854. public bool bMalloced; /* True if pStart obtained from sqlite3_malloc() */
  855. public int nOut; /* Number of buffers currently checked out */
  856. public int mxOut; /* Highwater mark for nOut */
  857. public int[] anStat = new int[3]; /* 0: hits. 1: size misses. 2: full misses */
  858. public LookasideSlot pFree; /* List of available buffers */
  859. public int pStart; /* First byte of available memory space */
  860. public int pEnd; /* First byte past end of available space */
  861. };
  862. public class LookasideSlot
  863. {
  864. public LookasideSlot pNext; /* Next buffer in the list of free buffers */
  865. };
  866. /*
  867. ** A hash table for function definitions.
  868. **
  869. ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots.
  870. ** Collisions are on the FuncDef.pHash chain.
  871. */
  872. public class FuncDefHash
  873. {
  874. public FuncDef[] a = new FuncDef[23]; /* Hash table for functions */
  875. };
  876. /*
  877. ** Each database connection is an instance of the following structure.
  878. **
  879. ** The sqlite.lastRowid records the last insert rowid generated by an
  880. ** insert statement. Inserts on views do not affect its value. Each
  881. ** trigger has its own context, so that lastRowid can be updated inside
  882. ** triggers as usual. The previous value will be restored once the trigger
  883. ** exits. Upon entering a before or instead of trigger, lastRowid is no
  884. ** longer (since after version 2.8.12) reset to -1.
  885. **
  886. ** The sqlite.nChange does not count changes within triggers and keeps no
  887. ** context. It is reset at start of sqlite3_exec.
  888. ** The sqlite.lsChange represents the number of changes made by the last
  889. ** insert, update, or delete statement. It remains constant throughout the
  890. ** length of a statement and is then updated by OP_SetCounts. It keeps a
  891. ** context stack just like lastRowid so that the count of changes
  892. ** within a trigger is not seen outside the trigger. Changes to views do not
  893. ** affect the value of lsChange.
  894. ** The sqlite.csChange keeps track of the number of current changes (since
  895. ** the last statement) and is used to update sqlite_lsChange.
  896. **
  897. ** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16
  898. ** store the most recent error code and, if applicable, string. The
  899. ** internal function sqlite3Error() is used to set these variables
  900. ** consistently.
  901. */
  902. public class sqlite3
  903. {
  904. public sqlite3_vfs pVfs; /* OS Interface */
  905. public int nDb; /* Number of backends currently in use */
  906. public Db[] aDb = new Db[SQLITE_MAX_ATTACHED]; /* All backends */
  907. public int flags; /* Miscellaneous flags. See below */
  908. public int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
  909. public int errCode; /* Most recent error code (SQLITE_*) */
  910. public int errMask; /* & result codes with this before returning */
  911. public u8 autoCommit; /* The auto-commit flag. */
  912. public u8 temp_store; /* 1: file 2: memory 0: default */
  913. // Cannot happen under C#
  914. // public u8 mallocFailed; /* True if we have seen a malloc failure */
  915. public u8 dfltLockMode; /* Default locking-mode for attached dbs */
  916. public int nextAutovac; /* Autovac setting after VACUUM if >=0 */
  917. public u8 suppressErr; /* Do not issue error messages if true */
  918. public int nextPagesize; /* Pagesize after VACUUM if >0 */
  919. public int nTable; /* Number of tables in the database */
  920. public CollSeq pDfltColl; /* The default collating sequence (BINARY) */
  921. public i64 lastRowid; /* ROWID of most recent insert (see above) */
  922. public u32 magic; /* Magic number for detect library misuse */
  923. public int nChange; /* Value returned by sqlite3_changes() */
  924. public int nTotalChange; /* Value returned by sqlite3_total_changes() */
  925. public sqlite3_mutex mutex; /* Connection mutex */
  926. public int[] aLimit = new int[SQLITE_N_LIMIT]; /* Limits */
  927. public class sqlite3InitInfo
  928. { /* Information used during initialization */
  929. public int iDb; /* When back is being initialized */
  930. public int newTnum; /* Rootpage of table being initialized */
  931. public u8 busy; /* TRUE if currently initializing */
  932. public u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
  933. };
  934. public sqlite3InitInfo init = new sqlite3InitInfo();
  935. public int nExtension; /* Number of loaded extensions */
  936. public object[] aExtension; /* Array of shared library handles */
  937. public Vdbe pVdbe; /* List of active virtual machines */
  938. public int activeVdbeCnt; /* Number of VDBEs currently executing */
  939. public int writeVdbeCnt; /* Number of active VDBEs that are writing */
  940. public int vdbeExecCnt; /* Number of nested calls to VdbeExec() */
  941. public dxTrace xTrace;//)(void*,const char*); /* Trace function */
  942. public object pTraceArg; /* Argument to the trace function */
  943. public dxProfile xProfile;//)(void*,const char*,u64); /* Profiling function */
  944. public object pProfileArg; /* Argument to profile function */
  945. public object pCommitArg; /* Argument to xCommitCallback() */
  946. public dxCommitCallback xCommitCallback;//)(void*); /* Invoked at every commit. */
  947. public object pRollbackArg; /* Argument to xRollbackCallback() */
  948. public dxRollbackCallback xRollbackCallback;//)(void*); /* Invoked at every commit. */
  949. public object pUpdateArg;
  950. public dxUpdateCallback xUpdateCallback;//)(void*,int, const char*,const char*,sqlite_int64);
  951. #if !SQLITE_OMIT_WAL
  952. //int (*xWalCallback)(void *, sqlite3 *, const char *, int);
  953. //void *pWalArg;
  954. #endif
  955. public dxCollNeeded xCollNeeded;//)(void*,sqlite3*,int eTextRep,const char*);
  956. public dxCollNeeded xCollNeeded16;//)(void*,sqlite3*,int eTextRep,const void*);
  957. public object pCollNeededArg;
  958. public sqlite3_value pErr; /* Most recent error message */
  959. public string zErrMsg; /* Most recent error message (UTF-8 encoded) */
  960. public string zErrMsg16; /* Most recent error message (UTF-16 encoded) */
  961. public struct _u1
  962. {
  963. public bool isInterrupted; /* True if sqlite3_interrupt has been called */
  964. public double notUsed1; /* Spacer */
  965. }
  966. public _u1 u1;
  967. public Lookaside lookaside = new Lookaside(); /* Lookaside malloc configuration */
  968. #if !SQLITE_OMIT_AUTHORIZATION
  969. public dxAuth xAuth;//)(void*,int,const char*,const char*,const char*,const char*);
  970. /* Access authorization function */
  971. public object pAuthArg; /* 1st argument to the access auth function */
  972. #endif
  973. #if !SQLITE_OMIT_PROGRESS_CALLBACK
  974. public dxProgress xProgress;//)(void *); /* The progress callback */
  975. public object pProgressArg; /* Argument to the progress callback */
  976. public int nProgressOps; /* Number of opcodes for progress callback */
  977. #endif
  978. #if !SQLITE_OMIT_VIRTUALTABLE
  979. public Hash aModule; /* populated by sqlite3_create_module() */
  980. public Table pVTab; /* vtab with active Connect/Create method */
  981. public VTable aVTrans; /* Virtual tables with open transactions */
  982. public int nVTrans; /* Allocated size of aVTrans */
  983. public VTable pDisconnect; /* Disconnect these in next sqlite3_prepare() */
  984. #endif
  985. public FuncDefHash aFunc = new FuncDefHash(); /* Hash table of connection functions */
  986. public Hash aCollSeq = new Hash(); /* All collating sequences */
  987. public BusyHandler busyHandler = new BusyHandler(); /* Busy callback */
  988. public int busyTimeout; /* Busy handler timeout, in msec */
  989. public Db[] aDbStatic = new Db[] { new Db(), new Db() }; /* Static space for the 2 default backends */
  990. public Savepoint pSavepoint; /* List of active savepoints */
  991. public int nSavepoint; /* Number of non-transaction savepoints */
  992. public int nStatement; /* Number of nested statement-transactions */
  993. public u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
  994. public i64 nDeferredCons; /* Net deferred constraints this transaction. */
  995. public int pnBytesFreed; /* If not NULL, increment this in DbFree() */
  996. #if SQLITE_ENABLE_UNLOCK_NOTIFY
  997. /* The following variables are all protected by the STATIC_MASTER
  998. ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
  999. **
  1000. ** When X.pUnlockConnection==Y, that means that X is waiting for Y to
  1001. ** unlock so that it can proceed.
  1002. **
  1003. ** When X.pBlockingConnection==Y, that means that something that X tried
  1004. ** tried to do recently failed with an SQLITE_LOCKED error due to locks
  1005. ** held by Y.
  1006. */
  1007. sqlite3 *pBlockingConnection; /* Connection that caused SQLITE_LOCKED */
  1008. sqlite3 *pUnlockConnection; /* Connection to watch for unlock */
  1009. void *pUnlockArg; /* Argument to xUnlockNotify */
  1010. void (*xUnlockNotify)(void **, int); /* Unlock notify callback */
  1011. sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
  1012. #endif
  1013. };
  1014. /*
  1015. ** A macro to discover the encoding of a database.
  1016. */
  1017. //#define ENC(db) ((db)->aDb[0].pSchema->enc)
  1018. static u8 ENC( sqlite3 db )
  1019. {
  1020. return db.aDb[0].pSchema.enc;
  1021. }
  1022. /*
  1023. ** Possible values for the sqlite3.flags.
  1024. */
  1025. //#define SQLITE_VdbeTrace 0x00000100 /* True to trace VDBE execution */
  1026. //#define SQLITE_InternChanges 0x00000200 /* Uncommitted Hash table changes */
  1027. //#define SQLITE_FullColNames 0x00000400 /* Show full column names on SELECT */
  1028. //#define SQLITE_ShortColNames 0x00000800 /* Show short columns names */
  1029. //#define SQLITE_CountRows 0x00001000 /* Count rows changed by INSERT, */
  1030. // /* DELETE, or UPDATE and return */
  1031. // /* the count using a callback. */
  1032. //#define SQLITE_NullCallback 0x00002000 /* Invoke the callback once if the */
  1033. // /* result set is empty */
  1034. //#define SQLITE_SqlTrace 0x00004000 /* Debug print SQL as it executes */
  1035. //#define SQLITE_VdbeListing 0x00008000 /* Debug listings of VDBE programs */
  1036. //#define SQLITE_WriteSchema 0x00010000 /* OK to update SQLITE_MASTER */
  1037. //#define SQLITE_NoReadlock 0x00020000 /* Readlocks are omitted when
  1038. // ** accessing read-only databases */
  1039. //#define SQLITE_IgnoreChecks 0x00040000 /* Do not enforce check constraints */
  1040. //#define SQLITE_ReadUncommitted 0x0080000 /* For shared-cache mode */
  1041. //#define SQLITE_LegacyFileFmt 0x00100000 /* Create new databases in format 1 */
  1042. //#define SQLITE_FullFSync 0x00200000 /* Use full fsync on the backend */
  1043. //#define SQLITE_CkptFullFSync 0x00400000 /* Use full fsync for checkpoint */
  1044. //#define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */
  1045. //#define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */
  1046. //#define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
  1047. //#define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
  1048. //#define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
  1049. //#define SQLITE_PreferBuiltin 0x10000000 /* Preference to built-in funcs */
  1050. //#define SQLITE_LoadExtension 0x20000000 /* Enable load_extension */
  1051. const int SQLITE_VdbeTrace = 0x00000100;
  1052. const int SQLITE_InternChanges = 0x00000200;
  1053. const int SQLITE_FullColNames = 0x00000400;
  1054. const int SQLITE_ShortColNames = 0x00000800;
  1055. const int SQLITE_CountRows = 0x00001000;
  1056. const int SQLITE_NullCallback = 0x00002000;
  1057. const int SQLITE_SqlTrace = 0x00004000;
  1058. const int SQLITE_VdbeListing = 0x00008000;
  1059. const int SQLITE_WriteSchema = 0x00010000;
  1060. const int SQLITE_NoReadlock = 0x00020000;
  1061. const int SQLITE_IgnoreChecks = 0x00040000;
  1062. const int SQLITE_ReadUncommitted = 0x0080000;
  1063. const int SQLITE_LegacyFileFmt = 0x00100000;
  1064. const int SQLITE_FullFSync = 0x00200000;
  1065. const int SQLITE_CkptFullFSync = 0x00400000;
  1066. const int SQLITE_RecoveryMode = 0x00800000;
  1067. const int SQLITE_ReverseOrder = 0x01000000;
  1068. const int SQLITE_RecTriggers = 0x02000000;
  1069. const int SQLITE_ForeignKeys = 0x04000000;
  1070. const int SQLITE_AutoIndex = 0x08000000;
  1071. const int SQLITE_PreferBuiltin = 0x10000000;
  1072. const int SQLITE_LoadExtension = 0x20000000;
  1073. /*
  1074. ** Bits of the sqlite3.flags field that are used by the
  1075. ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
  1076. ** These must be the low-order bits of the flags field.
  1077. */
  1078. //#define SQLITE_QueryFlattener 0x01 /* Disable query flattening */
  1079. //#define SQLITE_ColumnCache 0x02 /* Disable the column cache */
  1080. //#define SQLITE_IndexSort 0x04 /* Disable indexes for sorting */
  1081. //#define SQLITE_IndexSearch 0x08 /* Disable indexes for searching */
  1082. //#define SQLITE_IndexCover 0x10 /* Disable index covering table */
  1083. //#define SQLITE_GroupByOrder 0x20 /* Disable GROUPBY cover of ORDERBY */
  1084. //#define SQLITE_FactorOutConst 0x40 /* Disable factoring out constants */
  1085. //#define SQLITE_OptMask 0xff /* Mask of all disablable opts */
  1086. const int SQLITE_QueryFlattener = 0x01;
  1087. const int SQLITE_ColumnCache = 0x02;
  1088. const int SQLITE_IndexSort = 0x04;
  1089. const int SQLITE_IndexSearch = 0x08;
  1090. const int SQLITE_IndexCover = 0x10;
  1091. const int SQLITE_GroupByOrder = 0x20;
  1092. const int SQLITE_FactorOutConst = 0x40;
  1093. const int SQLITE_OptMask = 0xff;
  1094. /*
  1095. ** Possible values for the sqlite.magic field.
  1096. ** The numbers are obtained at random and have no special meaning, other
  1097. ** than being distinct from one another.
  1098. */
  1099. const int SQLITE_MAGIC_OPEN = 0x1029a697; //#define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */
  1100. const int SQLITE_MAGIC_CLOSED = 0x2f3c2d33; //#define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */
  1101. const int SQLITE_MAGIC_SICK = 0x3b771290; //#define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */
  1102. const int SQLITE_MAGIC_BUSY = 0x403b7906; //#define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
  1103. const int SQLITE_MAGIC_ERROR = 0x55357930; //#define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */
  1104. /*
  1105. ** Each SQL function is defined by an instance of the following
  1106. ** structure. A pointer to this structure is stored in the sqlite.aFunc
  1107. ** hash table. When multiple functions have the same name, the hash table
  1108. ** points to a linked list of these structures.
  1109. */
  1110. public class FuncDef
  1111. {
  1112. public i16 nArg; /* Number of arguments. -1 means unlimited */
  1113. public u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
  1114. public u8 flags; /* Some combination of SQLITE_FUNC_* */
  1115. public object pUserData; /* User data parameter */
  1116. public FuncDef pNext; /* Next function with same name */
  1117. public dxFunc xFunc;//)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
  1118. public dxStep xStep;//)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
  1119. public dxFinal xFinalize;//)(sqlite3_context*); /* Aggregate finalizer */
  1120. public string zName; /* SQL name of the function. */
  1121. public FuncDef pHash; /* Next with a different name but the same hash */
  1122. public FuncDestructor pDestructor; /* Reference counted destructor function */
  1123. public FuncDef()
  1124. {
  1125. }
  1126. public FuncDef( i16 nArg, u8 iPrefEnc, u8 iflags, object pUserData, FuncDef pNext, dxFunc xFunc, dxStep xStep, dxFinal xFinalize, string zName, FuncDef pHash, FuncDestructor pDestructor )
  1127. {
  1128. this.nArg = nArg;
  1129. this.iPrefEnc = iPrefEnc;
  1130. this.flags = iflags;
  1131. this.pUserData = pUserData;
  1132. this.pNext = pNext;
  1133. this.xFunc = xFunc;
  1134. this.xStep = xStep;
  1135. this.xFinalize = xFinalize;
  1136. this.zName = zName;
  1137. this.pHash = pHash;
  1138. this.pDestructor = pDestructor;
  1139. }
  1140. public FuncDef( string zName, u8 iPrefEnc, i16 nArg, int iArg, u8 iflags, dxFunc xFunc )
  1141. {
  1142. this.nArg = nArg;
  1143. this.iPrefEnc = iPrefEnc;
  1144. this.flags = iflags;
  1145. this.pUserData = iArg;
  1146. this.pNext = null;
  1147. this.xFunc = xFunc;
  1148. this.xStep = null;
  1149. this.xFinalize = null;
  1150. this.zName = zName;
  1151. }
  1152. public FuncDef( string zName, u8 iPrefEnc, i16 nArg, int iArg, u8 iflags, dxStep xStep, dxFinal xFinal )
  1153. {
  1154. this.nArg = nArg;
  1155. this.iPrefEnc = iPrefEnc;
  1156. this.flags = iflags;
  1157. this.pUserData = iArg;
  1158. this.pNext = null;
  1159. this.xFunc = null;
  1160. this.xStep = xStep;
  1161. this.xFinalize = xFinal;
  1162. this.zName = zName;
  1163. }
  1164. public FuncDef( string zName, u8 iPrefEnc, i16 nArg, object arg, dxFunc xFunc, u8 flags )
  1165. {
  1166. this.nArg = nArg;
  1167. this.iPrefEnc = iPrefEnc;
  1168. this.flags = flags;
  1169. this.pUserData = arg;
  1170. this.pNext = null;
  1171. this.xFunc = xFunc;
  1172. this.xStep = null;
  1173. this.xFinalize = null;
  1174. this.zName = zName;
  1175. }
  1176. };
  1177. /*
  1178. ** This structure encapsulates a user-function destructor callback (as
  1179. ** configured using create_function_v2()) and a reference counter. When
  1180. ** create_function_v2() is called to create a function with a destructor,
  1181. ** a single object of this type is allocated. FuncDestructor.nRef is set to
  1182. ** the number of FuncDef objects created (either 1 or 3, depending on whether
  1183. ** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor
  1184. ** member of each of the new FuncDef objects is set to point to the allocated
  1185. ** FuncDestructor.
  1186. **
  1187. ** Thereafter, when one of the FuncDef objects is deleted, the reference
  1188. ** count on this object is decremented. When it reaches 0, the destructor
  1189. ** is invoked and the FuncDestructor structure freed.
  1190. */
  1191. //struct FuncDestructor {
  1192. // int nRef;
  1193. // void (*xDestroy)(void *);
  1194. // void *pUserData;
  1195. //};
  1196. public class FuncDestructor
  1197. {
  1198. public int nRef;
  1199. public dxFDestroy xDestroy;// (*xDestroy)(void *);
  1200. public object pUserData;
  1201. };
  1202. /*
  1203. ** Possible values for FuncDef.flags
  1204. */
  1205. //#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
  1206. //#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
  1207. //#define SQLITE_FUNC_EPHEM 0x04 /* Ephemeral. Delete with VDBE */
  1208. //#define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
  1209. //#define SQLITE_FUNC_PRIVATE 0x10 /* Allowed for internal use only */
  1210. //#define SQLITE_FUNC_COUNT 0x20 /* Built-in count(*) aggregate */
  1211. //#define SQLITE_FUNC_COALESCE 0x40 /* Built-in coalesce() or ifnull() function */
  1212. const int SQLITE_FUNC_LIKE = 0x01; /* Candidate for the LIKE optimization */
  1213. const int SQLITE_FUNC_CASE = 0x02; /* Case-sensitive LIKE-type function */
  1214. const int SQLITE_FUNC_EPHEM = 0x04; /* Ephermeral. Delete with VDBE */
  1215. const int SQLITE_FUNC_NEEDCOLL = 0x08;/* sqlite3GetFuncCollSeq() might be called */
  1216. const int SQLITE_FUNC_PRIVATE = 0x10; /* Allowed for internal use only */
  1217. const int SQLITE_FUNC_COUNT = 0x20; /* Built-in count(*) aggregate */
  1218. const int SQLITE_FUNC_COALESCE = 0x40;/* Built-in coalesce() or ifnull() function */
  1219. /*
  1220. ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
  1221. ** used to create the initializers for the FuncDef structures.
  1222. **
  1223. ** FUNCTION(zName, nArg, iArg, bNC, xFunc)
  1224. ** Used to create a scalar function definition of a function zName
  1225. ** implemented by C function xFunc that accepts nArg arguments. The
  1226. ** value passed as iArg is cast to a (void*) and made available
  1227. ** as the user-data (sqlite3_user_data()) for the function. If
  1228. ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
  1229. **
  1230. ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
  1231. ** Used to create an aggregate function definition implemented by
  1232. ** the C functions xStep and xFinal. The first four parameters
  1233. ** are interpreted in the same way as the first 4 parameters to
  1234. ** FUNCTION().
  1235. **
  1236. ** LIKEFUNC(zName, nArg, pArg, flags)
  1237. ** Used to create a scalar function definition of a function zName
  1238. ** that accepts nArg arguments and is implemented by a call to C
  1239. ** function likeFunc. Argument pArg is cast to a (void *) and made
  1240. ** available as the function user-data (sqlite3_user_data()). The
  1241. ** FuncDef.flags variable is set to the value passed as the flags
  1242. ** parameter.
  1243. */
  1244. //#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
  1245. // {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
  1246. //SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
  1247. static FuncDef FUNCTION( string zName, i16 nArg, int iArg, u8 bNC, dxFunc xFunc )
  1248. {
  1249. return new FuncDef( zName, SQLITE_UTF8, nArg, iArg, (u8)( bNC * SQLITE_FUNC_NEEDCOLL ), xFunc );
  1250. }
  1251. //#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
  1252. // {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
  1253. //pArg, 0, xFunc, 0, 0, #zName, 0, 0}
  1254. //#define LIKEFUNC(zName, nArg, arg, flags) \
  1255. // {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
  1256. static FuncDef LIKEFUNC( string zName, i16 nArg, object arg, u8 flags )
  1257. {
  1258. return new FuncDef( zName, SQLITE_UTF8, nArg, arg, likeFunc, flags );
  1259. }
  1260. //#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
  1261. // {nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
  1262. //SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
  1263. static FuncDef AGGREGATE( string zName, i16 nArg, int arg, u8 nc, dxStep xStep, dxFinal xFinal )
  1264. {
  1265. return new FuncDef( zName, SQLITE_UTF8, nArg, arg, (u8)( nc * SQLITE_FUNC_NEEDCOLL ), xStep, xFinal );
  1266. }
  1267. /*
  1268. ** All current savepoints are stored in a linked list starting at
  1269. ** sqlite3.pSavepoint. The first element in the list is the most recently
  1270. ** opened savepoint. Savepoints are added to the list by the vdbe
  1271. ** OP_Savepoint instruction.
  1272. */
  1273. //struct Savepoint {
  1274. // char *zName; /* Savepoint name (nul-terminated) */
  1275. // i64 nDeferredCons; /* Number of deferred fk violations */
  1276. // Savepoint *pNext; /* Parent savepoint (if any) */
  1277. //};
  1278. public class Savepoint
  1279. {
  1280. public string zName; /* Savepoint name (nul-terminated) */
  1281. public i64 nDeferredCons; /* Number of deferred fk violations */
  1282. public Savepoint pNext; /* Parent savepoint (if any) */
  1283. };
  1284. /*
  1285. ** The following are used as the second parameter to sqlite3Savepoint(),
  1286. ** and as the P1 argument to the OP_Savepoint instruction.
  1287. */
  1288. const int SAVEPOINT_BEGIN = 0; //#define SAVEPOINT_BEGIN 0
  1289. const int SAVEPOINT_RELEASE = 1; //#define SAVEPOINT_RELEASE 1
  1290. const int SAVEPOINT_ROLLBACK = 2; //#define SAVEPOINT_ROLLBACK 2
  1291. /*
  1292. ** Each SQLite module (virtual table definition) is defined by an
  1293. ** instance of the following structure, stored in the sqlite3.aModule
  1294. ** hash table.
  1295. */
  1296. public class Module
  1297. {
  1298. public sqlite3_module pModule; /* Callback pointers */
  1299. public string zName; /* Name passed to create_module() */
  1300. public object pAux; /* pAux passed to create_module() */
  1301. public dxDestroy xDestroy;//)(void *); /* Module destructor function */
  1302. };
  1303. /*
  1304. ** information about each column of an SQL table is held in an instance
  1305. ** of this structure.
  1306. */
  1307. public class Column
  1308. {
  1309. public string zName; /* Name of this column */
  1310. public Expr pDflt; /* Default value of this column */
  1311. public string zDflt; /* Original text of the default value */
  1312. public string zType; /* Data type for this column */
  1313. public string zColl; /* Collating sequence. If NULL, use the default */
  1314. public u8 notNull; /* True if there is a NOT NULL constraint */
  1315. public u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
  1316. public char affinity; /* One of the SQLITE_AFF_... values */
  1317. #if !SQLITE_OMIT_VIRTUALTABLE
  1318. public u8 isHidden; /* True if this column is 'hidden' */
  1319. #endif
  1320. public Column Copy()
  1321. {
  1322. Column cp = (Column)MemberwiseClone();
  1323. if ( cp.pDflt != null )
  1324. cp.pDflt = pDflt.Copy();
  1325. return cp;
  1326. }
  1327. };
  1328. /*
  1329. ** A "Collating Sequence" is defined by an instance of the following
  1330. ** structure. Conceptually, a collating sequence consists of a name and
  1331. ** a comparison routine that defines the order of that sequence.
  1332. **
  1333. ** There may two separate implementations of the collation function, one
  1334. ** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that
  1335. ** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine
  1336. ** native byte order. When a collation sequence is invoked, SQLite selects
  1337. ** the version that will require the least expensive encoding
  1338. ** translations, if any.
  1339. **
  1340. ** The CollSeq.pUser member variable is an extra parameter that passed in
  1341. ** as the first argument to the UTF-8 comparison function, xCmp.
  1342. ** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function,
  1343. ** xCmp16.
  1344. **
  1345. ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
  1346. ** collating sequence is undefined. Indices built on an undefined
  1347. ** collating sequence may not be read or written.
  1348. */
  1349. public class CollSeq
  1350. {
  1351. public string zName; /* Name of the collating sequence, UTF-8 encoded */
  1352. public u8 enc; /* Text encoding handled by xCmp() */
  1353. public u8 type; /* One of the SQLITE_COLL_... values below */
  1354. public object pUser; /* First argument to xCmp() */
  1355. public dxCompare xCmp;//)(void*,int, const void*, int, const void*);
  1356. public dxDelCollSeq xDel;//)(void*); /* Destructor for pUser */
  1357. public CollSeq Copy()
  1358. {
  1359. if ( this == null )
  1360. return null;
  1361. else
  1362. {
  1363. CollSeq cp = (CollSeq)MemberwiseClone();
  1364. return cp;
  1365. }
  1366. }
  1367. };
  1368. /*
  1369. ** Allowed values of CollSeq.type:
  1370. */
  1371. const int SQLITE_COLL_BINARY = 1;//#define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */
  1372. const int SQLITE_COLL_NOCASE = 2;//#define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */
  1373. const int SQLITE_COLL_REVERSE = 3;//#define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */
  1374. const int SQLITE_COLL_USER = 0;//#define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */
  1375. /*
  1376. ** A sort order can be either ASC or DESC.
  1377. */
  1378. const int SQLITE_SO_ASC = 0;//#define SQLITE_SO_ASC 0 /* Sort in ascending order */
  1379. const int SQLITE_SO_DESC = 1;//#define SQLITE_SO_DESC 1 /* Sort in ascending order */
  1380. /*
  1381. ** Column affinity types.
  1382. **
  1383. ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
  1384. ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
  1385. ** the speed a little by numbering the values consecutively.
  1386. **
  1387. ** But rather than start with 0 or 1, we begin with 'a'. That way,
  1388. ** when multiple affinity types are concatenated into a string and
  1389. ** used as the P4 operand, they will be more readable.
  1390. **
  1391. ** Note also that the numeric types are grouped together so that testing
  1392. ** for a numeric type is a single comparison.
  1393. */
  1394. const char SQLITE_AFF_TEXT = 'a';//#define SQLITE_AFF_TEXT 'a'
  1395. const char SQLITE_AFF_NONE = 'b';//#define SQLITE_AFF_NONE 'b'
  1396. const char SQLITE_AFF_NUMERIC = 'c';//#define SQLITE_AFF_NUMERIC 'c'
  1397. const char SQLITE_AFF_INTEGER = 'd';//#define SQLITE_AFF_INTEGER 'd'
  1398. const char SQLITE_AFF_REAL = 'e';//#define SQLITE_AFF_REAL 'e'
  1399. //#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
  1400. /*
  1401. ** The SQLITE_AFF_MASK values masks off the significant bits of an
  1402. ** affinity value.
  1403. */
  1404. const int SQLITE_AFF_MASK = 0x67;//#define SQLITE_AFF_MASK 0x67
  1405. /*
  1406. ** Additional bit values that can be ORed with an affinity without
  1407. ** changing the affinity.
  1408. */
  1409. const int SQLITE_JUMPIFNULL = 0x08; //#define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
  1410. const int SQLITE_STOREP2 = 0x10; //#define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
  1411. const int SQLITE_NULLEQ = 0x80; //#define SQLITE_NULLEQ 0x80 /* NULL=NULL */
  1412. /*
  1413. ** An object of this type is created for each virtual table present in
  1414. ** the database schema.
  1415. **
  1416. ** If the database schema is shared, then there is one instance of this
  1417. ** structure for each database connection (sqlite3*) that uses the shared
  1418. ** schema. This is because each database connection requires its own unique
  1419. ** instance of the sqlite3_vtab* handle used to access the virtual table
  1420. ** implementation. sqlite3_vtab* handles can not be shared between
  1421. ** database connections, even when the rest of the in-memory database
  1422. ** schema is shared, as the implementation often stores the database
  1423. ** connection handle passed to it via the xConnect() or xCreate() method
  1424. ** during initialization internally. This database connection handle may
  1425. ** then used by the virtual table implementation to access real tables
  1426. ** within the database. So that they appear as part of the callers
  1427. ** transaction, these accesses need to be made via the same database
  1428. ** connection as that used to execute SQL operations on the virtual table.
  1429. **
  1430. ** All VTable objects that correspond to a single table in a shared
  1431. ** database schema are initially stored in a linked-list pointed to by
  1432. ** the Table.pVTable member variable of the corresponding Table object.
  1433. ** When an sqlite3_prepare() operation is required to access the virtual
  1434. ** table, it searches the list for the VTable that corresponds to the
  1435. ** database connection doing the preparing so as to use the correct
  1436. ** sqlite3_vtab* handle in the compiled query.
  1437. **
  1438. ** When an in-memory Table object is deleted (for example when the
  1439. ** schema is being reloaded for some reason), the VTable objects are not
  1440. ** deleted and the sqlite3_vtab* handles are not xDisconnect()ed
  1441. ** immediately. Instead, they are moved from the Table.pVTable list to
  1442. ** another linked list headed by the sqlite3.pDisconnect member of the
  1443. ** corresponding sqlite3 structure. They are then deleted/xDisconnected
  1444. ** next time a statement is prepared using said sqlite3*. This is done
  1445. ** to avoid deadlock issues involving multiple sqlite3.mutex mutexes.
  1446. ** Refer to comments above function sqlite3VtabUnlockList() for an
  1447. ** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect
  1448. ** list without holding the corresponding sqlite3.mutex mutex.
  1449. **
  1450. ** The memory for objects of this type is always allocated by
  1451. ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
  1452. ** the first argument.
  1453. */
  1454. public class VTable
  1455. {
  1456. public sqlite3 db; /* Database connection associated with this table */
  1457. public Module pMod; /* Pointer to module implementation */
  1458. public sqlite3_vtab pVtab; /* Pointer to vtab instance */
  1459. public int nRef; /* Number of pointers to this structure */
  1460. public VTable pNext; /* Next in linked list (see above) */
  1461. };
  1462. /*
  1463. ** Each SQL table is represented in memory by an instance of the
  1464. ** following structure.
  1465. **
  1466. ** Table.zName is the name of the table. The case of the original
  1467. ** CREATE TABLE statement is stored, but case is not significant for
  1468. ** comparisons.
  1469. **
  1470. ** Table.nCol is the number of columns in this table. Table.aCol is a
  1471. ** pointer to an array of Column structures, one for each column.
  1472. **
  1473. ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
  1474. ** the column that is that key. Otherwise Table.iPKey is negative. Note
  1475. ** that the datatype of the PRIMARY KEY must be INTEGER for this field to
  1476. ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
  1477. ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
  1478. ** is generated for each row of the table. TF_HasPrimaryKey is set if
  1479. ** the table has any PRIMARY KEY, INTEGER or otherwise.
  1480. **
  1481. ** Table.tnum is the page number for the root BTree page of the table in the
  1482. ** database file. If Table.iDb is the index of the database table backend
  1483. ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
  1484. ** holds temporary tables and indices. If TF_Ephemeral is set
  1485. ** then the table is stored in a file that is automatically deleted
  1486. ** when the VDBE cursor to the table is closed. In this case Table.tnum
  1487. ** refers VDBE cursor number that holds the table open, not to the root
  1488. ** page number. Transient tables are used to hold the results of a
  1489. ** sub-query that appears instead of a real table name in the FROM clause
  1490. ** of a SELECT statement.
  1491. */
  1492. public class Table
  1493. {
  1494. public string zName; /* Name of the table or view */
  1495. public int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
  1496. public int nCol; /* Number of columns in this table */
  1497. public Column[] aCol; /* Information about each column */
  1498. public Index pIndex; /* List of SQL indexes on this table. */
  1499. public int tnum; /* Root BTree node for this table (see note above) */
  1500. public u32 nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
  1501. public Select pSelect; /* NULL for tables. Points to definition if a view. */
  1502. public u16 nRef; /* Number of pointers to this Table */
  1503. public u8 tabFlags; /* Mask of TF_* values */
  1504. public u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
  1505. public FKey pFKey; /* Linked list of all foreign keys in this table */
  1506. public string zColAff; /* String defining the affinity of each column */
  1507. #if !SQLITE_OMIT_CHECK
  1508. public Expr pCheck; /* The AND of all CHECK constraints */
  1509. #endif
  1510. #if !SQLITE_OMIT_ALTERTABLE
  1511. public int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
  1512. #endif
  1513. #if !SQLITE_OMIT_VIRTUALTABLE
  1514. public VTable pVTable; /* List of VTable objects. */
  1515. public int nModuleArg; /* Number of arguments to the module */
  1516. public string[] azModuleArg;/* Text of all module args. [0] is module name */
  1517. #endif
  1518. public Trigger pTrigger; /* List of SQL triggers on this table */
  1519. public Schema pSchema; /* Schema that contains this table */
  1520. public Table pNextZombie; /* Next on the Parse.pZombieTab list */
  1521. public Table Copy()
  1522. {
  1523. if ( this == null )
  1524. return null;
  1525. else
  1526. {
  1527. Table cp = (Table)MemberwiseClone();
  1528. if ( pIndex != null )
  1529. cp.pIndex = pIndex.Copy();
  1530. if ( pSelect != null )
  1531. cp.pSelect = pSelect.Copy();
  1532. if ( pTrigger != null )
  1533. cp.pTrigger = pTrigger.Copy();
  1534. if ( pFKey != null )
  1535. cp.pFKey = pFKey.Copy();
  1536. #if !SQLITE_OMIT_CHECK
  1537. // Don't Clone Checks, only copy reference via Memberwise Clone above --
  1538. //if ( pCheck != null ) cp.pCheck = pCheck.Copy();
  1539. #endif
  1540. #if !SQLITE_OMIT_VIRTUALTABLE
  1541. if ( pMod != null ) cp.pMod =pMod.Copy();
  1542. if ( pVtab != null ) cp.pVtab =pVtab.Copy();
  1543. #endif
  1544. // Don't Clone Schema, only copy reference via Memberwise Clone above --
  1545. // if ( pSchema != null ) cp.pSchema=pSchema.Copy();
  1546. // Don't Clone pNextZombie, only copy reference via Memberwise Clone above --
  1547. // if ( pNextZombie != null ) cp.pNextZombie=pNextZombie.Copy();
  1548. return cp;
  1549. }
  1550. }
  1551. };
  1552. /*
  1553. ** Allowed values for Tabe.tabFlags.
  1554. */
  1555. //#define TF_Readonly 0x01 /* Read-only system table */
  1556. //#define TF_Ephemeral 0x02 /* An ephemeral table */
  1557. //#define TF_HasPrimaryKey 0x04 /* Table has a primary key */
  1558. //#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
  1559. //#define TF_Virtual 0x10 /* Is a virtual table */
  1560. //#define TF_NeedMetadata 0x20 /* aCol[].zType and aCol[].pColl missing */
  1561. /*
  1562. ** Allowed values for Tabe.tabFlags.
  1563. */
  1564. const int TF_Readonly = 0x01; /* Read-only system table */
  1565. const int TF_Ephemeral = 0x02; /* An ephemeral table */
  1566. const int TF_HasPrimaryKey = 0x04; /* Table has a primary key */
  1567. const int TF_Autoincrement = 0x08; /* Integer primary key is autoincrement */
  1568. const int TF_Virtual = 0x10; /* Is a virtual table */
  1569. const int TF_NeedMetadata = 0x20; /* aCol[].zType and aCol[].pColl missing */
  1570. /*
  1571. ** Test to see whether or not a table is a virtual table. This is
  1572. ** done as a macro so that it will be optimized out when virtual
  1573. ** table support is omitted from the build.
  1574. */
  1575. #if !SQLITE_OMIT_VIRTUALTABLE
  1576. //# define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)
  1577. static bool IsVirtual( Table X) { return (X.tabFlags & TF_Virtual)!=0;}
  1578. //# define IsHiddenColumn(X) ((X)->isHidden)
  1579. static bool IsVirtual( Column X) { return X.isHidden!=0;}
  1580. #else
  1581. //# define IsVirtual(X) 0
  1582. static bool IsVirtual( Table T )
  1583. {
  1584. return false;
  1585. }
  1586. //# define IsHiddenColumn(X) 0
  1587. static bool IsHiddenColumn( Column C )
  1588. {
  1589. return false;
  1590. }
  1591. #endif
  1592. /*
  1593. ** Each foreign key constraint is an instance of the following structure.
  1594. **
  1595. ** A foreign key is associated with two tables. The "from" table is
  1596. ** the table that contains the REFERENCES clause that creates the foreign
  1597. ** key. The "to" table is the table that is named in the REFERENCES clause.
  1598. ** Consider this example:
  1599. **
  1600. ** CREATE TABLE ex1(
  1601. ** a INTEGER PRIMARY KEY,
  1602. ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
  1603. ** );
  1604. **
  1605. ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
  1606. **
  1607. ** Each REFERENCES clause generates an instance of the following structure
  1608. ** which is attached to the from-table. The to-table need not exist when
  1609. ** the from-table is created. The existence of the to-table is not checked.
  1610. */
  1611. public class FKey
  1612. {
  1613. public Table pFrom; /* Table containing the REFERENCES clause (aka: Child) */
  1614. public FKey pNextFrom; /* Next foreign key in pFrom */
  1615. public string zTo; /* Name of table that the key points to (aka: Parent) */
  1616. public FKey pNextTo; /* Next foreign key on table named zTo */
  1617. public FKey pPrevTo; /* Previous foreign key on table named zTo */
  1618. public int nCol; /* Number of columns in this key */
  1619. /* EV: R-30323-21917 */
  1620. public u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
  1621. public u8[] aAction = new u8[2]; /* ON DELETE and ON UPDATE actions, respectively */
  1622. public Trigger[] apTrigger = new Trigger[2];/* Triggers for aAction[] actions */
  1623. public class sColMap
  1624. { /* Mapping of columns in pFrom to columns in zTo */
  1625. public int iFrom; /* Index of column in pFrom */
  1626. public string zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */
  1627. };
  1628. public sColMap[] aCol; /* One entry for each of nCol column s */
  1629. public FKey Copy()
  1630. {
  1631. if ( this == null )
  1632. return null;
  1633. else
  1634. {
  1635. FKey cp = (FKey)MemberwiseClone();
  1636. return cp;
  1637. }
  1638. }
  1639. };
  1640. /*
  1641. ** SQLite supports many different ways to resolve a constraint
  1642. ** error. ROLLBACK processing means that a constraint violation
  1643. ** causes the operation in process to fail and for the current transaction
  1644. ** to be rolled back. ABORT processing means the operation in process
  1645. ** fails and any prior changes from that one operation are backed out,
  1646. ** but the transaction is not rolled back. FAIL processing means that
  1647. ** the operation in progress stops and returns an error code. But prior
  1648. ** changes due to the same operation are not backed out and no rollback
  1649. ** occurs. IGNORE means that the particular row that caused the constraint
  1650. ** error is not inserted or updated. Processing continues and no error
  1651. ** is returned. REPLACE means that preexisting database rows that caused
  1652. ** a UNIQUE constraint violation are removed so that the new insert or
  1653. ** update can proceed. Processing continues and no error is reported.
  1654. **
  1655. ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
  1656. ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
  1657. ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign
  1658. ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the
  1659. ** referenced table row is propagated into the row that holds the
  1660. ** foreign key.
  1661. **
  1662. ** The following symbolic values are used to record which type
  1663. ** of action to take.
  1664. */
  1665. const int OE_None = 0;//#define OE_None 0 /* There is no constraint to check */
  1666. const int OE_Rollback = 1;//#define OE_Rollback 1 /* Fail the operation and rollback the transaction */
  1667. const int OE_Abort = 2;//#define OE_Abort 2 /* Back out changes but do no rollback transaction */
  1668. const int OE_Fail = 3;//#define OE_Fail 3 /* Stop the operation but leave all prior changes */
  1669. const int OE_Ignore = 4;//#define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */
  1670. const int OE_Replace = 5;//#define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */
  1671. const int OE_Restrict = 6;//#define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
  1672. const int OE_SetNull = 7;//#define OE_SetNull 7 /* Set the foreign key value to NULL */
  1673. const int OE_SetDflt = 8;//#define OE_SetDflt 8 /* Set the foreign key value to its default */
  1674. const int OE_Cascade = 9;//#define OE_Cascade 9 /* Cascade the changes */
  1675. const int OE_Default = 99;//#define OE_Default 99 /* Do whatever the default action is */
  1676. /*
  1677. ** An instance of the following structure is passed as the first
  1678. ** argument to sqlite3VdbeKeyCompare and is used to control the
  1679. ** comparison of the two index keys.
  1680. */
  1681. public class KeyInfo
  1682. {
  1683. public sqlite3 db; /* The database connection */
  1684. public u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
  1685. public u16 nField; /* Number of entries in aColl[] */
  1686. public u8[] aSortOrder; /* Sort order for each column. May be NULL */
  1687. public CollSeq[] aColl = new CollSeq[1]; /* Collating sequence for each term of the key */
  1688. public KeyInfo Copy()
  1689. {
  1690. return (KeyInfo)MemberwiseClone();
  1691. }
  1692. };
  1693. /*
  1694. ** An instance of the following structure holds information about a
  1695. ** single index record that has already been parsed out into individual
  1696. ** values.
  1697. **
  1698. ** A record is an object that contains one or more fields of data.
  1699. ** Records are used to store the content of a table row and to store
  1700. ** the key of an index. A blob encoding of a record is created by
  1701. ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
  1702. ** OP_Column opcode.
  1703. **
  1704. ** This structure holds a record that has already been disassembled
  1705. ** into its constituent fields.
  1706. */
  1707. public class UnpackedRecord
  1708. {
  1709. public KeyInfo pKeyInfo; /* Collation and sort-order information */
  1710. public u16 nField; /* Number of entries in apMem[] */
  1711. public u16 flags; /* Boolean settings. UNPACKED_... below */
  1712. public i64 rowid; /* Used by UNPACKED_PREFIX_SEARCH */
  1713. public Mem[] aMem; /* Values */
  1714. };
  1715. /*
  1716. ** Allowed values of UnpackedRecord.flags
  1717. */
  1718. //#define UNPACKED_NEED_FREE 0x0001 /* Memory is from sqlite3Malloc() */
  1719. //#define UNPACKED_NEED_DESTROY 0x0002 /* apMem[]s should all be destroyed */
  1720. //#define UNPACKED_IGNORE_ROWID 0x0004 /* Ignore trailing rowid on key1 */
  1721. //#define UNPACKED_INCRKEY 0x0008 /* Make this key an epsilon larger */
  1722. //#define UNPACKED_PREFIX_MATCH 0x0010 /* A prefix match is considered OK */
  1723. //#define UNPACKED_PREFIX_SEARCH 0x0020 /* A prefix match is considered OK */
  1724. const int UNPACKED_NEED_FREE = 0x0001; /* Memory is from sqlite3Malloc() */
  1725. const int UNPACKED_NEED_DESTROY = 0x0002; /* apMem[]s should all be destroyed */
  1726. const int UNPACKED_IGNORE_ROWID = 0x0004; /* Ignore trailing rowid on key1 */
  1727. const int UNPACKED_INCRKEY = 0x0008; /* Make this key an epsilon larger */
  1728. const int UNPACKED_PREFIX_MATCH = 0x0010; /* A prefix match is considered OK */
  1729. const int UNPACKED_PREFIX_SEARCH = 0x0020; /* A prefix match is considered OK */
  1730. /*
  1731. ** Each SQL index is represented in memory by an
  1732. ** instance of the following structure.
  1733. **
  1734. ** The columns of the table that are to be indexed are described
  1735. ** by the aiColumn[] field of this structure. For example, suppose
  1736. ** we have the following table and index:
  1737. **
  1738. ** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
  1739. ** CREATE INDEX Ex2 ON Ex1(c3,c1);
  1740. **
  1741. ** In the Table structure describing Ex1, nCol==3 because there are
  1742. ** three columns in the table. In the Index structure describing
  1743. ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
  1744. ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the
  1745. ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
  1746. ** The second column to be indexed (c1) has an index of 0 in
  1747. ** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
  1748. **
  1749. ** The Index.onError field determines whether or not the indexed columns
  1750. ** must be unique and what to do if they are not. When Index.onError=OE_None,
  1751. ** it means this is not a unique index. Otherwise it is a unique index
  1752. ** and the value of Index.onError indicate the which conflict resolution
  1753. ** algorithm to employ whenever an attempt is made to insert a non-unique
  1754. ** element.
  1755. */
  1756. public class Index
  1757. {
  1758. public string zName; /* Name of this index */
  1759. public int nColumn; /* Number of columns in the table used by this index */
  1760. public int[] aiColumn; /* Which columns are used by this index. 1st is 0 */
  1761. public int[] aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
  1762. public Table pTable; /* The SQL table being indexed */
  1763. public int tnum; /* Page containing root of this index in database file */
  1764. public u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
  1765. public u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
  1766. public string zColAff; /* String defining the affinity of each column */
  1767. public Index pNext; /* The next index associated with the same table */
  1768. public Schema pSchema; /* Schema containing this index */
  1769. public u8[] aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
  1770. public string[] azColl; /* Array of collation sequence names for index */
  1771. public IndexSample[] aSample; /* Array of SQLITE_INDEX_SAMPLES samples */
  1772. public Index Copy()
  1773. {
  1774. if ( this == null )
  1775. return null;
  1776. else
  1777. {
  1778. Index cp = (Index)MemberwiseClone();
  1779. return cp;
  1780. }
  1781. }
  1782. };
  1783. /*
  1784. ** Each sample stored in the sqlite_stat2 table is represented in memory
  1785. ** using a structure of this type.
  1786. */
  1787. public class IndexSample
  1788. {
  1789. public struct _u
  1790. { //union {
  1791. public string z; /* Value if eType is SQLITE_TEXT */
  1792. public byte[] zBLOB; /* Value if eType is SQLITE_BLOB */
  1793. public double r; /* Value if eType is SQLITE_FLOAT or SQLITE_INTEGER */
  1794. }
  1795. public _u u;
  1796. public u8 eType; /* SQLITE_NULL, SQLITE_INTEGER ... etc. */
  1797. public u8 nByte; /* Size in byte of text or blob. */
  1798. };
  1799. /*
  1800. ** Each token coming out of the lexer is an instance of
  1801. ** this structure. Tokens are also used as part of an expression.
  1802. **
  1803. ** Note if Token.z==0 then Token.dyn and Token.n are undefined and
  1804. ** may contain random values. Do not make any assumptions about Token.dyn
  1805. ** and Token.n when Token.z==0.
  1806. */
  1807. public class Token
  1808. {
  1809. #if DEBUG_CLASS_TOKEN || DEBUG_CLASS_ALL
  1810. public string _z; /* Text of the token. Not NULL-terminated! */
  1811. public bool dyn;// : 1; /* True for malloced memory, false for static */
  1812. public Int32 _n;// : 31; /* Number of characters in this token */
  1813. public string z
  1814. {
  1815. get { return _z; }
  1816. set { _z = value; }
  1817. }
  1818. public Int32 n
  1819. {
  1820. get { return _n; }
  1821. set { _n = value; }
  1822. }
  1823. #else
  1824. public string z; /* Text of the token. Not NULL-terminated! */
  1825. public Int32 n; /* Number of characters in this token */
  1826. #endif
  1827. public Token()
  1828. {
  1829. this.z = null;
  1830. this.n = 0;
  1831. }
  1832. public Token( string z, Int32 n )
  1833. {
  1834. this.z = z;
  1835. this.n = n;
  1836. }
  1837. public Token Copy()
  1838. {
  1839. if ( this == null )
  1840. return null;
  1841. else
  1842. {
  1843. Token cp = (Token)MemberwiseClone();
  1844. if ( z == null || z.Length == 0 )
  1845. cp.n = 0;
  1846. else
  1847. if ( n > z.Length )
  1848. cp.n = z.Length;
  1849. return cp;
  1850. }
  1851. }
  1852. }
  1853. /*
  1854. ** An instance of this structure contains information needed to generate
  1855. ** code for a SELECT that contains aggregate functions.
  1856. **
  1857. ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
  1858. ** pointer to this structure. The Expr.iColumn field is the index in
  1859. ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
  1860. ** code for that node.
  1861. **
  1862. ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
  1863. ** original Select structure that describes the SELECT statement. These
  1864. ** fields do not need to be freed when deallocating the AggInfo structure.
  1865. */
  1866. public class AggInfo_col
  1867. { /* For each column used in source tables */
  1868. public Table pTab; /* Source table */
  1869. public int iTable; /* VdbeCursor number of the source table */
  1870. public int iColumn; /* Column number within the source table */
  1871. public int iSorterColumn; /* Column number in the sorting index */
  1872. public int iMem; /* Memory location that acts as accumulator */
  1873. public Expr pExpr; /* The original expression */
  1874. };
  1875. public class AggInfo_func
  1876. { /* For each aggregate function */
  1877. public Expr pExpr; /* Expression encoding the function */
  1878. public FuncDef pFunc; /* The aggregate function implementation */
  1879. public int iMem; /* Memory location that acts as accumulator */
  1880. public int iDistinct; /* Ephemeral table used to enforce DISTINCT */
  1881. }
  1882. public class AggInfo
  1883. {
  1884. public u8 directMode; /* Direct rendering mode means take data directly
  1885. ** from source tables rather than from accumulators */
  1886. public u8 useSortingIdx; /* In direct mode, reference the sorting index rather
  1887. ** than the source table */
  1888. public int sortingIdx; /* VdbeCursor number of the sorting index */
  1889. public ExprList pGroupBy; /* The group by clause */
  1890. public int nSortingColumn; /* Number of columns in the sorting index */
  1891. public AggInfo_col[] aCol;
  1892. public int nColumn; /* Number of used entries in aCol[] */
  1893. public int nColumnAlloc; /* Number of slots allocated for aCol[] */
  1894. public int nAccumulator; /* Number of columns that show through to the output.
  1895. ** Additional columns are used only as parameters to
  1896. ** aggregate functions */
  1897. public AggInfo_func[] aFunc;
  1898. public int nFunc; /* Number of entries in aFunc[] */
  1899. public int nFuncAlloc; /* Number of slots allocated for aFunc[] */
  1900. public AggInfo Copy()
  1901. {
  1902. if ( this == null )
  1903. return null;
  1904. else
  1905. {
  1906. AggInfo cp = (AggInfo)MemberwiseClone();
  1907. if ( pGroupBy != null )
  1908. cp.pGroupBy = pGroupBy.Copy();
  1909. return cp;
  1910. }
  1911. }
  1912. };
  1913. /*
  1914. ** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
  1915. ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater
  1916. ** than 32767 we have to make it 32-bit. 16-bit is preferred because
  1917. ** it uses less memory in the Expr object, which is a big memory user
  1918. ** in systems with lots of prepared statements. And few applications
  1919. ** need more than about 10 or 20 variables. But some extreme users want
  1920. ** to have prepared statements with over 32767 variables, and for them
  1921. ** the option is available (at compile-time).
  1922. */
  1923. //#if SQLITE_MAX_VARIABLE_NUMBER<=32767
  1924. //typedef i16 ynVar;
  1925. //#else
  1926. //typedef int ynVar;
  1927. //#endif
  1928. /*
  1929. ** Each node of an expression in the parse tree is an instance
  1930. ** of this structure.
  1931. **
  1932. ** Expr.op is the opcode. The integer parser token codes are reused
  1933. ** as opcodes here. For example, the parser defines TK_GE to be an integer
  1934. ** code representing the ">=" operator. This same integer code is reused
  1935. ** to represent the greater-than-or-equal-to operator in the expression
  1936. ** tree.
  1937. **
  1938. ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
  1939. ** or TK_STRING), then Expr.token contains the text of the SQL literal. If
  1940. ** the expression is a variable (TK_VARIABLE), then Expr.token contains the
  1941. ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
  1942. ** then Expr.token contains the name of the function.
  1943. **
  1944. ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
  1945. ** binary operator. Either or both may be NULL.
  1946. **
  1947. ** Expr.x.pList is a list of arguments if the expression is an SQL function,
  1948. ** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)".
  1949. ** Expr.x.pSelect is used if the expression is a sub-select or an expression of
  1950. ** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the
  1951. ** Expr.flags mask, then Expr.x.pSelect is valid. Otherwise, Expr.x.pList is
  1952. ** valid.
  1953. **
  1954. ** An expression of the form ID or ID.ID refers to a column in a table.
  1955. ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
  1956. ** the integer cursor number of a VDBE cursor pointing to that table and
  1957. ** Expr.iColumn is the column number for the specific column. If the
  1958. ** expression is used as a result in an aggregate SELECT, then the
  1959. ** value is also stored in the Expr.iAgg column in the aggregate so that
  1960. ** it can be accessed after all aggregates are computed.
  1961. **
  1962. ** If the expression is an unbound variable marker (a question mark
  1963. ** character '?' in the original SQL) then the Expr.iTable holds the index
  1964. ** number for that variable.
  1965. **
  1966. ** If the expression is a subquery then Expr.iColumn holds an integer
  1967. ** register number containing the result of the subquery. If the
  1968. ** subquery gives a constant result, then iTable is -1. If the subquery
  1969. ** gives a different answer at different times during statement processing
  1970. ** then iTable is the address of a subroutine that computes the subquery.
  1971. **
  1972. ** If the Expr is of type OP_Column, and the table it is selecting from
  1973. ** is a disk table or the "old.*" pseudo-table, then pTab points to the
  1974. ** corresponding table definition.
  1975. **
  1976. ** ALLOCATION NOTES:
  1977. **
  1978. ** Expr objects can use a lot of memory space in database schema. To
  1979. ** help reduce memory requirements, sometimes an Expr object will be
  1980. ** truncated. And to reduce the number of memory allocations, sometimes
  1981. ** two or more Expr objects will be stored in a single memory allocation,
  1982. ** together with Expr.zToken strings.
  1983. **
  1984. ** If the EP_Reduced and EP_TokenOnly flags are set when
  1985. ** an Expr object is truncated. When EP_Reduced is set, then all
  1986. ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
  1987. ** are contained within the same memory allocation. Note, however, that
  1988. ** the subtrees in Expr.x.pList or Expr.x.pSelect are always separately
  1989. ** allocated, regardless of whether or not EP_Reduced is set.
  1990. */
  1991. public class Expr
  1992. {
  1993. #if DEBUG_CLASS_EXPR || DEBUG_CLASS_ALL
  1994. public u8 _op; /* Operation performed by this node */
  1995. public u8 op
  1996. {
  1997. get { return _op; }
  1998. set { _op = value; }
  1999. }
  2000. #else
  2001. public u8 op; /* Operation performed by this node */
  2002. #endif
  2003. public char affinity; /* The affinity of the column or 0 if not a column */
  2004. #if DEBUG_CLASS_EXPR || DEBUG_CLASS_ALL
  2005. public u16 _flags; /* Various flags. EP_* See below */
  2006. public u16 flags
  2007. {
  2008. get { return _flags; }
  2009. set { _flags = value; }
  2010. }
  2011. public struct _u
  2012. {
  2013. public string _zToken; /* Token value. Zero terminated and dequoted */
  2014. public string zToken
  2015. {
  2016. get { return _zToken; }
  2017. set { _zToken = value; }
  2018. }
  2019. public int iValue; /* Integer value if EP_IntValue */
  2020. }
  2021. #else
  2022. public struct _u
  2023. {
  2024. public string zToken; /* Token value. Zero terminated and dequoted */
  2025. public int iValue; /* Integer value if EP_IntValue */
  2026. }
  2027. public u16 flags; /* Various flags. EP_* See below */
  2028. #endif
  2029. public _u u;
  2030. /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no
  2031. ** space is allocated for the fields below this point. An attempt to
  2032. ** access them will result in a segfault or malfunction.
  2033. *********************************************************************/
  2034. public Expr pLeft; /* Left subnode */
  2035. public Expr pRight; /* Right subnode */
  2036. public struct _x
  2037. {
  2038. public ExprList pList; /* Function arguments or in "<expr> IN (<expr-list)" */
  2039. public Select pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */
  2040. }
  2041. public _x x;
  2042. public CollSeq pColl; /* The collation type of the column or 0 */
  2043. /* If the EP_Reduced flag is set in the Expr.flags mask, then no
  2044. ** space is allocated for the fields below this point. An attempt to
  2045. ** access them will result in a segfault or malfunction.
  2046. *********************************************************************/
  2047. public int iTable; /* TK_COLUMN: cursor number of table holding column
  2048. ** TK_REGISTER: register number
  2049. ** TK_TRIGGER: 1 -> new, 0 -> old */
  2050. public ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
  2051. ** TK_VARIABLE: variable number (always >= 1). */
  2052. public i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  2053. public i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
  2054. public u8 flags2; /* Second set of flags. EP2_... */
  2055. public u8 op2; /* If a TK_REGISTER, the original value of Expr.op */
  2056. public AggInfo pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  2057. public Table pTab; /* Table for TK_COLUMN expressions. */
  2058. #if SQLITE_MAX_EXPR_DEPTH //>0
  2059. public int nHeight; /* Height of the tree headed by this node */
  2060. public Table pZombieTab; /* List of Table objects to delete after code gen */
  2061. #endif
  2062. #if DEBUG_CLASS
  2063. public int op
  2064. {
  2065. get { return _op; }
  2066. set { _op = value; }
  2067. }
  2068. #endif
  2069. public void CopyFrom( Expr cf )
  2070. {
  2071. op = cf.op;
  2072. affinity = cf.affinity;
  2073. flags = cf.flags;
  2074. u = cf.u;
  2075. pColl = cf.pColl == null ? null : cf.pColl.Copy();
  2076. iTable = cf.iTable;
  2077. iColumn = cf.iColumn;
  2078. pAggInfo = cf.pAggInfo == null ? null : cf.pAggInfo.Copy();
  2079. iAgg = cf.iAgg;
  2080. iRightJoinTable = cf.iRightJoinTable;
  2081. flags2 = cf.flags2;
  2082. pTab = cf.pTab == null ? null : cf.pTab;
  2083. #if SQLITE_TEST || SQLITE_MAX_EXPR_DEPTH //SQLITE_MAX_EXPR_DEPTH>0
  2084. nHeight = cf.nHeight;
  2085. pZombieTab = cf.pZombieTab;
  2086. #endif
  2087. pLeft = cf.pLeft == null ? null : cf.pLeft.Copy();
  2088. pRight = cf.pRight == null ? null : cf.pRight.Copy();
  2089. x.pList = cf.x.pList == null ? null : cf.x.pList.Copy();
  2090. x.pSelect = cf.x.pSelect == null ? null : cf.x.pSelect.Copy();
  2091. }
  2092. public Expr Copy()
  2093. {
  2094. if ( this == null )
  2095. return null;
  2096. else
  2097. return Copy( flags );
  2098. }
  2099. public Expr Copy( int flag )
  2100. {
  2101. Expr cp = new Expr();
  2102. cp.op = op;
  2103. cp.affinity = affinity;
  2104. cp.flags = flags;
  2105. cp.u = u;
  2106. if ( ( flag & EP_TokenOnly ) != 0 )
  2107. return cp;
  2108. if ( pLeft != null )
  2109. cp.pLeft = pLeft.Copy();
  2110. if ( pRight != null )
  2111. cp.pRight = pRight.Copy();
  2112. cp.x = x;
  2113. cp.pColl = pColl;
  2114. if ( ( flag & EP_Reduced ) != 0 )
  2115. return cp;
  2116. cp.iTable = iTable;
  2117. cp.iColumn = iColumn;
  2118. cp.iAgg = iAgg;
  2119. cp.iRightJoinTable = iRightJoinTable;
  2120. cp.flags2 = flags2;
  2121. cp.op2 = op2;
  2122. cp.pAggInfo = pAggInfo;
  2123. cp.pTab = pTab;
  2124. #if SQLITE_MAX_EXPR_DEPTH //>0
  2125. cp.nHeight = nHeight;
  2126. cp.pZombieTab = pZombieTab;
  2127. #endif
  2128. return cp;
  2129. }
  2130. };
  2131. /*
  2132. ** The following are the meanings of bits in the Expr.flags field.
  2133. */
  2134. //#define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
  2135. //#define EP_Agg 0x0002 /* Contains one or more aggregate functions */
  2136. //#define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */
  2137. //#define EP_Error 0x0008 /* Expression contains one or more errors */
  2138. //#define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */
  2139. //#define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */
  2140. //#define EP_DblQuoted 0x0040 /* token.z was originally in "..." */
  2141. //#define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */
  2142. //#define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */
  2143. //#define EP_FixedDest 0x0200 /* Result needed in a specific register */
  2144. //#define EP_IntValue 0x0400 /* Integer value contained in u.iValue */
  2145. //#define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */
  2146. //#define EP_Reduced 0x1000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */
  2147. //#define EP_TokenOnly 0x2000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */
  2148. //#define EP_Static 0x4000 /* Held in memory not obtained from malloc() */
  2149. const ushort EP_FromJoin = 0x0001;
  2150. const ushort EP_Agg = 0x0002;
  2151. const ushort EP_Resolved = 0x0004;
  2152. const ushort EP_Error = 0x0008;
  2153. const ushort EP_Distinct = 0x0010;
  2154. const ushort EP_VarSelect = 0x0020;
  2155. const ushort EP_DblQuoted = 0x0040;
  2156. const ushort EP_InfixFunc = 0x0080;
  2157. const ushort EP_ExpCollate = 0x0100;
  2158. const ushort EP_FixedDest = 0x0200;
  2159. const ushort EP_IntValue = 0x0400;
  2160. const ushort EP_xIsSelect = 0x0800;
  2161. const ushort EP_Reduced = 0x1000;
  2162. const ushort EP_TokenOnly = 0x2000;
  2163. const ushort EP_Static = 0x4000;
  2164. /*
  2165. ** The following are the meanings of bits in the Expr.flags2 field.
  2166. */
  2167. //#define EP2_MallocedToken 0x0001 /* Need to sqlite3DbFree() Expr.zToken */
  2168. //#define EP2_Irreducible 0x0002 /* Cannot EXPRDUP_REDUCE this Expr */
  2169. const u8 EP2_MallocedToken = 0x0001;
  2170. const u8 EP2_Irreducible = 0x0002;
  2171. /*
  2172. ** The pseudo-routine sqlite3ExprSetIrreducible sets the EP2_Irreducible
  2173. ** flag on an expression structure. This flag is used for VV&A only. The
  2174. ** routine is implemented as a macro that only works when in debugging mode,
  2175. ** so as not to burden production code.
  2176. */
  2177. #if SQLITE_DEBUG
  2178. //# define ExprSetIrreducible(X) (X)->flags2 |= EP2_Irreducible
  2179. static void ExprSetIrreducible( Expr X )
  2180. {
  2181. X.flags2 |= EP2_Irreducible;
  2182. }
  2183. #else
  2184. //# define ExprSetIrreducible(X)
  2185. static void ExprSetIrreducible( Expr X ) { }
  2186. #endif
  2187. /*
  2188. ** These macros can be used to test, set, or clear bits in the
  2189. ** Expr.flags field.
  2190. */
  2191. //#define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
  2192. static bool ExprHasProperty( Expr E, int P )
  2193. {
  2194. return ( E.flags & P ) == P;
  2195. }
  2196. //#define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
  2197. static bool ExprHasAnyProperty( Expr E, int P )
  2198. {
  2199. return ( E.flags & P ) != 0;
  2200. }
  2201. //#define ExprSetProperty(E,P) (E)->flags|=(P)
  2202. static void ExprSetProperty( Expr E, int P )
  2203. {
  2204. E.flags = (ushort)( E.flags | P );
  2205. }
  2206. //#define ExprClearProperty(E,P) (E)->flags&=~(P)
  2207. static void ExprClearProperty( Expr E, int P )
  2208. {
  2209. E.flags = (ushort)( E.flags & ~P );
  2210. }
  2211. /*
  2212. ** Macros to determine the number of bytes required by a normal Expr
  2213. ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
  2214. ** and an Expr struct with the EP_TokenOnly flag set.
  2215. */
  2216. //#define EXPR_FULLSIZE sizeof(Expr) /* Full size */
  2217. //#define EXPR_REDUCEDSIZE offsetof(Expr,iTable) /* Common features */
  2218. //#define EXPR_TOKENONLYSIZE offsetof(Expr,pLeft) /* Fewer features */
  2219. // We don't use these in C#, but define them anyway,
  2220. const int EXPR_FULLSIZE = 48;
  2221. const int EXPR_REDUCEDSIZE = 24;
  2222. const int EXPR_TOKENONLYSIZE = 8;
  2223. /*
  2224. ** Flags passed to the sqlite3ExprDup() function. See the header comment
  2225. ** above sqlite3ExprDup() for details.
  2226. */
  2227. //#define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */
  2228. const int EXPRDUP_REDUCE = 0x0001;
  2229. /*
  2230. ** A list of expressions. Each expression may optionally have a
  2231. ** name. An expr/name combination can be used in several ways, such
  2232. ** as the list of "expr AS ID" fields following a "SELECT" or in the
  2233. ** list of "ID = expr" items in an UPDATE. A list of expressions can
  2234. ** also be used as the argument to a function, in which case the a.zName
  2235. ** field is not used.
  2236. */
  2237. public class ExprList_item
  2238. {
  2239. public Expr pExpr; /* The list of expressions */
  2240. public string zName; /* Token associated with this expression */
  2241. public string zSpan; /* Original text of the expression */
  2242. public u8 sortOrder; /* 1 for DESC or 0 for ASC */
  2243. public u8 done; /* A flag to indicate when processing is finished */
  2244. public u16 iCol; /* For ORDER BY, column number in result set */
  2245. public u16 iAlias; /* Index into Parse.aAlias[] for zName */
  2246. }
  2247. public class ExprList
  2248. {
  2249. public int nExpr; /* Number of expressions on the list */
  2250. public int nAlloc; /* Number of entries allocated below */
  2251. public int iECursor; /* VDBE VdbeCursor associated with this ExprList */
  2252. public ExprList_item[] a; /* One entry for each expression */
  2253. public ExprList Copy()
  2254. {
  2255. if ( this == null )
  2256. return null;
  2257. else
  2258. {
  2259. ExprList cp = (ExprList)MemberwiseClone();
  2260. a.CopyTo( cp.a, 0 );
  2261. return cp;
  2262. }
  2263. }
  2264. };
  2265. /*
  2266. ** An instance of this structure is used by the parser to record both
  2267. ** the parse tree for an expression and the span of input text for an
  2268. ** expression.
  2269. */
  2270. public class ExprSpan
  2271. {
  2272. public Expr pExpr; /* The expression parse tree */
  2273. public string zStart; /* First character of input text */
  2274. public string zEnd; /* One character past the end of input text */
  2275. };
  2276. /*
  2277. ** An instance of this structure can hold a simple list of identifiers,
  2278. ** such as the list "a,b,c" in the following statements:
  2279. **
  2280. ** INSERT INTO t(a,b,c) VALUES ...;
  2281. ** CREATE INDEX idx ON t(a,b,c);
  2282. ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
  2283. **
  2284. ** The IdList.a.idx field is used when the IdList represents the list of
  2285. ** column names after a table name in an INSERT statement. In the statement
  2286. **
  2287. ** INSERT INTO t(a,b,c) ...
  2288. **
  2289. ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
  2290. */
  2291. public class IdList_item
  2292. {
  2293. public string zName; /* Name of the identifier */
  2294. public int idx; /* Index in some Table.aCol[] of a column named zName */
  2295. }
  2296. public class IdList
  2297. {
  2298. public IdList_item[] a;
  2299. public int nId; /* Number of identifiers on the list */
  2300. public int nAlloc; /* Number of entries allocated for a[] below */
  2301. public IdList Copy()
  2302. {
  2303. if ( this == null )
  2304. return null;
  2305. else
  2306. {
  2307. IdList cp = (IdList)MemberwiseClone();
  2308. a.CopyTo( cp.a, 0 );
  2309. return cp;
  2310. }
  2311. }
  2312. };
  2313. /*
  2314. ** The bitmask datatype defined below is used for various optimizations.
  2315. **
  2316. ** Changing this from a 64-bit to a 32-bit type limits the number of
  2317. ** tables in a join to 32 instead of 64. But it also reduces the size
  2318. ** of the library by 738 bytes on ix86.
  2319. */
  2320. //typedef u64 Bitmask;
  2321. /*
  2322. ** The number of bits in a Bitmask. "BMS" means "BitMask Size".
  2323. */
  2324. //#define BMS ((int)(sizeof(Bitmask)*8))
  2325. const int BMS = ( (int)( sizeof( Bitmask ) * 8 ) );
  2326. /*
  2327. ** The following structure describes the FROM clause of a SELECT statement.
  2328. ** Each table or subquery in the FROM clause is a separate element of
  2329. ** the SrcList.a[] array.
  2330. **
  2331. ** With the addition of multiple database support, the following structure
  2332. ** can also be used to describe a particular table such as the table that
  2333. ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
  2334. ** such a table must be a simple name: ID. But in SQLite, the table can
  2335. ** now be identified by a database name, a dot, then the table name: ID.ID.
  2336. **
  2337. ** The jointype starts out showing the join type between the current table
  2338. ** and the next table on the list. The parser builds the list this way.
  2339. ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
  2340. ** jointype expresses the join between the table and the previous table.
  2341. **
  2342. ** In the colUsed field, the high-order bit (bit 63) is set if the table
  2343. ** contains more than 63 columns and the 64-th or later column is used.
  2344. */
  2345. public class SrcList_item
  2346. {
  2347. public string zDatabase; /* Name of database holding this table */
  2348. public string zName; /* Name of the table */
  2349. public string zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
  2350. public Table pTab; /* An SQL table corresponding to zName */
  2351. public Select pSelect; /* A SELECT statement used in place of a table name */
  2352. public u8 isPopulated; /* Temporary table associated with SELECT is populated */
  2353. public u8 jointype; /* Type of join between this able and the previous */
  2354. public u8 notIndexed; /* True if there is a NOT INDEXED clause */
  2355. #if !SQLITE_OMIT_EXPLAIN
  2356. public u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
  2357. #endif
  2358. public int iCursor; /* The VDBE cursor number used to access this table */
  2359. public Expr pOn; /* The ON clause of a join */
  2360. public IdList pUsing; /* The USING clause of a join */
  2361. public Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
  2362. public string zIndex; /* Identifier from "INDEXED BY <zIndex>" clause */
  2363. public Index pIndex; /* Index structure corresponding to zIndex, if any */
  2364. }
  2365. public class SrcList
  2366. {
  2367. public i16 nSrc; /* Number of tables or subqueries in the FROM clause */
  2368. public i16 nAlloc; /* Number of entries allocated in a[] below */
  2369. public SrcList_item[] a;/* One entry for each identifier on the list */
  2370. public SrcList Copy()
  2371. {
  2372. if ( this == null )
  2373. return null;
  2374. else
  2375. {
  2376. SrcList cp = (SrcList)MemberwiseClone();
  2377. if ( a != null )
  2378. a.CopyTo( cp.a, 0 );
  2379. return cp;
  2380. }
  2381. }
  2382. };
  2383. /*
  2384. ** Permitted values of the SrcList.a.jointype field
  2385. */
  2386. const int JT_INNER = 0x0001; //#define JT_INNER 0x0001 /* Any kind of inner or cross join */
  2387. const int JT_CROSS = 0x0002; //#define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */
  2388. const int JT_NATURAL = 0x0004; //#define JT_NATURAL 0x0004 /* True for a "natural" join */
  2389. const int JT_LEFT = 0x0008; //#define JT_LEFT 0x0008 /* Left outer join */
  2390. const int JT_RIGHT = 0x0010; //#define JT_RIGHT 0x0010 /* Right outer join */
  2391. const int JT_OUTER = 0x0020; //#define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
  2392. const int JT_ERROR = 0x0040; //#define JT_ERROR 0x0040 /* unknown or unsupported join type */
  2393. /*
  2394. ** A WherePlan object holds information that describes a lookup
  2395. ** strategy.
  2396. **
  2397. ** This object is intended to be opaque outside of the where.c module.
  2398. ** It is included here only so that that compiler will know how big it
  2399. ** is. None of the fields in this object should be used outside of
  2400. ** the where.c module.
  2401. **
  2402. ** Within the union, pIdx is only used when wsFlags&WHERE_INDEXED is true.
  2403. ** pTerm is only used when wsFlags&WHERE_MULTI_OR is true. And pVtabIdx
  2404. ** is only used when wsFlags&WHERE_VIRTUALTABLE is true. It is never the
  2405. ** case that more than one of these conditions is true.
  2406. */
  2407. public class WherePlan
  2408. {
  2409. public u32 wsFlags; /* WHERE_* flags that describe the strategy */
  2410. public u32 nEq; /* Number of == constraints */
  2411. public double nRow; /* Estimated number of rows (for EQP) */
  2412. public class _u
  2413. {
  2414. public Index pIdx; /* Index when WHERE_INDEXED is true */
  2415. public WhereTerm pTerm; /* WHERE clause term for OR-search */
  2416. public sqlite3_index_info pVtabIdx; /* Virtual table index to use */
  2417. }
  2418. public _u u = new _u();
  2419. public void Clear()
  2420. {
  2421. wsFlags = 0;
  2422. nEq = 0;
  2423. nRow = 0;
  2424. u.pIdx = null;
  2425. u.pTerm = null;
  2426. u.pVtabIdx = null;
  2427. }
  2428. };
  2429. /*
  2430. ** For each nested loop in a WHERE clause implementation, the WhereInfo
  2431. ** structure contains a single instance of this structure. This structure
  2432. ** is intended to be private the the where.c module and should not be
  2433. ** access or modified by other modules.
  2434. **
  2435. ** The pIdxInfo field is used to help pick the best index on a
  2436. ** virtual table. The pIdxInfo pointer contains indexing
  2437. ** information for the i-th table in the FROM clause before reordering.
  2438. ** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
  2439. ** All other information in the i-th WhereLevel object for the i-th table
  2440. ** after FROM clause ordering.
  2441. */
  2442. public class InLoop
  2443. {
  2444. public int iCur; /* The VDBE cursor used by this IN operator */
  2445. public int addrInTop; /* Top of the IN loop */
  2446. }
  2447. public class WhereLevel
  2448. {
  2449. public WherePlan plan; /* query plan for this element of the FROM clause */
  2450. public int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
  2451. public int iTabCur; /* The VDBE cursor used to access the table */
  2452. public int iIdxCur; /* The VDBE cursor used to access pIdx */
  2453. public int addrBrk; /* Jump here to break out of the loop */
  2454. public int addrNxt; /* Jump here to start the next IN combination */
  2455. public int addrCont; /* Jump here to continue with the next loop cycle */
  2456. public int addrFirst; /* First instruction of interior of the loop */
  2457. public u8 iFrom; /* Which entry in the FROM clause */
  2458. public u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
  2459. public int p1, p2; /* Operands of the opcode used to ends the loop */
  2460. public class _u
  2461. {
  2462. public class __in /* Information that depends on plan.wsFlags */
  2463. {
  2464. public int nIn; /* Number of entries in aInLoop[] */
  2465. public InLoop[] aInLoop; /* Information about each nested IN operator */
  2466. }
  2467. public __in _in = new __in(); /* Used when plan.wsFlags&WHERE_IN_ABLE */
  2468. }
  2469. public _u u = new _u();
  2470. /* The following field is really not part of the current level. But
  2471. ** we need a place to cache virtual table index information for each
  2472. ** virtual table in the FROM clause and the WhereLevel structure is
  2473. ** a convenient place since there is one WhereLevel for each FROM clause
  2474. ** element.
  2475. */
  2476. public sqlite3_index_info pIdxInfo; /* Index info for n-th source table */
  2477. };
  2478. /*
  2479. ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
  2480. ** and the WhereInfo.wctrlFlags member.
  2481. */
  2482. //#define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
  2483. //#define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
  2484. //#define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
  2485. //#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
  2486. //#define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
  2487. //#define WHERE_OMIT_OPEN 0x0010 /* Table cursors are already open */
  2488. //#define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
  2489. //#define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
  2490. //#define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
  2491. const int WHERE_ORDERBY_NORMAL = 0x0000;
  2492. const int WHERE_ORDERBY_MIN = 0x0001;
  2493. const int WHERE_ORDERBY_MAX = 0x0002;
  2494. const int WHERE_ONEPASS_DESIRED = 0x0004;
  2495. const int WHERE_DUPLICATES_OK = 0x0008;
  2496. const int WHERE_OMIT_OPEN = 0x0010;
  2497. const int WHERE_OMIT_CLOSE = 0x0020;
  2498. const int WHERE_FORCE_TABLE = 0x0040;
  2499. const int WHERE_ONETABLE_ONLY = 0x0080;
  2500. /*
  2501. ** The WHERE clause processing routine has two halves. The
  2502. ** first part does the start of the WHERE loop and the second
  2503. ** half does the tail of the WHERE loop. An instance of
  2504. ** this structure is returned by the first half and passed
  2505. ** into the second half to give some continuity.
  2506. */
  2507. public class WhereInfo
  2508. {
  2509. public Parse pParse; /* Parsing and code generating context */
  2510. public u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
  2511. public u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE or DELETE */
  2512. public u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
  2513. public SrcList pTabList; /* List of tables in the join */
  2514. public int iTop; /* The very beginning of the WHERE loop */
  2515. public int iContinue; /* Jump here to continue with next record */
  2516. public int iBreak; /* Jump here to break out of the loop */
  2517. public int nLevel; /* Number of nested loop */
  2518. public WhereClause pWC; /* Decomposition of the WHERE clause */
  2519. public double savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
  2520. public double nRowOut; /* Estimated number of output rows */
  2521. public WhereLevel[] a = new WhereLevel[] { new WhereLevel() }; /* Information about each nest loop in the WHERE */
  2522. };
  2523. /*
  2524. ** A NameContext defines a context in which to resolve table and column
  2525. ** names. The context consists of a list of tables (the pSrcList) field and
  2526. ** a list of named expression (pEList). The named expression list may
  2527. ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or
  2528. ** to the table being operated on by INSERT, UPDATE, or DELETE. The
  2529. ** pEList corresponds to the result set of a SELECT and is NULL for
  2530. ** other statements.
  2531. **
  2532. ** NameContexts can be nested. When resolving names, the inner-most
  2533. ** context is searched first. If no match is found, the next outer
  2534. ** context is checked. If there is still no match, the next context
  2535. ** is checked. This process continues until either a match is found
  2536. ** or all contexts are check. When a match is found, the nRef member of
  2537. ** the context containing the match is incremented.
  2538. **
  2539. ** Each subquery gets a new NameContext. The pNext field points to the
  2540. ** NameContext in the parent query. Thus the process of scanning the
  2541. ** NameContext list corresponds to searching through successively outer
  2542. ** subqueries looking for a match.
  2543. */
  2544. public class NameContext
  2545. {
  2546. public Parse pParse; /* The parser */
  2547. public SrcList pSrcList; /* One or more tables used to resolve names */
  2548. public ExprList pEList; /* Optional list of named expressions */
  2549. public int nRef; /* Number of names resolved by this context */
  2550. public int nErr; /* Number of errors encountered while resolving names */
  2551. public u8 allowAgg; /* Aggregate functions allowed here */
  2552. public u8 hasAgg; /* True if aggregates are seen */
  2553. public u8 isCheck; /* True if resolving names in a CHECK constraint */
  2554. public int nDepth; /* Depth of subquery recursion. 1 for no recursion */
  2555. public AggInfo pAggInfo; /* Information about aggregates at this level */
  2556. public NameContext pNext; /* Next outer name context. NULL for outermost */
  2557. };
  2558. /*
  2559. ** An instance of the following structure contains all information
  2560. ** needed to generate code for a single SELECT statement.
  2561. **
  2562. ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.
  2563. ** If there is a LIMIT clause, the parser sets nLimit to the value of the
  2564. ** limit and nOffset to the value of the offset (or 0 if there is not
  2565. ** offset). But later on, nLimit and nOffset become the memory locations
  2566. ** in the VDBE that record the limit and offset counters.
  2567. **
  2568. ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.
  2569. ** These addresses must be stored so that we can go back and fill in
  2570. ** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor
  2571. ** the number of columns in P2 can be computed at the same time
  2572. ** as the OP_OpenEphm instruction is coded because not
  2573. ** enough information about the compound query is known at that point.
  2574. ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
  2575. ** for the result set. The KeyInfo for addrOpenTran[2] contains collating
  2576. ** sequences for the ORDER BY clause.
  2577. */
  2578. public class Select
  2579. {
  2580. public ExprList pEList; /* The fields of the result */
  2581. public u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
  2582. public char affinity; /* MakeRecord with this affinity for SRT_Set */
  2583. public u16 selFlags; /* Various SF_* values */
  2584. public SrcList pSrc; /* The FROM clause */
  2585. public Expr pWhere; /* The WHERE clause */
  2586. public ExprList pGroupBy; /* The GROUP BY clause */
  2587. public Expr pHaving; /* The HAVING clause */
  2588. public ExprList pOrderBy; /* The ORDER BY clause */
  2589. public Select pPrior; /* Prior select in a compound select statement */
  2590. public Select pNext; /* Next select to the left in a compound */
  2591. public Select pRightmost; /* Right-most select in a compound select statement */
  2592. public Expr pLimit; /* LIMIT expression. NULL means not used. */
  2593. public Expr pOffset; /* OFFSET expression. NULL means not used. */
  2594. public int iLimit;
  2595. public int iOffset; /* Memory registers holding LIMIT & OFFSET counters */
  2596. public int[] addrOpenEphm = new int[3]; /* OP_OpenEphem opcodes related to this select */
  2597. public double nSelectRow; /* Estimated number of result rows */
  2598. public Select Copy()
  2599. {
  2600. if ( this == null )
  2601. return null;
  2602. else
  2603. {
  2604. Select cp = (Select)MemberwiseClone();
  2605. if ( pEList != null )
  2606. cp.pEList = pEList.Copy();
  2607. if ( pSrc != null )
  2608. cp.pSrc = pSrc.Copy();
  2609. if ( pWhere != null )
  2610. cp.pWhere = pWhere.Copy();
  2611. if ( pGroupBy != null )
  2612. cp.pGroupBy = pGroupBy.Copy();
  2613. if ( pHaving != null )
  2614. cp.pHaving = pHaving.Copy();
  2615. if ( pOrderBy != null )
  2616. cp.pOrderBy = pOrderBy.Copy();
  2617. if ( pPrior != null )
  2618. cp.pPrior = pPrior.Copy();
  2619. if ( pNext != null )
  2620. cp.pNext = pNext.Copy();
  2621. if ( pRightmost != null )
  2622. cp.pRightmost = pRightmost.Copy();
  2623. if ( pLimit != null )
  2624. cp.pLimit = pLimit.Copy();
  2625. if ( pOffset != null )
  2626. cp.pOffset = pOffset.Copy();
  2627. return cp;
  2628. }
  2629. }
  2630. };
  2631. /*
  2632. ** Allowed values for Select.selFlags. The "SF" prefix stands for
  2633. ** "Select Flag".
  2634. */
  2635. //#define SF_Distinct 0x0001 /* Output should be DISTINCT */
  2636. //#define SF_Resolved 0x0002 /* Identifiers have been resolved */
  2637. //#define SF_Aggregate 0x0004 /* Contains aggregate functions */
  2638. //#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
  2639. //#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
  2640. //#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
  2641. const int SF_Distinct = 0x0001; /* Output should be DISTINCT */
  2642. const int SF_Resolved = 0x0002; /* Identifiers have been resolved */
  2643. const int SF_Aggregate = 0x0004; /* Contains aggregate functions */
  2644. const int SF_UsesEphemeral = 0x0008; /* Uses the OpenEphemeral opcode */
  2645. const int SF_Expanded = 0x0010; /* sqlite3SelectExpand() called on this */
  2646. const int SF_HasTypeInfo = 0x0020; /* FROM subqueries have Table metadata */
  2647. /*
  2648. ** The results of a select can be distributed in several ways. The
  2649. ** "SRT" prefix means "SELECT Result Type".
  2650. */
  2651. const int SRT_Union = 1;//#define SRT_Union 1 /* Store result as keys in an index */
  2652. const int SRT_Except = 2;//#define SRT_Except 2 /* Remove result from a UNION index */
  2653. const int SRT_Exists = 3;//#define SRT_Exists 3 /* Store 1 if the result is not empty */
  2654. const int SRT_Discard = 4;//#define SRT_Discard 4 /* Do not save the results anywhere */
  2655. /* The ORDER BY clause is ignored for all of the above */
  2656. //#define IgnorableOrderby(X) ((X->eDest)<=SRT_Discard)
  2657. const int SRT_Output = 5;//#define SRT_Output 5 /* Output each row of result */
  2658. const int SRT_Mem = 6;//#define SRT_Mem 6 /* Store result in a memory cell */
  2659. const int SRT_Set = 7;//#define SRT_Set 7 /* Store results as keys in an index */
  2660. const int SRT_Table = 8;//#define SRT_Table 8 /* Store result as data with an automatic rowid */
  2661. const int SRT_EphemTab = 9;//#define SRT_EphemTab 9 /* Create transient tab and store like SRT_Table /
  2662. const int SRT_Coroutine = 10;//#define SRT_Coroutine 10 /* Generate a single row of result */
  2663. /*
  2664. ** A structure used to customize the behavior of sqlite3Select(). See
  2665. ** comments above sqlite3Select() for details.
  2666. */
  2667. //typedef struct SelectDest SelectDest;
  2668. public class SelectDest
  2669. {
  2670. public u8 eDest; /* How to dispose of the results */
  2671. public char affinity; /* Affinity used when eDest==SRT_Set */
  2672. public int iParm; /* A parameter used by the eDest disposal method */
  2673. public int iMem; /* Base register where results are written */
  2674. public int nMem; /* Number of registers allocated */
  2675. public SelectDest()
  2676. {
  2677. this.eDest = 0;
  2678. this.affinity = '\0';
  2679. this.iParm = 0;
  2680. this.iMem = 0;
  2681. this.nMem = 0;
  2682. }
  2683. public SelectDest( u8 eDest, char affinity, int iParm )
  2684. {
  2685. this.eDest = eDest;
  2686. this.affinity = affinity;
  2687. this.iParm = iParm;
  2688. this.iMem = 0;
  2689. this.nMem = 0;
  2690. }
  2691. public SelectDest( u8 eDest, char affinity, int iParm, int iMem, int nMem )
  2692. {
  2693. this.eDest = eDest;
  2694. this.affinity = affinity;
  2695. this.iParm = iParm;
  2696. this.iMem = iMem;
  2697. this.nMem = nMem;
  2698. }
  2699. };
  2700. /*
  2701. ** During code generation of statements that do inserts into AUTOINCREMENT
  2702. ** tables, the following information is attached to the Table.u.autoInc.p
  2703. ** pointer of each autoincrement table to record some side information that
  2704. ** the code generator needs. We have to keep per-table autoincrement
  2705. ** information in case inserts are down within triggers. Triggers do not
  2706. ** normally coordinate their activities, but we do need to coordinate the
  2707. ** loading and saving of autoincrement information.
  2708. */
  2709. public class AutoincInfo
  2710. {
  2711. public AutoincInfo pNext; /* Next info block in a list of them all */
  2712. public Table pTab; /* Table this info block refers to */
  2713. public int iDb; /* Index in sqlite3.aDb[] of database holding pTab */
  2714. public int regCtr; /* Memory register holding the rowid counter */
  2715. };
  2716. /*
  2717. ** Size of the column cache
  2718. */
  2719. #if !SQLITE_N_COLCACHE
  2720. //# define SQLITE_N_COLCACHE 10
  2721. const int SQLITE_N_COLCACHE = 10;
  2722. #endif
  2723. /*
  2724. ** At least one instance of the following structure is created for each
  2725. ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
  2726. ** statement. All such objects are stored in the linked list headed at
  2727. ** Parse.pTriggerPrg and deleted once statement compilation has been
  2728. ** completed.
  2729. **
  2730. ** A Vdbe sub-program that implements the body and WHEN clause of trigger
  2731. ** TriggerPrg.pTrigger, assuming a default ON CONFLICT clause of
  2732. ** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable.
  2733. ** The Parse.pTriggerPrg list never contains two entries with the same
  2734. ** values for both pTrigger and orconf.
  2735. **
  2736. ** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns
  2737. ** accessed (or set to 0 for triggers fired as a result of INSERT
  2738. ** statements). Similarly, the TriggerPrg.aColmask[1] variable is set to
  2739. ** a mask of new.* columns used by the program.
  2740. */
  2741. public class TriggerPrg
  2742. {
  2743. public Trigger pTrigger; /* Trigger this program was coded from */
  2744. public int orconf; /* Default ON CONFLICT policy */
  2745. public SubProgram pProgram; /* Program implementing pTrigger/orconf */
  2746. public u32[] aColmask = new u32[2]; /* Masks of old.*, new.* columns accessed */
  2747. public TriggerPrg pNext; /* Next entry in Parse.pTriggerPrg list */
  2748. };
  2749. /*
  2750. ** An SQL parser context. A copy of this structure is passed through
  2751. ** the parser and down into all the parser action routine in order to
  2752. ** carry around information that is global to the entire parse.
  2753. **
  2754. ** The structure is divided into two parts. When the parser and code
  2755. ** generate call themselves recursively, the first part of the structure
  2756. ** is constant but the second part is reset at the beginning and end of
  2757. ** each recursion.
  2758. **
  2759. ** The nTableLock and aTableLock variables are only used if the shared-cache
  2760. ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
  2761. ** used to store the set of table-locks required by the statement being
  2762. ** compiled. Function sqlite3TableLock() is used to add entries to the
  2763. ** list.
  2764. */
  2765. public class yColCache
  2766. {
  2767. public int iTable; /* Table cursor number */
  2768. public int iColumn; /* Table column number */
  2769. public u8 tempReg; /* iReg is a temp register that needs to be freed */
  2770. public int iLevel; /* Nesting level */
  2771. public int iReg; /* Reg with value of this column. 0 means none. */
  2772. public int lru; /* Least recently used entry has the smallest value */
  2773. }
  2774. public class Parse
  2775. {
  2776. public sqlite3 db; /* The main database structure */
  2777. public int rc; /* Return code from execution */
  2778. public string zErrMsg; /* An error message */
  2779. public Vdbe pVdbe; /* An engine for executing database bytecode */
  2780. public u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
  2781. public u8 nameClash; /* A permanent table name clashes with temp table name */
  2782. public u8 checkSchema; /* Causes schema cookie check after an error */
  2783. public u8 nested; /* Number of nested calls to the parser/code generator */
  2784. public u8 parseError; /* True after a parsing error. Ticket #1794 */
  2785. public u8 nTempReg; /* Number of temporary registers in aTempReg[] */
  2786. public u8 nTempInUse; /* Number of aTempReg[] currently checked out */
  2787. public int[] aTempReg = new int[8]; /* Holding area for temporary registers */
  2788. public int nRangeReg; /* Size of the temporary register block */
  2789. public int iRangeReg; /* First register in temporary register block */
  2790. public int nErr; /* Number of errors seen */
  2791. public int nTab; /* Number of previously allocated VDBE cursors */
  2792. public int nMem; /* Number of memory cells used so far */
  2793. public int nSet; /* Number of sets used so far */
  2794. public int ckBase; /* Base register of data during check constraints */
  2795. public int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
  2796. public int iCacheCnt; /* Counter used to generate aColCache[].lru values */
  2797. public u8 nColCache; /* Number of entries in the column cache */
  2798. public u8 iColCache; /* Next entry of the cache to replace */
  2799. public yColCache[] aColCache = new yColCache[SQLITE_N_COLCACHE]; /* One for each valid column cache entry */
  2800. public u32 writeMask; /* Start a write transaction on these databases */
  2801. public u32 cookieMask; /* Bitmask of schema verified databases */
  2802. public u8 isMultiWrite; /* True if statement may affect/insert multiple rows */
  2803. public u8 mayAbort; /* True if statement may throw an ABORT exception */
  2804. public int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
  2805. public int[] cookieValue = new int[SQLITE_MAX_ATTACHED + 2]; /* Values of cookies to verify */
  2806. #if !SQLITE_OMIT_SHARED_CACHE
  2807. public int nTableLock; /* Number of locks in aTableLock */
  2808. public TableLock[] aTableLock; /* Required table locks for shared-cache mode */
  2809. #endif
  2810. public int regRowid; /* Register holding rowid of CREATE TABLE entry */
  2811. public int regRoot; /* Register holding root page number for new objects */
  2812. public AutoincInfo pAinc; /* Information about AUTOINCREMENT counters */
  2813. public int nMaxArg; /* Max args passed to user function by sub-program */
  2814. /* Information used while coding trigger programs. */
  2815. public Parse pToplevel; /* Parse structure for main program (or NULL) */
  2816. public Table pTriggerTab; /* Table triggers are being coded for */
  2817. public u32 oldmask; /* Mask of old.* columns referenced */
  2818. public u32 newmask; /* Mask of new.* columns referenced */
  2819. public u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
  2820. public u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
  2821. public u8 disableTriggers; /* True to disable triggers */
  2822. public double nQueryLoop; /* Estimated number of iterations of a query */
  2823. /* Above is constant between recursions. Below is reset before and after
  2824. ** each recursion */
  2825. public int nVar; /* Number of '?' variables seen in the SQL so far */
  2826. public int nVarExpr; /* Number of used slots in apVarExpr[] */
  2827. public int nVarExprAlloc; /* Number of allocated slots in apVarExpr[] */
  2828. public Expr[] apVarExpr; /* Pointers to :aaa and $aaaa wildcard expressions */
  2829. public Vdbe pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
  2830. public int nAlias; /* Number of aliased result set columns */
  2831. public int nAliasAlloc; /* Number of allocated slots for aAlias[] */
  2832. public int[] aAlias; /* Register used to hold aliased result */
  2833. public u8 explain; /* True if the EXPLAIN flag is found on the query */
  2834. public Token sNameToken; /* Token with unqualified schema object name */
  2835. public Token sLastToken = new Token(); /* The last token parsed */
  2836. public StringBuilder zTail; /* All SQL text past the last semicolon parsed */
  2837. public Table pNewTable; /* A table being constructed by CREATE TABLE */
  2838. public Trigger pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
  2839. public string zAuthContext; /* The 6th parameter to db.xAuth callbacks */
  2840. #if !SQLITE_OMIT_VIRTUALTABLE
  2841. public Token sArg; /* Complete text of a module argument */
  2842. public u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
  2843. public int nVtabLock; /* Number of virtual tables to lock */
  2844. public Table[] apVtabLock; /* Pointer to virtual tables needing locking */
  2845. #endif
  2846. public int nHeight; /* Expression tree height of current sub-select */
  2847. public Table pZombieTab; /* List of Table objects to delete after code gen */
  2848. public TriggerPrg pTriggerPrg; /* Linked list of coded triggers */
  2849. #if !SQLITE_OMIT_EXPLAIN
  2850. public int iSelectId;
  2851. public int iNextSelectId;
  2852. #endif
  2853. // We need to create instances of the col cache
  2854. public Parse()
  2855. {
  2856. for ( int i = 0; i < this.aColCache.Length; i++ )
  2857. {
  2858. this.aColCache[i] = new yColCache();
  2859. }
  2860. }
  2861. public void ResetMembers() // Need to clear all the following variables during each recursion
  2862. {
  2863. nVar = 0;
  2864. nVarExpr = 0;
  2865. nVarExprAlloc = 0;
  2866. apVarExpr = null;
  2867. nAlias = 0;
  2868. nAliasAlloc = 0;
  2869. aAlias = null;
  2870. explain = 0;
  2871. sNameToken = new Token();
  2872. sLastToken = new Token();
  2873. zTail.Length = 0;
  2874. pNewTable = null;
  2875. pNewTrigger = null;
  2876. zAuthContext = null;
  2877. #if !SQLITE_OMIT_VIRTUALTABLE
  2878. sArg = new Token();
  2879. declareVtab = 0;
  2880. nVtabLock = 0;
  2881. apVtabLoc = null;
  2882. #endif
  2883. nHeight = 0;
  2884. pZombieTab = null;
  2885. pTriggerPrg = null;
  2886. }
  2887. Parse[] SaveBuf = new Parse[10]; //For Recursion Storage
  2888. public void RestoreMembers() // Need to clear all the following variables during each recursion
  2889. {
  2890. if ( SaveBuf[nested] != null )
  2891. nVar = SaveBuf[nested].nVar;
  2892. nVarExpr = SaveBuf[nested].nVarExpr;
  2893. nVarExprAlloc = SaveBuf[nested].nVarExprAlloc;
  2894. apVarExpr = SaveBuf[nested].apVarExpr;
  2895. nAlias = SaveBuf[nested].nAlias;
  2896. nAliasAlloc = SaveBuf[nested].nAliasAlloc;
  2897. aAlias = SaveBuf[nested].aAlias;
  2898. explain = SaveBuf[nested].explain;
  2899. sNameToken = SaveBuf[nested].sNameToken;
  2900. sLastToken = SaveBuf[nested].sLastToken;
  2901. zTail = SaveBuf[nested].zTail;
  2902. pNewTable = SaveBuf[nested].pNewTable;
  2903. pNewTrigger = SaveBuf[nested].pNewTrigger;
  2904. zAuthContext = SaveBuf[nested].zAuthContext;
  2905. #if !SQLITE_OMIT_VIRTUALTABLE
  2906. sArg = SaveBuf[nested].sArg ;
  2907. declareVtab = SaveBuf[nested].declareVtab;
  2908. nVtabLock = SaveBuf[nested].nVtabLock;
  2909. apVtabLock = SaveBuf[nested].apVtabLock;
  2910. #endif
  2911. nHeight = SaveBuf[nested].nHeight;
  2912. pZombieTab = SaveBuf[nested].pZombieTab;
  2913. pTriggerPrg = SaveBuf[nested].pTriggerPrg;
  2914. SaveBuf[nested] = null;
  2915. }
  2916. public void SaveMembers() // Need to clear all the following variables during each recursion
  2917. {
  2918. SaveBuf[nested] = new Parse();
  2919. SaveBuf[nested].nVar = nVar;
  2920. SaveBuf[nested].nVarExpr = nVarExpr;
  2921. SaveBuf[nested].nVarExprAlloc = nVarExprAlloc;
  2922. SaveBuf[nested].apVarExpr = apVarExpr;
  2923. SaveBuf[nested].nAlias = nAlias;
  2924. SaveBuf[nested].nAliasAlloc = nAliasAlloc;
  2925. SaveBuf[nested].aAlias = aAlias;
  2926. SaveBuf[nested].explain = explain;
  2927. SaveBuf[nested].sNameToken = sNameToken;
  2928. SaveBuf[nested].sLastToken = sLastToken;
  2929. SaveBuf[nested].zTail = zTail;
  2930. SaveBuf[nested].pNewTable = pNewTable;
  2931. SaveBuf[nested].pNewTrigger = pNewTrigger;
  2932. SaveBuf[nested].zAuthContext = zAuthContext;
  2933. #if !SQLITE_OMIT_VIRTUALTABLE
  2934. SaveBuf[nested].sArg = sArg ;
  2935. SaveBuf[nested].declareVtab = declareVtab;
  2936. SaveBuf[nested].nVtabLock = nVtabLock ;
  2937. SaveBuf[nested].apVtabLock = apVtabLock ;
  2938. #endif
  2939. SaveBuf[nested].nHeight = nHeight;
  2940. SaveBuf[nested].pZombieTab = pZombieTab;
  2941. SaveBuf[nested].pTriggerPrg = pTriggerPrg;
  2942. }
  2943. };
  2944. #if SQLITE_OMIT_VIRTUALTABLE
  2945. static bool IN_DECLARE_VTAB = false;//#define IN_DECLARE_VTAB 0
  2946. #else
  2947. //#define IN_DECLARE_VTAB (pParse.declareVtab)
  2948. #endif
  2949. /*
  2950. ** An instance of the following structure can be declared on a stack and used
  2951. ** to save the Parse.zAuthContext value so that it can be restored later.
  2952. */
  2953. public class AuthContext
  2954. {
  2955. public string zAuthContext; /* Put saved Parse.zAuthContext here */
  2956. public Parse pParse; /* The Parse structure */
  2957. };
  2958. /*
  2959. ** Bitfield flags for P5 value in OP_Insert and OP_Delete
  2960. */
  2961. //#define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
  2962. //#define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
  2963. //#define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
  2964. //#define OPFLAG_APPEND 0x08 /* This is likely to be an append */
  2965. //#define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
  2966. //#define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */
  2967. const byte OPFLAG_NCHANGE = 0x01;
  2968. const byte OPFLAG_LASTROWID = 0x02;
  2969. const byte OPFLAG_ISUPDATE = 0x04;
  2970. const byte OPFLAG_APPEND = 0x08;
  2971. const byte OPFLAG_USESEEKRESULT = 0x10;
  2972. const byte OPFLAG_CLEARCACHE = 0x20;
  2973. /*
  2974. * Each trigger present in the database schema is stored as an instance of
  2975. * struct Trigger.
  2976. *
  2977. * Pointers to instances of struct Trigger are stored in two ways.
  2978. * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
  2979. * database). This allows Trigger structures to be retrieved by name.
  2980. * 2. All triggers associated with a single table form a linked list, using the
  2981. * pNext member of struct Trigger. A pointer to the first element of the
  2982. * linked list is stored as the "pTrigger" member of the associated
  2983. * struct Table.
  2984. *
  2985. * The "step_list" member points to the first element of a linked list
  2986. * containing the SQL statements specified as the trigger program.
  2987. */
  2988. public class Trigger
  2989. {
  2990. public string zName; /* The name of the trigger */
  2991. public string table; /* The table or view to which the trigger applies */
  2992. public u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
  2993. public u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
  2994. public Expr pWhen; /* The WHEN clause of the expression (may be NULL) */
  2995. public IdList pColumns; /* If this is an UPDATE OF <column-list> trigger,
  2996. the <column-list> is stored here */
  2997. public Schema pSchema; /* Schema containing the trigger */
  2998. public Schema pTabSchema; /* Schema containing the table */
  2999. public TriggerStep step_list; /* Link list of trigger program steps */
  3000. public Trigger pNext; /* Next trigger associated with the table */
  3001. public Trigger Copy()
  3002. {
  3003. if ( this == null )
  3004. return null;
  3005. else
  3006. {
  3007. Trigger cp = (Trigger)MemberwiseClone();
  3008. if ( pWhen != null )
  3009. cp.pWhen = pWhen.Copy();
  3010. if ( pColumns != null )
  3011. cp.pColumns = pColumns.Copy();
  3012. if ( pSchema != null )
  3013. cp.pSchema = pSchema.Copy();
  3014. if ( pTabSchema != null )
  3015. cp.pTabSchema = pTabSchema.Copy();
  3016. if ( step_list != null )
  3017. cp.step_list = step_list.Copy();
  3018. if ( pNext != null )
  3019. cp.pNext = pNext.Copy();
  3020. return cp;
  3021. }
  3022. }
  3023. };
  3024. /*
  3025. ** A trigger is either a BEFORE or an AFTER trigger. The following constants
  3026. ** determine which.
  3027. **
  3028. ** If there are multiple triggers, you might of some BEFORE and some AFTER.
  3029. ** In that cases, the constants below can be ORed together.
  3030. */
  3031. const u8 TRIGGER_BEFORE = 1;//#define TRIGGER_BEFORE 1
  3032. const u8 TRIGGER_AFTER = 2;//#define TRIGGER_AFTER 2
  3033. /*
  3034. * An instance of struct TriggerStep is used to store a single SQL statement
  3035. * that is a part of a trigger-program.
  3036. *
  3037. * Instances of struct TriggerStep are stored in a singly linked list (linked
  3038. * using the "pNext" member) referenced by the "step_list" member of the
  3039. * associated struct Trigger instance. The first element of the linked list is
  3040. * the first step of the trigger-program.
  3041. *
  3042. * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
  3043. * "SELECT" statement. The meanings of the other members is determined by the
  3044. * value of "op" as follows:
  3045. *
  3046. * (op == TK_INSERT)
  3047. * orconf -> stores the ON CONFLICT algorithm
  3048. * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
  3049. * this stores a pointer to the SELECT statement. Otherwise NULL.
  3050. * target -> A token holding the quoted name of the table to insert into.
  3051. * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
  3052. * this stores values to be inserted. Otherwise NULL.
  3053. * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
  3054. * statement, then this stores the column-names to be
  3055. * inserted into.
  3056. *
  3057. * (op == TK_DELETE)
  3058. * target -> A token holding the quoted name of the table to delete from.
  3059. * pWhere -> The WHERE clause of the DELETE statement if one is specified.
  3060. * Otherwise NULL.
  3061. *
  3062. * (op == TK_UPDATE)
  3063. * target -> A token holding the quoted name of the table to update rows of.
  3064. * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
  3065. * Otherwise NULL.
  3066. * pExprList -> A list of the columns to update and the expressions to update
  3067. * them to. See sqlite3Update() documentation of "pChanges"
  3068. * argument.
  3069. *
  3070. */
  3071. public class TriggerStep
  3072. {
  3073. public u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
  3074. public u8 orconf; /* OE_Rollback etc. */
  3075. public Trigger pTrig; /* The trigger that this step is a part of */
  3076. public Select pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */
  3077. public Token target; /* Target table for DELETE, UPDATE, INSERT */
  3078. public Expr pWhere; /* The WHERE clause for DELETE or UPDATE steps */
  3079. public ExprList pExprList; /* SET clause for UPDATE. VALUES clause for INSERT */
  3080. public IdList pIdList; /* Column names for INSERT */
  3081. public TriggerStep pNext; /* Next in the link-list */
  3082. public TriggerStep pLast; /* Last element in link-list. Valid for 1st elem only */
  3083. public TriggerStep()
  3084. {
  3085. target = new Token();
  3086. }
  3087. public TriggerStep Copy()
  3088. {
  3089. if ( this == null )
  3090. return null;
  3091. else
  3092. {
  3093. TriggerStep cp = (TriggerStep)MemberwiseClone();
  3094. return cp;
  3095. }
  3096. }
  3097. };
  3098. /*
  3099. ** The following structure contains information used by the sqliteFix...
  3100. ** routines as they walk the parse tree to make database references
  3101. ** explicit.
  3102. */
  3103. //typedef struct DbFixer DbFixer;
  3104. public class DbFixer
  3105. {
  3106. public Parse pParse; /* The parsing context. Error messages written here */
  3107. public string zDb; /* Make sure all objects are contained in this database */
  3108. public string zType; /* Type of the container - used for error messages */
  3109. public Token pName; /* Name of the container - used for error messages */
  3110. };
  3111. /*
  3112. ** An objected used to accumulate the text of a string where we
  3113. ** do not necessarily know how big the string will be in the end.
  3114. */
  3115. public class StrAccum
  3116. {
  3117. public sqlite3 db; /* Optional database for lookaside. Can be NULL */
  3118. //public StringBuilder zBase; /* A base allocation. Not from malloc. */
  3119. public StringBuilder zText; /* The string collected so far */
  3120. //public int nChar; /* Length of the string so far */
  3121. //public int nAlloc; /* Amount of space allocated in zText */
  3122. public int mxAlloc; /* Maximum allowed string length */
  3123. // Cannot happen under C#
  3124. //public u8 mallocFailed; /* Becomes true if any memory allocation fails */
  3125. //public u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
  3126. //public u8 tooBig; /* Becomes true if string size exceeds limits */
  3127. public Mem Context;
  3128. public StrAccum( int n )
  3129. {
  3130. db = null;
  3131. //zBase = new StringBuilder( n );
  3132. zText = new StringBuilder( n );
  3133. //nChar = 0;
  3134. //nAlloc = n;
  3135. mxAlloc = 0;
  3136. //useMalloc = 0;
  3137. //tooBig = 0;
  3138. Context = null;
  3139. }
  3140. public i64 nChar
  3141. {
  3142. get
  3143. {
  3144. return zText.Length;
  3145. }
  3146. }
  3147. public bool tooBig
  3148. {
  3149. get
  3150. {
  3151. return mxAlloc > 0 && zText.Length > mxAlloc;
  3152. }
  3153. }
  3154. };
  3155. /*
  3156. ** A pointer to this structure is used to communicate information
  3157. ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
  3158. */
  3159. public class InitData
  3160. {
  3161. public sqlite3 db; /* The database being initialized */
  3162. public int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
  3163. public string pzErrMsg; /* Error message stored here */
  3164. public int rc; /* Result code stored here */
  3165. }
  3166. /*
  3167. ** Structure containing global configuration data for the SQLite library.
  3168. **
  3169. ** This structure also contains some state information.
  3170. */
  3171. public class Sqlite3Config
  3172. {
  3173. public bool bMemstat; /* True to enable memory status */
  3174. public bool bCoreMutex; /* True to enable core mutexing */
  3175. public bool bFullMutex; /* True to enable full mutexing */
  3176. public int mxStrlen; /* Maximum string length */
  3177. public int szLookaside; /* Default lookaside buffer size */
  3178. public int nLookaside; /* Default lookaside buffer count */
  3179. public sqlite3_mem_methods m; /* Low-level memory allocation interface */
  3180. public sqlite3_mutex_methods mutex; /* Low-level mutex interface */
  3181. public sqlite3_pcache_methods pcache; /* Low-level page-cache interface */
  3182. public byte[] pHeap; /* Heap storage space */
  3183. public int nHeap; /* Size of pHeap[] */
  3184. public int mnReq, mxReq; /* Min and max heap requests sizes */
  3185. public byte[][] pScratch2; /* Scratch memory */
  3186. public byte[][] pScratch; /* Scratch memory */
  3187. public int szScratch; /* Size of each scratch buffer */
  3188. public int nScratch; /* Number of scratch buffers */
  3189. public MemPage pPage; /* Page cache memory */
  3190. public int szPage; /* Size of each page in pPage[] */
  3191. public int nPage; /* Number of pages in pPage[] */
  3192. public int mxParserStack; /* maximum depth of the parser stack */
  3193. public bool sharedCacheEnabled; /* true if shared-cache mode enabled */
  3194. /* The above might be initialized to non-zero. The following need to always
  3195. ** initially be zero, however. */
  3196. public int isInit; /* True after initialization has finished */
  3197. public int inProgress; /* True while initialization in progress */
  3198. public int isMutexInit; /* True after mutexes are initialized */
  3199. public int isMallocInit; /* True after malloc is initialized */
  3200. public int isPCacheInit; /* True after malloc is initialized */
  3201. public sqlite3_mutex pInitMutex; /* Mutex used by sqlite3_initialize() */
  3202. public int nRefInitMutex; /* Number of users of pInitMutex */
  3203. public dxLog xLog; //void (*xLog)(void*,int,const char*); /* Function for logging */
  3204. public object pLogArg; /* First argument to xLog() */
  3205. public Sqlite3Config( int bMemstat, int bCoreMutex, bool bFullMutex, int mxStrlen, int szLookaside, int nLookaside
  3206. , sqlite3_mem_methods m
  3207. , sqlite3_mutex_methods mutex
  3208. , sqlite3_pcache_methods pcache
  3209. , byte[] pHeap
  3210. , int nHeap,
  3211. int mnReq, int mxReq
  3212. , byte[][] pScratch
  3213. , int szScratch
  3214. , int nScratch
  3215. , MemPage pPage
  3216. , int szPage
  3217. , int nPage
  3218. , int mxParserStack
  3219. , bool sharedCacheEnabled
  3220. , int isInit
  3221. , int inProgress
  3222. , int isMutexInit
  3223. , int isMallocInit
  3224. , int isPCacheInit
  3225. , sqlite3_mutex pInitMutex
  3226. , int nRefInitMutex
  3227. , dxLog xLog
  3228. , object pLogArg
  3229. )
  3230. {
  3231. this.bMemstat = bMemstat != 0;
  3232. this.bCoreMutex = bCoreMutex != 0;
  3233. this.bFullMutex = bFullMutex;
  3234. this.mxStrlen = mxStrlen;
  3235. this.szLookaside = szLookaside;
  3236. this.nLookaside = nLookaside;
  3237. this.m = m;
  3238. this.mutex = mutex;
  3239. this.pcache = pcache;
  3240. this.pHeap = pHeap;
  3241. this.nHeap = nHeap;
  3242. this.mnReq = mnReq;
  3243. this.mxReq = mxReq;
  3244. this.pScratch = pScratch;
  3245. this.szScratch = szScratch;
  3246. this.nScratch = nScratch;
  3247. this.pPage = pPage;
  3248. this.szPage = szPage;
  3249. this.nPage = nPage;
  3250. this.mxParserStack = mxParserStack;
  3251. this.sharedCacheEnabled = sharedCacheEnabled;
  3252. this.isInit = isInit;
  3253. this.inProgress = inProgress;
  3254. this.isMutexInit = isMutexInit;
  3255. this.isMallocInit = isMallocInit;
  3256. this.isPCacheInit = isPCacheInit;
  3257. this.pInitMutex = pInitMutex;
  3258. this.nRefInitMutex = nRefInitMutex;
  3259. this.xLog = xLog;
  3260. this.pLogArg = pLogArg;
  3261. }
  3262. };
  3263. /*
  3264. ** Context pointer passed down through the tree-walk.
  3265. */
  3266. public class Walker
  3267. {
  3268. public dxExprCallback xExprCallback; //)(Walker*, Expr*); /* Callback for expressions */
  3269. public dxSelectCallback xSelectCallback; //)(Walker*,Select*); /* Callback for SELECTs */
  3270. public Parse pParse; /* Parser context. */
  3271. public struct uw
  3272. { /* Extra data for callback */
  3273. public NameContext pNC; /* Naming context */
  3274. public int i; /* Integer value */
  3275. }
  3276. public uw u;
  3277. };
  3278. /* Forward declarations */
  3279. //int sqlite3WalkExpr(Walker*, Expr*);
  3280. //int sqlite3WalkExprList(Walker*, ExprList*);
  3281. //int sqlite3WalkSelect(Walker*, Select*);
  3282. //int sqlite3WalkSelectExpr(Walker*, Select*);
  3283. //int sqlite3WalkSelectFrom(Walker*, Select*);
  3284. /*
  3285. ** Return code from the parse-tree walking primitives and their
  3286. ** callbacks.
  3287. */
  3288. //#define WRC_Continue 0 /* Continue down into children */
  3289. //#define WRC_Prune 1 /* Omit children but continue walking siblings */
  3290. //#define WRC_Abort 2 /* Abandon the tree walk */
  3291. const int WRC_Continue = 0;
  3292. const int WRC_Prune = 1;
  3293. const int WRC_Abort = 2;
  3294. /*
  3295. ** Assuming zIn points to the first byte of a UTF-8 character,
  3296. ** advance zIn to point to the first byte of the next UTF-8 character.
  3297. */
  3298. //#define SQLITE_SKIP_UTF8(zIn) { \
  3299. // if( (*(zIn++))>=0xc0 ){ \
  3300. // while( (*zIn & 0xc0)==0x80 ){ zIn++; } \
  3301. // } \
  3302. //}
  3303. static void SQLITE_SKIP_UTF8( string zIn, ref int iz )
  3304. {
  3305. iz++;
  3306. if ( iz < zIn.Length && zIn[iz - 1] >= 0xC0 )
  3307. {
  3308. while ( iz < zIn.Length && ( zIn[iz] & 0xC0 ) == 0x80 )
  3309. {
  3310. iz++;
  3311. }
  3312. }
  3313. }
  3314. static void SQLITE_SKIP_UTF8(
  3315. byte[] zIn, ref int iz )
  3316. {
  3317. iz++;
  3318. if ( iz < zIn.Length && zIn[iz - 1] >= 0xC0 )
  3319. {
  3320. while ( iz < zIn.Length && ( zIn[iz] & 0xC0 ) == 0x80 )
  3321. {
  3322. iz++;
  3323. }
  3324. }
  3325. }
  3326. /*
  3327. ** The SQLITE_*_BKPT macros are substitutes for the error codes with
  3328. ** the same name but without the _BKPT suffix. These macros invoke
  3329. ** routines that report the line-number on which the error originated
  3330. ** using sqlite3_log(). The routines also provide a convenient place
  3331. ** to set a debugger breakpoint.
  3332. */
  3333. //int sqlite3CorruptError(int);
  3334. //int sqlite3MisuseError(int);
  3335. //int sqlite3CantopenError(int);
  3336. #if DEBUG
  3337. //#define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__)
  3338. static int SQLITE_CORRUPT_BKPT()
  3339. {
  3340. return sqlite3CorruptError( 0 );
  3341. }
  3342. //#define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__)
  3343. static int SQLITE_MISUSE_BKPT()
  3344. {
  3345. return sqlite3MisuseError( 0 );
  3346. }
  3347. //#define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__)
  3348. static int SQLITE_CANTOPEN_BKPT()
  3349. {
  3350. return sqlite3CantopenError( 0 );
  3351. }
  3352. #else
  3353. static int SQLITE_CORRUPT_BKPT() {return SQLITE_CORRUPT;}
  3354. static int SQLITE_MISUSE_BKPT() {return SQLITE_MISUSE;}
  3355. static int SQLITE_CANTOPEN_BKPT() {return SQLITE_CANTOPEN;}
  3356. #endif
  3357. /*
  3358. ** FTS4 is really an extension for FTS3. It is enabled using the
  3359. ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also all
  3360. ** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3.
  3361. */
  3362. //#if (SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
  3363. //# define SQLITE_ENABLE_FTS3
  3364. //#endif
  3365. /*
  3366. ** The ctype.h header is needed for non-ASCII systems. It is also
  3367. ** needed by FTS3 when FTS3 is included in the amalgamation.
  3368. */
  3369. //#if !defined(SQLITE_ASCII) || \
  3370. // (defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_AMALGAMATION))
  3371. //# include <ctype.h>
  3372. //#endif
  3373. /*
  3374. ** The following macros mimic the standard library functions toupper(),
  3375. ** isspace(), isalnum(), isdigit() and isxdigit(), respectively. The
  3376. ** sqlite versions only work for ASCII characters, regardless of locale.
  3377. */
  3378. #if SQLITE_ASCII
  3379. //# define sqlite3Toupper(x) ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20))
  3380. //# define sqlite3Isspace(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x01)
  3381. static bool sqlite3Isspace( byte x )
  3382. {
  3383. return ( sqlite3CtypeMap[(byte)( x )] & 0x01 ) != 0;
  3384. }
  3385. static bool sqlite3Isspace( char x )
  3386. {
  3387. return x < 256 && ( sqlite3CtypeMap[(byte)( x )] & 0x01 ) != 0;
  3388. }
  3389. //# define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
  3390. static bool sqlite3Isalnum( byte x )
  3391. {
  3392. return ( sqlite3CtypeMap[(byte)( x )] & 0x06 ) != 0;
  3393. }
  3394. static bool sqlite3Isalnum( char x )
  3395. {
  3396. return x < 256 && ( sqlite3CtypeMap[(byte)( x )] & 0x06 ) != 0;
  3397. }
  3398. //# define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
  3399. //# define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
  3400. static bool sqlite3Isdigit( byte x )
  3401. {
  3402. return ( sqlite3CtypeMap[( (byte)x )] & 0x04 ) != 0;
  3403. }
  3404. static bool sqlite3Isdigit( char x )
  3405. {
  3406. return x < 256 && ( sqlite3CtypeMap[( (byte)x )] & 0x04 ) != 0;
  3407. }
  3408. //# define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
  3409. static bool sqlite3Isxdigit( byte x )
  3410. {
  3411. return ( sqlite3CtypeMap[( (byte)x )] & 0x08 ) != 0;
  3412. }
  3413. static bool sqlite3Isxdigit( char x )
  3414. {
  3415. return x < 256 && ( sqlite3CtypeMap[( (byte)x )] & 0x08 ) != 0;
  3416. }
  3417. //# define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
  3418. #else
  3419. //# define sqlite3Toupper(x) toupper((unsigned char)(x))
  3420. //# define sqlite3Isspace(x) isspace((unsigned char)(x))
  3421. //# define sqlite3Isalnum(x) isalnum((unsigned char)(x))
  3422. //# define sqlite3Isalpha(x) isalpha((unsigned char)(x))
  3423. //# define sqlite3Isdigit(x) isdigit((unsigned char)(x))
  3424. //# define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
  3425. //# define sqlite3Tolower(x) tolower((unsigned char)(x))
  3426. #endif
  3427. /*
  3428. ** Internal function prototypes
  3429. */
  3430. //int sqlite3StrICmp(const char *, const char *);
  3431. //int sqlite3Strlen30(const char*);
  3432. //#define sqlite3StrNICmp sqlite3_strnicmp
  3433. //int sqlite3MallocInit(void);
  3434. //void sqlite3MallocEnd(void);
  3435. //void *sqlite3Malloc(int);
  3436. //void *sqlite3MallocZero(int);
  3437. //void *sqlite3DbMallocZero(sqlite3*, int);
  3438. //void *sqlite3DbMallocRaw(sqlite3*, int);
  3439. //char *sqlite3DbStrDup(sqlite3*,const char*);
  3440. //char *sqlite3DbStrNDup(sqlite3*,const char*, int);
  3441. //void *sqlite3Realloc(void*, int);
  3442. //void *sqlite3DbReallocOrFree(sqlite3 *, void *, int);
  3443. //void *sqlite3DbRealloc(sqlite3 *, void *, int);
  3444. //void sqlite3DbFree(sqlite3*, void*);
  3445. //int sqlite3MallocSize(void*);
  3446. //int sqlite3DbMallocSize(sqlite3*, void*);
  3447. //void *sqlite3ScratchMalloc(int);
  3448. //void //sqlite3ScratchFree(void*);
  3449. //void *sqlite3PageMalloc(int);
  3450. //void sqlite3PageFree(void*);
  3451. //void sqlite3MemSetDefault(void);
  3452. //void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
  3453. //int sqlite3HeapNearlyFull(void);
  3454. /*
  3455. ** On systems with ample stack space and that support alloca(), make
  3456. ** use of alloca() to obtain space for large automatic objects. By default,
  3457. ** obtain space from malloc().
  3458. **
  3459. ** The alloca() routine never returns NULL. This will cause code paths
  3460. ** that deal with sqlite3StackAlloc() failures to be unreachable.
  3461. */
  3462. #if SQLITE_USE_ALLOCA
  3463. //# define sqlite3StackAllocRaw(D,N) alloca(N)
  3464. //# define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N)
  3465. //# define sqlite3StackFree(D,P)
  3466. #else
  3467. #if FALSE
  3468. //# define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N)
  3469. static void sqlite3StackAllocRaw( sqlite3 D, int N ) { sqlite3DbMallocRaw( D, N ); }
  3470. //# define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N)
  3471. static void sqlite3StackAllocZero( sqlite3 D, int N ) { sqlite3DbMallocZero( D, N ); }
  3472. //# define sqlite3StackFree(D,P) sqlite3DbFree(D,P)
  3473. static void sqlite3StackFree( sqlite3 D, object P ) {sqlite3DbFree( D, P ); }
  3474. #endif
  3475. #endif
  3476. #if SQLITE_ENABLE_MEMSYS3
  3477. const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
  3478. #endif
  3479. #if SQLITE_ENABLE_MEMSYS5
  3480. const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
  3481. #endif
  3482. #if !SQLITE_MUTEX_OMIT
  3483. // sqlite3_mutex_methods const *sqlite3DefaultMutex(void);
  3484. // sqlite3_mutex_methods const *sqlite3NoopMutex(void);
  3485. // sqlite3_mutex *sqlite3MutexAlloc(int);
  3486. // int sqlite3MutexInit(void);
  3487. // int sqlite3MutexEnd(void);
  3488. #endif
  3489. //int sqlite3StatusValue(int);
  3490. //void sqlite3StatusAdd(int, int);
  3491. //void sqlite3StatusSet(int, int);
  3492. //#ifndef SQLITE_OMIT_FLOATING_POINT
  3493. // int sqlite3IsNaN(double);
  3494. //#else
  3495. //# define sqlite3IsNaN(X) 0
  3496. //#endif
  3497. //void sqlite3VXPrintf(StrAccum*, int, const char*, va_list);
  3498. #if!SQLITE_OMIT_TRACE
  3499. //void sqlite3XPrintf(StrAccum*, const char*, ...);
  3500. #endif
  3501. //char *sqlite3MPrintf(sqlite3*,const char*, ...);
  3502. //char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
  3503. //char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
  3504. #if SQLITE_TEST || SQLITE_DEBUG
  3505. // void sqlite3DebugPrintf(const char*, ...);
  3506. #endif
  3507. #if SQLITE_TEST
  3508. // void *sqlite3TestTextToPtr(const char*);
  3509. #endif
  3510. //void sqlite3SetString(char **, sqlite3*, const char*, ...);
  3511. //void sqlite3ErrorMsg(Parse*, const char*, ...);
  3512. //int sqlite3Dequote(char*);
  3513. //int sqlite3KeywordCode(const unsigned char*, int);
  3514. //int sqlite3RunParser(Parse*, const char*, char **);
  3515. //void sqlite3FinishCoding(Parse*);
  3516. //int sqlite3GetTempReg(Parse*);
  3517. //void sqlite3ReleaseTempReg(Parse*,int);
  3518. //int sqlite3GetTempRange(Parse*,int);
  3519. //void sqlite3ReleaseTempRange(Parse*,int,int);
  3520. //Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
  3521. //Expr *sqlite3Expr(sqlite3*,int,const char*);
  3522. //void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
  3523. //Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
  3524. //Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
  3525. //Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
  3526. //void sqlite3ExprAssignVarNumber(Parse*, Expr*);
  3527. //void sqlite3ExprDelete(sqlite3*, Expr*);
  3528. //ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
  3529. //void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
  3530. //void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
  3531. //void sqlite3ExprListDelete(sqlite3*, ExprList*);
  3532. //int sqlite3Init(sqlite3*, char**);
  3533. //int sqlite3InitCallback(void*, int, char**, char**);
  3534. //void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
  3535. //void sqlite3ResetInternalSchema(sqlite3*, int);
  3536. //void sqlite3BeginParse(Parse*,int);
  3537. //void sqlite3CommitInternalChanges(sqlite3*);
  3538. //Table *sqlite3ResultSetOfSelect(Parse*,Select*);
  3539. //void sqlite3OpenMasterTable(Parse *, int);
  3540. //void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
  3541. //void sqlite3AddColumn(Parse*,Token*);
  3542. //void sqlite3AddNotNull(Parse*, int);
  3543. //void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
  3544. //void sqlite3AddCheckConstraint(Parse*, Expr*);
  3545. //void sqlite3AddColumnType(Parse*,Token*);
  3546. //void sqlite3AddDefaultValue(Parse*,ExprSpan*);
  3547. //void sqlite3AddCollateType(Parse*, Token*);
  3548. //void sqlite3EndTable(Parse*,Token*,Token*,Select*);
  3549. //Bitvec *sqlite3BitvecCreate(u32);
  3550. //int sqlite3BitvecTest(Bitvec*, u32);
  3551. //int sqlite3BitvecSet(Bitvec*, u32);
  3552. //void sqlite3BitvecClear(Bitvec*, u32, void*);
  3553. //void sqlite3BitvecDestroy(Bitvec*);
  3554. //u32 sqlite3BitvecSize(Bitvec*);
  3555. //int sqlite3BitvecBuiltinTest(int,int*);
  3556. //RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
  3557. //void sqlite3RowSetClear(RowSet*);
  3558. //void sqlite3RowSetInsert(RowSet*, i64);
  3559. //int sqlite3RowSetTest(RowSet*, u8 iBatch, i64);
  3560. //int sqlite3RowSetNext(RowSet*, i64*);
  3561. //void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
  3562. #if !SQLITE_OMIT_VIEW || !SQLITE_OMIT_VIRTUALTABLE
  3563. //int sqlite3ViewGetColumnNames(Parse*,Table*);
  3564. #else
  3565. //# define sqlite3ViewGetColumnNames(A,B) 0
  3566. static int sqlite3ViewGetColumnNames( Parse A, Table B )
  3567. {
  3568. return 0;
  3569. }
  3570. #endif
  3571. //void sqlite3DropTable(Parse*, SrcList*, int, int);
  3572. //void sqlite3DeleteTable(sqlite3*, Table*);
  3573. //#if ! SQLITE_OMIT_AUTOINCREMENT
  3574. // void sqlite3AutoincrementBegin(Parse *pParse);
  3575. // void sqlite3AutoincrementEnd(Parse *pParse);
  3576. //#else
  3577. //# define sqlite3AutoincrementBegin(X)
  3578. //# define sqlite3AutoincrementEnd(X)
  3579. //#endif
  3580. //void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
  3581. //void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*);
  3582. //IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
  3583. //int sqlite3IdListIndex(IdList*,const char*);
  3584. //SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
  3585. //SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
  3586. //SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
  3587. // Token*, Select*, Expr*, IdList*);
  3588. //void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
  3589. //int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
  3590. //void sqlite3SrcListShiftJoinType(SrcList*);
  3591. //void sqlite3SrcListAssignCursors(Parse*, SrcList*);
  3592. //void sqlite3IdListDelete(sqlite3*, IdList*);
  3593. //void sqlite3SrcListDelete(sqlite3*, SrcList*);
  3594. //Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
  3595. // Token*, int, int);
  3596. //void sqlite3DropIndex(Parse*, SrcList*, int);
  3597. //int sqlite3Select(Parse*, Select*, SelectDest*);
  3598. //Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
  3599. // Expr*,ExprList*,int,Expr*,Expr*);
  3600. //void sqlite3SelectDelete(sqlite3*, Select*);
  3601. //Table *sqlite3SrcListLookup(Parse*, SrcList*);
  3602. //int sqlite3IsReadOnly(Parse*, Table*, int);
  3603. //void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
  3604. #if (SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !(SQLITE_OMIT_SUBQUERY)
  3605. //Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *);
  3606. #endif
  3607. //void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
  3608. //void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
  3609. //WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u16);
  3610. //void sqlite3WhereEnd(WhereInfo*);
  3611. //int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int);
  3612. //void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
  3613. //void sqlite3ExprCodeMove(Parse*, int, int, int);
  3614. //void sqlite3ExprCodeCopy(Parse*, int, int, int);
  3615. //void sqlite3ExprCacheStore(Parse*, int, int, int);
  3616. //void sqlite3ExprCachePush(Parse*);
  3617. //void sqlite3ExprCachePop(Parse*, int);
  3618. //void sqlite3ExprCacheRemove(Parse*, int, int);
  3619. //void sqlite3ExprCacheClear(Parse*);
  3620. //void sqlite3ExprCacheAffinityChange(Parse*, int, int);
  3621. //int sqlite3ExprCode(Parse*, Expr*, int);
  3622. //int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
  3623. //int sqlite3ExprCodeTarget(Parse*, Expr*, int);
  3624. //int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
  3625. //void sqlite3ExprCodeConstants(Parse*, Expr*);
  3626. //int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
  3627. //void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
  3628. //void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
  3629. //Table *sqlite3FindTable(sqlite3*,const char*, const char*);
  3630. //Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
  3631. //Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
  3632. //void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
  3633. //void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
  3634. //void sqlite3Vacuum(Parse*);
  3635. //int sqlite3RunVacuum(char**, sqlite3*);
  3636. //char *sqlite3NameFromToken(sqlite3*, Token*);
  3637. //int sqlite3ExprCompare(Expr*, Expr*);
  3638. //int sqlite3ExprListCompare(ExprList*, ExprList*);
  3639. //void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
  3640. //void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
  3641. //Vdbe *sqlite3GetVdbe(Parse*);
  3642. //void sqlite3PrngSaveState(void);
  3643. //void sqlite3PrngRestoreState(void);
  3644. //void sqlite3PrngResetState(void);
  3645. //void sqlite3RollbackAll(sqlite3*);
  3646. //void sqlite3CodeVerifySchema(Parse*, int);
  3647. //void sqlite3BeginTransaction(Parse*, int);
  3648. //void sqlite3CommitTransaction(Parse*);
  3649. //void sqlite3RollbackTransaction(Parse*);
  3650. //void sqlite3Savepoint(Parse*, int, Token*);
  3651. //void sqlite3CloseSavepoints(sqlite3 *);
  3652. //int sqlite3ExprIsConstant(Expr*);
  3653. //int sqlite3ExprIsConstantNotJoin(Expr*);
  3654. //int sqlite3ExprIsConstantOrFunction(Expr*);
  3655. //int sqlite3ExprIsInteger(Expr*, int*);
  3656. //int sqlite3ExprCanBeNull(const Expr*);
  3657. //void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
  3658. //int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
  3659. //int sqlite3IsRowid(const char*);
  3660. //void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int, Trigger *, int);
  3661. //void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*);
  3662. //int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int);
  3663. //void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int,
  3664. // int*,int,int,int,int,int*);
  3665. //void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int);
  3666. //int sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
  3667. //void sqlite3BeginWriteOperation(Parse*, int, int);
  3668. //void sqlite3MultiWrite(Parse*);
  3669. //void sqlite3MayAbort(Parse *);
  3670. //void sqlite3HaltConstraint(Parse*, int, char*, int);
  3671. //Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
  3672. //ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
  3673. //SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
  3674. //IdList *sqlite3IdListDup(sqlite3*,IdList*);
  3675. //Select *sqlite3SelectDup(sqlite3*,Select*,int);
  3676. //void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*);
  3677. //FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
  3678. //void sqlite3RegisterBuiltinFunctions(sqlite3*);
  3679. //void sqlite3RegisterDateTimeFunctions(void);
  3680. //void sqlite3RegisterGlobalFunctions(void);
  3681. //int sqlite3SafetyCheckOk(sqlite3*);
  3682. //int sqlite3SafetyCheckSickOrOk(sqlite3*);
  3683. //void sqlite3ChangeCookie(Parse*, int);
  3684. #if !(SQLITE_OMIT_VIEW) && !(SQLITE_OMIT_TRIGGER)
  3685. //void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
  3686. #endif
  3687. #if !SQLITE_OMIT_TRIGGER
  3688. //void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
  3689. // Expr*,int, int);
  3690. //void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
  3691. //void sqlite3DropTrigger(Parse*, SrcList*, int);
  3692. //Trigger *sqlite3TriggersExist(Parse *, Table*, int, ExprList*, int *pMask);
  3693. //Trigger *sqlite3TriggerList(Parse *, Table *);
  3694. // void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
  3695. // int, int, int);
  3696. //void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
  3697. //void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*);
  3698. //TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*);
  3699. //TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
  3700. // ExprList*,Select*,u8);
  3701. //TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8);
  3702. //TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*);
  3703. //void sqlite3DeleteTrigger(sqlite3*, Trigger*);
  3704. //void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
  3705. // u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
  3706. //# define sqlite3ParseToplevel(p) ((p)->pToplevel ? (p)->pToplevel : (p))
  3707. static Parse sqlite3ParseToplevel( Parse p )
  3708. {
  3709. return p.pToplevel != null ? p.pToplevel : p;
  3710. }
  3711. #else
  3712. static void sqlite3BeginTrigger( Parse A, Token B, Token C, int D, int E, IdList F, SrcList G, Expr H, int I, int J )
  3713. {
  3714. }
  3715. static void sqlite3FinishTrigger( Parse P, TriggerStep TS, Token T )
  3716. {
  3717. }
  3718. static TriggerStep sqlite3TriggerSelectStep( sqlite3 A, Select B )
  3719. {
  3720. return null;
  3721. }
  3722. static TriggerStep sqlite3TriggerInsertStep( sqlite3 A, Token B, IdList C, ExprList D, Select E, u8 F )
  3723. {
  3724. return null;
  3725. }
  3726. static TriggerStep sqlite3TriggerInsertStep( sqlite3 A, Token B, IdList C, int D, Select E, u8 F )
  3727. {
  3728. return null;
  3729. }
  3730. static TriggerStep sqlite3TriggerInsertStep( sqlite3 A, Token B, IdList C, ExprList D, int E, u8 F )
  3731. {
  3732. return null;
  3733. }
  3734. static TriggerStep sqlite3TriggerUpdateStep( sqlite3 A, Token B, ExprList C, Expr D, u8 E )
  3735. {
  3736. return null;
  3737. }
  3738. static TriggerStep sqlite3TriggerDeleteStep( sqlite3 A, Token B, Expr C )
  3739. {
  3740. return null;
  3741. }
  3742. static u32 sqlite3TriggerColmask( Parse A, Trigger B, ExprList C, int D, int E, Table F, int G )
  3743. {
  3744. return 0;
  3745. }
  3746. //# define sqlite3TriggersExist(B,C,D,E,F) 0
  3747. static Trigger sqlite3TriggersExist( Parse B, Table C, int D, ExprList E, ref int F )
  3748. {
  3749. return null;
  3750. }
  3751. //# define sqlite3DeleteTrigger(A,B)
  3752. static void sqlite3DeleteTrigger( sqlite3 A, ref Trigger B )
  3753. {
  3754. }
  3755. static void sqlite3DeleteTriggerStep( sqlite3 A, ref TriggerStep B )
  3756. {
  3757. }
  3758. //# define sqlite3DropTriggerPtr(A,B)
  3759. static void sqlite3DropTriggerPtr( Parse A, Trigger B )
  3760. {
  3761. }
  3762. static void sqlite3DropTrigger( Parse A, SrcList B, int C )
  3763. {
  3764. }
  3765. //# define sqlite3UnlinkAndDeleteTrigger(A,B,C)
  3766. static void sqlite3UnlinkAndDeleteTrigger( sqlite3 A, int B, string C )
  3767. {
  3768. }
  3769. //# define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I)
  3770. static void sqlite3CodeRowTrigger( Parse A, Trigger B, int C, ExprList D, int E, Table F, int G, int H, int I )
  3771. {
  3772. }
  3773. //# define sqlite3CodeRowTriggerDirect(A,B,C,D,E,F)
  3774. static Trigger sqlite3TriggerList( Parse pParse, Table pTab )
  3775. {
  3776. return null;
  3777. } //# define sqlite3TriggerList(X, Y) 0
  3778. //# define sqlite3ParseToplevel(p) p
  3779. static Parse sqlite3ParseToplevel( Parse p )
  3780. {
  3781. return p;
  3782. }
  3783. //# define sqlite3TriggerOldmask(A,B,C,D,E,F) 0
  3784. static u32 sqlite3TriggerOldmask( Parse A, Trigger B, int C, ExprList D, Table E, int F )
  3785. {
  3786. return 0;
  3787. }
  3788. #endif
  3789. //int sqlite3JoinType(Parse*, Token*, Token*, Token*);
  3790. //void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
  3791. //void sqlite3DeferForeignKey(Parse*, int);
  3792. #if !SQLITE_OMIT_AUTHORIZATION
  3793. void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList*);
  3794. int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*);
  3795. void sqlite3AuthContextPush(Parse*, AuthContext*, const char*);
  3796. void sqlite3AuthContextPop(AuthContext*);
  3797. int sqlite3AuthReadCol(Parse*, const char *, const char *, int);
  3798. #else
  3799. //# define sqlite3AuthRead(a,b,c,d)
  3800. static void sqlite3AuthRead( Parse a, Expr b, Schema c, SrcList d )
  3801. {
  3802. }
  3803. //# define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK
  3804. static int sqlite3AuthCheck( Parse a, int b, string c, byte[] d, byte[] e )
  3805. {
  3806. return SQLITE_OK;
  3807. }
  3808. //# define sqlite3AuthContextPush(a,b,c)
  3809. static void sqlite3AuthContextPush( Parse a, AuthContext b, string c )
  3810. {
  3811. }
  3812. //# define sqlite3AuthContextPop(a) ((void)(a))
  3813. static Parse sqlite3AuthContextPop( Parse a )
  3814. {
  3815. return a;
  3816. }
  3817. #endif
  3818. //void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
  3819. //void sqlite3Detach(Parse*, Expr*);
  3820. //int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
  3821. //int sqlite3FixSrcList(DbFixer*, SrcList*);
  3822. //int sqlite3FixSelect(DbFixer*, Select*);
  3823. //int sqlite3FixExpr(DbFixer*, Expr*);
  3824. //int sqlite3FixExprList(DbFixer*, ExprList*);
  3825. //int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
  3826. //sqlite3AtoF(const char *z, double*, int, u8)
  3827. //int sqlite3GetInt32(const char *, int*);
  3828. //int sqlite3Atoi(const char *);
  3829. //int sqlite3Utf16ByteLen(const void pData, int nChar);
  3830. //int sqlite3Utf8CharLen(const char pData, int nByte);
  3831. //int sqlite3Utf8Read(const u8*, const u8**);
  3832. /*
  3833. ** Routines to read and write variable-length integers. These used to
  3834. ** be defined locally, but now we use the varint routines in the util.c
  3835. ** file. Code should use the MACRO forms below, as the Varint32 versions
  3836. ** are coded to assume the single byte case is already handled (which
  3837. ** the MACRO form does).
  3838. */
  3839. //int sqlite3PutVarint(unsigned char*, u64);
  3840. //int putVarint32(unsigned char*, u32);
  3841. //u8 sqlite3GetVarint(const unsigned char *, u64 *);
  3842. //u8 sqlite3GetVarint32(const unsigned char *, u32 *);
  3843. //int sqlite3VarintLen(u64 v);
  3844. /*
  3845. ** The header of a record consists of a sequence variable-length integers.
  3846. ** These integers are almost always small and are encoded as a single byte.
  3847. ** The following macros take advantage this fact to provide a fast encode
  3848. ** and decode of the integers in a record header. It is faster for the common
  3849. ** case where the integer is a single byte. It is a little slower when the
  3850. ** integer is two or more bytes. But overall it is faster.
  3851. **
  3852. ** The following expressions are equivalent:
  3853. **
  3854. ** x = sqlite3GetVarint32( A, B );
  3855. ** x = putVarint32( A, B );
  3856. **
  3857. ** x = getVarint32( A, B );
  3858. ** x = putVarint32( A, B );
  3859. **
  3860. */
  3861. //#define getVarint32(A,B) (u8)((*(A)<(u8)0x80) ? ((B) = (u32)*(A)),1 : sqlite3GetVarint32((A), (u32 *)&(B)))
  3862. //#define putVarint32(A,B) (u8)(((u32)(B)<(u32)0x80) ? (*(A) = (unsigned char)(B)),1 : sqlite3PutVarint32((A), (B)))
  3863. //#define getVarint sqlite3GetVarint
  3864. //#define putVarint sqlite3PutVarint
  3865. //const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
  3866. //void sqlite3TableAffinityStr(Vdbe *, Table *);
  3867. //char sqlite3CompareAffinity(Expr pExpr, char aff2);
  3868. //int sqlite3IndexAffinityOk(Expr pExpr, char idx_affinity);
  3869. //char sqlite3ExprAffinity(Expr pExpr);
  3870. //int sqlite3Atoi64(const char*, i64*, int, u8);
  3871. //void sqlite3Error(sqlite3*, int, const char*,...);
  3872. //void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
  3873. //int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
  3874. //const char *sqlite3ErrStr(int);
  3875. //int sqlite3ReadSchema(Parse pParse);
  3876. //CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
  3877. //CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
  3878. //CollSeq *sqlite3ExprCollSeq(Parse pParse, Expr pExpr);
  3879. //Expr *sqlite3ExprSetColl(Expr*, CollSeq*);
  3880. //Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*);
  3881. //int sqlite3CheckCollSeq(Parse *, CollSeq *);
  3882. //int sqlite3CheckObjectName(Parse *, const char *);
  3883. //void sqlite3VdbeSetChanges(sqlite3 *, int);
  3884. //const void *sqlite3ValueText(sqlite3_value*, u8);
  3885. //int sqlite3ValueBytes(sqlite3_value*, u8);
  3886. //void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
  3887. // // void(*)(void*));
  3888. //void sqlite3ValueFree(sqlite3_value*);
  3889. //sqlite3_value *sqlite3ValueNew(sqlite3 *);
  3890. //char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
  3891. //#ifdef SQLITE_ENABLE_STAT2
  3892. //char *sqlite3Utf8to16(sqlite3 *, u8, char *, int, int *);
  3893. //#endif
  3894. //int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
  3895. //void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
  3896. //#if !SQLITE_AMALGAMATION
  3897. //extern const unsigned char sqlite3OpcodeProperty[];
  3898. //extern const unsigned char sqlite3UpperToLower[];
  3899. //extern const unsigned char sqlite3CtypeMap[];
  3900. //extern const Token sqlite3IntTokens[];
  3901. //extern SQLITE_WSD struct Sqlite3Config sqlite3Config;
  3902. //extern SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;
  3903. //#ifndef SQLITE_OMIT_WSD
  3904. //extern int sqlite3PendingByte;
  3905. //#endif
  3906. //#endif
  3907. //void sqlite3RootPageMoved(Db*, int, int);
  3908. //void sqlite3Reindex(Parse*, Token*, Token*);
  3909. //void sqlite3AlterFunctions(void);
  3910. //void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
  3911. //int sqlite3GetToken(const unsigned char *, int *);
  3912. //void sqlite3NestedParse(Parse*, const char*, ...);
  3913. //void sqlite3ExpirePreparedStatements(sqlite3*);
  3914. //int sqlite3CodeSubselect(Parse *, Expr *, int, int);
  3915. //void sqlite3SelectPrep(Parse*, Select*, NameContext*);
  3916. //int sqlite3ResolveExprNames(NameContext*, Expr*);
  3917. //void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
  3918. //int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
  3919. //void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
  3920. //void sqlite3AlterFinishAddColumn(Parse *, Token *);
  3921. //void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  3922. //CollSeq *sqlite3GetCollSeq(sqlite3*, u8, CollSeq *, const char*);
  3923. //char sqlite3AffinityType(const char*);
  3924. //void sqlite3Analyze(Parse*, Token*, Token*);
  3925. //int sqlite3InvokeBusyHandler(BusyHandler*);
  3926. //int sqlite3FindDb(sqlite3*, Token*);
  3927. //int sqlite3FindDbName(sqlite3 *, const char *);
  3928. //int sqlite3AnalysisLoad(sqlite3*,int iDB);
  3929. //void sqlite3DeleteIndexSamples(sqlite3*,Index*);
  3930. //void sqlite3DefaultRowEst(Index*);
  3931. //void sqlite3RegisterLikeFunctions(sqlite3*, int);
  3932. //int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
  3933. //void sqlite3MinimumFileFormat(Parse*, int, int);
  3934. //void sqlite3SchemaFree(void *);
  3935. //Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
  3936. //int sqlite3SchemaToIndex(sqlite3 db, Schema *);
  3937. //KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
  3938. //int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
  3939. // void (*)(sqlite3_context*,int,sqlite3_value **),
  3940. // void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*),
  3941. // FuncDestructor *pDestructor
  3942. //);
  3943. //int sqlite3ApiExit(sqlite3 db, int);
  3944. //int sqlite3OpenTempDatabase(Parse *);
  3945. //void sqlite3StrAccumAppend(StrAccum*,const char*,int);
  3946. //char *sqlite3StrAccumFinish(StrAccum*);
  3947. //void sqlite3StrAccumReset(StrAccum*);
  3948. //void sqlite3SelectDestInit(SelectDest*,int,int);
  3949. //Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
  3950. //void sqlite3BackupRestart(sqlite3_backup *);
  3951. //void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
  3952. /*
  3953. ** The interface to the LEMON-generated parser
  3954. */
  3955. //void *sqlite3ParserAlloc(void*(*)(size_t));
  3956. //void sqlite3ParserFree(void*, void(*)(void*));
  3957. //void sqlite3Parser(void*, int, Token, Parse*);
  3958. #if YYTRACKMAXSTACKDEPTH
  3959. int sqlite3ParserStackPeak(void*);
  3960. #endif
  3961. //void sqlite3AutoLoadExtensions(sqlite3*);
  3962. #if !SQLITE_OMIT_LOAD_EXTENSION
  3963. //void sqlite3CloseExtensions(sqlite3*);
  3964. #else
  3965. //# define sqlite3CloseExtensions(X)
  3966. #endif
  3967. #if !SQLITE_OMIT_SHARED_CACHE
  3968. //void sqlite3TableLock(Parse *, int, int, u8, const char *);
  3969. #else
  3970. //#define sqlite3TableLock(v,w,x,y,z)
  3971. static void sqlite3TableLock( Parse p, int p1, int p2, u8 p3, byte[] p4 )
  3972. {
  3973. }
  3974. static void sqlite3TableLock( Parse p, int p1, int p2, u8 p3, string p4 )
  3975. {
  3976. }
  3977. #endif
  3978. #if SQLITE_TEST
  3979. ///int sqlite3Utf8To8(unsigned char*);
  3980. #endif
  3981. #if SQLITE_OMIT_VIRTUALTABLE
  3982. //# define sqlite3VtabClear(D, Y)
  3983. static void sqlite3VtabClear( sqlite3 db, Table Y )
  3984. {
  3985. }
  3986. //# define sqlite3VtabSync(X,Y) SQLITE_OK
  3987. static int sqlite3VtabSync( sqlite3 X, string Y )
  3988. {
  3989. return SQLITE_OK;
  3990. }
  3991. //# define sqlite3VtabRollback(X)
  3992. static void sqlite3VtabRollback( sqlite3 X )
  3993. {
  3994. }
  3995. //# define sqlite3VtabCommit(X)
  3996. static void sqlite3VtabCommit( sqlite3 X )
  3997. {
  3998. }
  3999. //# define sqlite3VtabInSync(db) 0
  4000. //# define sqlite3VtabLock(X)
  4001. static void sqlite3VtabLock( VTable X )
  4002. {
  4003. }
  4004. //# define sqlite3VtabUnlock(X)
  4005. static void sqlite3VtabUnlock( VTable X )
  4006. {
  4007. }
  4008. //# define sqlite3VtabUnlockList(X)
  4009. static void sqlite3VtabUnlockList( sqlite3 X )
  4010. {
  4011. }
  4012. static void sqlite3VtabArgExtend( Parse P, Token T )
  4013. {
  4014. }//# define sqlite3VtabArgExtend(P, T)
  4015. static void sqlite3VtabArgInit( Parse P )
  4016. {
  4017. }//# define sqlite3VtabArgInit(P)
  4018. static void sqlite3VtabBeginParse( Parse P, Token T, Token T1, Token T2 )
  4019. {
  4020. }//# define sqlite3VtabBeginParse(P, T, T1, T2);
  4021. static void sqlite3VtabFinishParse<T>( Parse P, T t )
  4022. {
  4023. }//# define sqlite3VtabFinishParse(P, T)
  4024. static bool sqlite3VtabInSync( sqlite3 db )
  4025. {
  4026. return false;
  4027. }
  4028. static VTable sqlite3GetVTable( sqlite3 db, Table T )
  4029. {
  4030. return null;
  4031. }
  4032. #else
  4033. //void sqlite3VtabClear(sqlite3 *db, Table*);
  4034. //int sqlite3VtabSync(sqlite3 db, int rc);
  4035. //int sqlite3VtabRollback(sqlite3 db);
  4036. //int sqlite3VtabCommit(sqlite3 db);
  4037. //void sqlite3VtabLock(VTable *);
  4038. //void sqlite3VtabUnlock(VTable *);
  4039. //void sqlite3VtabUnlockList(sqlite3*);
  4040. //# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
  4041. static bool sqlite3VtabInSync( sqlite3 db ) { return ( db.nVTrans > 0 && db.aVTrans == 0 ); }
  4042. #endif
  4043. //void sqlite3VtabMakeWritable(Parse*,Table*);
  4044. //void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
  4045. //void sqlite3VtabFinishParse(Parse*, Token*);
  4046. //void sqlite3VtabArgInit(Parse*);
  4047. //void sqlite3VtabArgExtend(Parse*, Token*);
  4048. //int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
  4049. //int sqlite3VtabCallConnect(Parse*, Table*);
  4050. //int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
  4051. //int sqlite3VtabBegin(sqlite3 *, VTable *);
  4052. //FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
  4053. //void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
  4054. //int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
  4055. //int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
  4056. //int sqlite3Reprepare(Vdbe*);
  4057. //void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
  4058. //CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
  4059. //int sqlite3TempInMemory(const sqlite3*);
  4060. //VTable *sqlite3GetVTable(sqlite3*, Table*);
  4061. //const char *sqlite3JournalModename(int);
  4062. //int sqlite3Checkpoint(sqlite3*, int);
  4063. //int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int);
  4064. /* Declarations for functions in fkey.c. All of these are replaced by
  4065. ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign
  4066. ** key functionality is available. If OMIT_TRIGGER is defined but
  4067. ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
  4068. ** this case foreign keys are parsed, but no other functionality is
  4069. ** provided (enforcement of FK constraints requires the triggers sub-system).
  4070. */
  4071. #if !(SQLITE_OMIT_FOREIGN_KEY) && !(SQLITE_OMIT_TRIGGER)
  4072. //void sqlite3FkCheck(Parse*, Table*, int, int);
  4073. //void sqlite3FkDropTable(Parse*, SrcList *, Table*);
  4074. //void sqlite3FkActions(Parse*, Table*, ExprList*, int);
  4075. //int sqlite3FkRequired(Parse*, Table*, int*, int);
  4076. //u32 sqlite3FkOldmask(Parse*, Table*);
  4077. //FKey *sqlite3FkReferences(Table *);
  4078. #else
  4079. //#define sqlite3FkActions(a,b,c,d)
  4080. static void sqlite3FkActions( Parse a, Table b, ExprList c, int d ) { }
  4081. //#define sqlite3FkCheck(a,b,c,d)
  4082. static void sqlite3FkCheck( Parse a, Table b, int c, int d ) { }
  4083. //#define sqlite3FkDropTable(a,b,c)
  4084. static void sqlite3FkDropTable( Parse a, SrcList b, Table c ) { }
  4085. //#define sqlite3FkOldmask(a,b) 0
  4086. static u32 sqlite3FkOldmask( Parse a, Table b ) { return 0; }
  4087. //#define sqlite3FkRequired(a,b,c,d) 0
  4088. static int sqlite3FkRequired( Parse a, Table b, int[] c, int d ) { return 0; }
  4089. #endif
  4090. #if !SQLITE_OMIT_FOREIGN_KEY
  4091. //void sqlite3FkDelete(sqlite3 *, Table*);
  4092. #else
  4093. //#define sqlite3FkDelete(a, b)
  4094. static void sqlite3FkDelete(sqlite3 a, Table b) {}
  4095. #endif
  4096. /*
  4097. ** Available fault injectors. Should be numbered beginning with 0.
  4098. */
  4099. const int SQLITE_FAULTINJECTOR_MALLOC = 0;//#define SQLITE_FAULTINJECTOR_MALLOC 0
  4100. const int SQLITE_FAULTINJECTOR_COUNT = 1;//#define SQLITE_FAULTINJECTOR_COUNT 1
  4101. /*
  4102. ** The interface to the code in fault.c used for identifying "benign"
  4103. ** malloc failures. This is only present if SQLITE_OMIT_BUILTIN_TEST
  4104. ** is not defined.
  4105. */
  4106. #if !SQLITE_OMIT_BUILTIN_TEST
  4107. //void sqlite3BeginBenignMalloc(void);
  4108. //void sqlite3EndBenignMalloc(void);
  4109. #else
  4110. //#define sqlite3BeginBenignMalloc()
  4111. //#define sqlite3EndBenignMalloc()
  4112. #endif
  4113. const int IN_INDEX_ROWID = 1;//#define IN_INDEX_ROWID 1
  4114. const int IN_INDEX_EPH = 2;//#define IN_INDEX_EPH 2
  4115. const int IN_INDEX_INDEX = 3;//#define IN_INDEX_INDEX 3
  4116. //int sqlite3FindInIndex(Parse *, Expr *, int*);
  4117. #if SQLITE_ENABLE_ATOMIC_WRITE
  4118. // int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
  4119. // int sqlite3JournalSize(sqlite3_vfs *);
  4120. // int sqlite3JournalCreate(sqlite3_file *);
  4121. #else
  4122. //#define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
  4123. static int sqlite3JournalSize( sqlite3_vfs pVfs )
  4124. {
  4125. return pVfs.szOsFile;
  4126. }
  4127. #endif
  4128. //void sqlite3MemJournalOpen(sqlite3_file *);
  4129. //int sqlite3MemJournalSize(void);
  4130. //int sqlite3IsMemJournal(sqlite3_file *);
  4131. #if SQLITE_MAX_EXPR_DEPTH//>0
  4132. // void sqlite3ExprSetHeight(Parse pParse, Expr p);
  4133. // int sqlite3SelectExprHeight(Select *);
  4134. //int sqlite3ExprCheckHeight(Parse*, int);
  4135. #else
  4136. //#define sqlite3ExprSetHeight(x,y)
  4137. //#define sqlite3SelectExprHeight(x) 0
  4138. //#define sqlite3ExprCheckHeight(x,y)
  4139. #endif
  4140. //u32 sqlite3Get4byte(const u8*);
  4141. //void sqlite3sqlite3Put4byte(u8*, u32);
  4142. #if SQLITE_ENABLE_UNLOCK_NOTIFY
  4143. void sqlite3ConnectionBlocked(sqlite3 *, sqlite3 *);
  4144. void sqlite3ConnectionUnlocked(sqlite3 *db);
  4145. void sqlite3ConnectionClosed(sqlite3 *db);
  4146. #else
  4147. static void sqlite3ConnectionBlocked( sqlite3 x, sqlite3 y )
  4148. {
  4149. } //#define sqlite3ConnectionBlocked(x,y)
  4150. static void sqlite3ConnectionUnlocked( sqlite3 x )
  4151. {
  4152. } //#define sqlite3ConnectionUnlocked(x)
  4153. static void sqlite3ConnectionClosed( sqlite3 x )
  4154. {
  4155. } //#define sqlite3ConnectionClosed(x)
  4156. #endif
  4157. #if SQLITE_DEBUG
  4158. // void sqlite3ParserTrace(FILE*, char *);
  4159. #endif
  4160. /*
  4161. ** If the SQLITE_ENABLE IOTRACE exists then the global variable
  4162. ** sqlite3IoTrace is a pointer to a printf-like routine used to
  4163. ** print I/O tracing messages.
  4164. */
  4165. #if SQLITE_ENABLE_IOTRACE
  4166. static bool SQLite3IoTrace = false;
  4167. //#define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; }
  4168. static void IOTRACE( string X, params object[] ap ) { if ( SQLite3IoTrace ) { printf( X, ap ); } }
  4169. // void sqlite3VdbeIOTraceSql(Vdbe);
  4170. //SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...);
  4171. #else
  4172. //#define IOTRACE(A)
  4173. static void IOTRACE( string F, params object[] ap )
  4174. {
  4175. }
  4176. //#define sqlite3VdbeIOTraceSql(X)
  4177. static void sqlite3VdbeIOTraceSql( Vdbe X )
  4178. {
  4179. }
  4180. #endif
  4181. /*
  4182. ** These routines are available for the mem2.c debugging memory allocator
  4183. ** only. They are used to verify that different "types" of memory
  4184. ** allocations are properly tracked by the system.
  4185. **
  4186. ** sqlite3MemdebugSetType() sets the "type" of an allocation to one of
  4187. ** the MEMTYPE_* macros defined below. The type must be a bitmask with
  4188. ** a single bit set.
  4189. **
  4190. ** sqlite3MemdebugHasType() returns true if any of the bits in its second
  4191. ** argument match the type set by the previous sqlite3MemdebugSetType().
  4192. ** sqlite3MemdebugHasType() is intended for use inside assert() statements.
  4193. **
  4194. ** sqlite3MemdebugNoType() returns true if none of the bits in its second
  4195. ** argument match the type set by the previous sqlite3MemdebugSetType().
  4196. **
  4197. ** Perhaps the most important point is the difference between MEMTYPE_HEAP
  4198. ** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means
  4199. ** it might have been allocated by lookaside, except the allocation was
  4200. ** too large or lookaside was already full. It is important to verify
  4201. ** that allocations that might have been satisfied by lookaside are not
  4202. ** passed back to non-lookaside free() routines. Asserts such as the
  4203. ** example above are placed on the non-lookaside free() routines to verify
  4204. ** this constraint.
  4205. **
  4206. ** All of this is no-op for a production build. It only comes into
  4207. ** play when the SQLITE_MEMDEBUG compile-time option is used.
  4208. */
  4209. #if SQLITE_MEMDEBUG
  4210. // void sqlite3MemdebugSetType(void*,u8);
  4211. // int sqlite3MemdebugHasType(void*,u8);
  4212. // int sqlite3MemdebugNoType(void*,u8);
  4213. #else
  4214. //# define sqlite3MemdebugSetType(X,Y) /* no-op */
  4215. static void sqlite3MemdebugSetType<T>( T X, int Y )
  4216. {
  4217. }
  4218. //# define sqlite3MemdebugHasType(X,Y) 1
  4219. static bool sqlite3MemdebugHasType<T>( T X, int Y )
  4220. {
  4221. return true;
  4222. }
  4223. //# define sqlite3MemdebugNoType(X,Y) 1
  4224. static bool sqlite3MemdebugNoType<T>( T X, int Y )
  4225. {
  4226. return true;
  4227. }
  4228. #endif
  4229. //#define MEMTYPE_HEAP 0x01 /* General heap allocations */
  4230. //#define MEMTYPE_LOOKASIDE 0x02 /* Might have been lookaside memory */
  4231. //#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
  4232. //#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
  4233. //#define MEMTYPE_DB 0x10 /* Uses sqlite3DbMalloc, not sqlite_malloc */
  4234. public const int MEMTYPE_HEAP = 0x01;
  4235. public const int MEMTYPE_LOOKASIDE = 0x02;
  4236. public const int MEMTYPE_SCRATCH = 0x04;
  4237. public const int MEMTYPE_PCACHE = 0x08;
  4238. public const int MEMTYPE_DB = 0x10;
  4239. //#endif //* _SQLITEINT_H_ */
  4240. }
  4241. }