Blame src/global.c

Packit 87b942
/*
Packit 87b942
** 2008 June 13
Packit 87b942
**
Packit 87b942
** The author disclaims copyright to this source code.  In place of
Packit 87b942
** a legal notice, here is a blessing:
Packit 87b942
**
Packit 87b942
**    May you do good and not evil.
Packit 87b942
**    May you find forgiveness for yourself and forgive others.
Packit 87b942
**    May you share freely, never taking more than you give.
Packit 87b942
**
Packit 87b942
*************************************************************************
Packit 87b942
**
Packit 87b942
** This file contains definitions of global variables and constants.
Packit 87b942
*/
Packit 87b942
#include "sqliteInt.h"
Packit 87b942
Packit 87b942
/* An array to map all upper-case characters into their corresponding
Packit 87b942
** lower-case character. 
Packit 87b942
**
Packit 87b942
** SQLite only considers US-ASCII (or EBCDIC) characters.  We do not
Packit 87b942
** handle case conversions for the UTF character set since the tables
Packit 87b942
** involved are nearly as big or bigger than SQLite itself.
Packit 87b942
*/
Packit 87b942
const unsigned char sqlite3UpperToLower[] = {
Packit 87b942
#ifdef SQLITE_ASCII
Packit 87b942
      0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
Packit 87b942
     18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
Packit 87b942
     36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
Packit 87b942
     54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103,
Packit 87b942
    104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,
Packit 87b942
    122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,
Packit 87b942
    108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
Packit 87b942
    126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
Packit 87b942
    144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,
Packit 87b942
    162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
Packit 87b942
    180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
Packit 87b942
    198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
Packit 87b942
    216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
Packit 87b942
    234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
Packit 87b942
    252,253,254,255
Packit 87b942
#endif
Packit 87b942
#ifdef SQLITE_EBCDIC
Packit 87b942
      0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, /* 0x */
Packit 87b942
     16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */
Packit 87b942
     32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */
Packit 87b942
     48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 3x */
Packit 87b942
     64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 4x */
Packit 87b942
     80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 5x */
Packit 87b942
     96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 6x */
Packit 87b942
    112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 7x */
Packit 87b942
    128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */
Packit 87b942
    144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, /* 9x */
Packit 87b942
    160,161,162,163,164,165,166,167,168,169,170,171,140,141,142,175, /* Ax */
Packit 87b942
    176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, /* Bx */
Packit 87b942
    192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */
Packit 87b942
    208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */
Packit 87b942
    224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */
Packit 87b942
    240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */
Packit 87b942
#endif
Packit 87b942
};
Packit 87b942
Packit 87b942
/*
Packit 87b942
** The following 256 byte lookup table is used to support SQLites built-in
Packit 87b942
** equivalents to the following standard library functions:
Packit 87b942
**
Packit 87b942
**   isspace()                        0x01
Packit 87b942
**   isalpha()                        0x02
Packit 87b942
**   isdigit()                        0x04
Packit 87b942
**   isalnum()                        0x06
Packit 87b942
**   isxdigit()                       0x08
Packit 87b942
**   toupper()                        0x20
Packit 87b942
**   SQLite identifier character      0x40
Packit 87b942
**   Quote character                  0x80
Packit 87b942
**
Packit 87b942
** Bit 0x20 is set if the mapped character requires translation to upper
Packit 87b942
** case. i.e. if the character is a lower-case ASCII character.
Packit 87b942
** If x is a lower-case ASCII character, then its upper-case equivalent
Packit 87b942
** is (x - 0x20). Therefore toupper() can be implemented as:
Packit 87b942
**
Packit 87b942
**   (x & ~(map[x]&0x20))
Packit 87b942
**
Packit 87b942
** The equivalent of tolower() is implemented using the sqlite3UpperToLower[]
Packit 87b942
** array. tolower() is used more often than toupper() by SQLite.
Packit 87b942
**
Packit 87b942
** Bit 0x40 is set if the character is non-alphanumeric and can be used in an 
Packit 87b942
** SQLite identifier.  Identifiers are alphanumerics, "_", "$", and any
Packit 87b942
** non-ASCII UTF character. Hence the test for whether or not a character is
Packit 87b942
** part of an identifier is 0x46.
Packit 87b942
*/
Packit 87b942
#ifdef SQLITE_ASCII
Packit 87b942
const unsigned char sqlite3CtypeMap[256] = {
Packit 87b942
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 00..07    ........ */
Packit 87b942
  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,  /* 08..0f    ........ */
Packit 87b942
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 10..17    ........ */
Packit 87b942
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 18..1f    ........ */
Packit 87b942
  0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80,  /* 20..27     !"#$%&' */
Packit 87b942
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 28..2f    ()*+,-./ */
Packit 87b942
  0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,  /* 30..37    01234567 */
Packit 87b942
  0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 38..3f    89:;<=>? */
Packit 87b942
Packit 87b942
  0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02,  /* 40..47    @ABCDEFG */
Packit 87b942
  0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,  /* 48..4f    HIJKLMNO */
Packit 87b942
  0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,  /* 50..57    PQRSTUVW */
Packit 87b942
  0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40,  /* 58..5f    XYZ[\]^_ */
Packit 87b942
  0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22,  /* 60..67    `abcdefg */
Packit 87b942
  0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,  /* 68..6f    hijklmno */
Packit 87b942
  0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,  /* 70..77    pqrstuvw */
Packit 87b942
  0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 78..7f    xyz{|}~. */
Packit 87b942
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* 80..87    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* 88..8f    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* 90..97    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* 98..9f    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* a0..a7    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* a8..af    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* b0..b7    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* b8..bf    ........ */
Packit 87b942
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* c0..c7    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* c8..cf    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* d0..d7    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* d8..df    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* e0..e7    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* e8..ef    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* f0..f7    ........ */
Packit 87b942
  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40   /* f8..ff    ........ */
Packit 87b942
};
Packit 87b942
#endif
Packit 87b942
Packit 87b942
/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
Packit 87b942
** compatibility for legacy applications, the URI filename capability is
Packit 87b942
** disabled by default.
Packit 87b942
**
Packit 87b942
** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
Packit 87b942
** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
Packit 87b942
**
Packit 87b942
** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
Packit 87b942
** disabled. The default value may be changed by compiling with the
Packit 87b942
** SQLITE_USE_URI symbol defined.
Packit 87b942
**
Packit 87b942
** URI filenames are enabled by default if SQLITE_HAS_CODEC is
Packit 87b942
** enabled.
Packit 87b942
*/
Packit 87b942
#ifndef SQLITE_USE_URI
Packit 87b942
# ifdef SQLITE_HAS_CODEC
Packit 87b942
#  define SQLITE_USE_URI 1
Packit 87b942
# else
Packit 87b942
#  define SQLITE_USE_URI 0
Packit 87b942
# endif
Packit 87b942
#endif
Packit 87b942
Packit 87b942
/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
Packit 87b942
** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
Packit 87b942
** that compile-time option is omitted.
Packit 87b942
*/
Packit 87b942
#ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
Packit 87b942
# define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
Packit 87b942
#endif
Packit 87b942
Packit 87b942
/* The minimum PMA size is set to this value multiplied by the database
Packit 87b942
** page size in bytes.
Packit 87b942
*/
Packit 87b942
#ifndef SQLITE_SORTER_PMASZ
Packit 87b942
# define SQLITE_SORTER_PMASZ 250
Packit 87b942
#endif
Packit 87b942
Packit 87b942
/* Statement journals spill to disk when their size exceeds the following
Packit 87b942
** threshold (in bytes). 0 means that statement journals are created and
Packit 87b942
** written to disk immediately (the default behavior for SQLite versions
Packit 87b942
** before 3.12.0).  -1 means always keep the entire statement journal in
Packit 87b942
** memory.  (The statement journal is also always held entirely in memory
Packit 87b942
** if journal_mode=MEMORY or if temp_store=MEMORY, regardless of this
Packit 87b942
** setting.)
Packit 87b942
*/
Packit 87b942
#ifndef SQLITE_STMTJRNL_SPILL 
Packit 87b942
# define SQLITE_STMTJRNL_SPILL (64*1024)
Packit 87b942
#endif
Packit 87b942
Packit 87b942
/*
Packit 87b942
** The default lookaside-configuration, the format "SZ,N".  SZ is the
Packit 87b942
** number of bytes in each lookaside slot (should be a multiple of 8)
Packit 87b942
** and N is the number of slots.  The lookaside-configuration can be
Packit 87b942
** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
Packit 87b942
** or at run-time for an individual database connection using
Packit 87b942
** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
Packit 87b942
*/
Packit 87b942
#ifndef SQLITE_DEFAULT_LOOKASIDE
Packit 87b942
# define SQLITE_DEFAULT_LOOKASIDE 1200,100
Packit 87b942
#endif
Packit 87b942
Packit 87b942
Packit 87b942
/*
Packit 87b942
** The following singleton contains the global configuration for
Packit 87b942
** the SQLite library.
Packit 87b942
*/
Packit 87b942
SQLITE_WSD struct Sqlite3Config sqlite3Config = {
Packit 87b942
   SQLITE_DEFAULT_MEMSTATUS,  /* bMemstat */
Packit 87b942
   1,                         /* bCoreMutex */
Packit 87b942
   SQLITE_THREADSAFE==1,      /* bFullMutex */
Packit 87b942
   SQLITE_USE_URI,            /* bOpenUri */
Packit 87b942
   SQLITE_ALLOW_COVERING_INDEX_SCAN,   /* bUseCis */
Packit 87b942
   0,                         /* bSmallMalloc */
Packit 87b942
   0x7ffffffe,                /* mxStrlen */
Packit 87b942
   0,                         /* neverCorrupt */
Packit 87b942
   SQLITE_DEFAULT_LOOKASIDE,  /* szLookaside, nLookaside */
Packit 87b942
   SQLITE_STMTJRNL_SPILL,     /* nStmtSpill */
Packit 87b942
   {0,0,0,0,0,0,0,0},         /* m */
Packit 87b942
   {0,0,0,0,0,0,0,0,0},       /* mutex */
Packit 87b942
   {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
Packit 87b942
   (void*)0,                  /* pHeap */
Packit 87b942
   0,                         /* nHeap */
Packit 87b942
   0, 0,                      /* mnHeap, mxHeap */
Packit 87b942
   SQLITE_DEFAULT_MMAP_SIZE,  /* szMmap */
Packit 87b942
   SQLITE_MAX_MMAP_SIZE,      /* mxMmap */
Packit 87b942
   (void*)0,                  /* pPage */
Packit 87b942
   0,                         /* szPage */
Packit 87b942
   SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */
Packit 87b942
   0,                         /* mxParserStack */
Packit 87b942
   0,                         /* sharedCacheEnabled */
Packit 87b942
   SQLITE_SORTER_PMASZ,       /* szPma */
Packit 87b942
   /* All the rest should always be initialized to zero */
Packit 87b942
   0,                         /* isInit */
Packit 87b942
   0,                         /* inProgress */
Packit 87b942
   0,                         /* isMutexInit */
Packit 87b942
   0,                         /* isMallocInit */
Packit 87b942
   0,                         /* isPCacheInit */
Packit 87b942
   0,                         /* nRefInitMutex */
Packit 87b942
   0,                         /* pInitMutex */
Packit 87b942
   0,                         /* xLog */
Packit 87b942
   0,                         /* pLogArg */
Packit 87b942
#ifdef SQLITE_ENABLE_SQLLOG
Packit 87b942
   0,                         /* xSqllog */
Packit 87b942
   0,                         /* pSqllogArg */
Packit 87b942
#endif
Packit 87b942
#ifdef SQLITE_VDBE_COVERAGE
Packit 87b942
   0,                         /* xVdbeBranch */
Packit 87b942
   0,                         /* pVbeBranchArg */
Packit 87b942
#endif
Packit 87b942
#ifndef SQLITE_UNTESTABLE
Packit 87b942
   0,                         /* xTestCallback */
Packit 87b942
#endif
Packit 87b942
   0,                         /* bLocaltimeFault */
Packit 87b942
   0x7ffffffe                 /* iOnceResetThreshold */
Packit 87b942
};
Packit 87b942
Packit 87b942
/*
Packit 87b942
** Hash table for global functions - functions common to all
Packit 87b942
** database connections.  After initialization, this table is
Packit 87b942
** read-only.
Packit 87b942
*/
Packit 87b942
FuncDefHash sqlite3BuiltinFunctions;
Packit 87b942
Packit 87b942
/*
Packit 87b942
** Constant tokens for values 0 and 1.
Packit 87b942
*/
Packit 87b942
const Token sqlite3IntTokens[] = {
Packit 87b942
   { "0", 1 },
Packit 87b942
   { "1", 1 }
Packit 87b942
};
Packit 87b942
Packit 87b942
Packit 87b942
/*
Packit 87b942
** The value of the "pending" byte must be 0x40000000 (1 byte past the
Packit 87b942
** 1-gibabyte boundary) in a compatible database.  SQLite never uses
Packit 87b942
** the database page that contains the pending byte.  It never attempts
Packit 87b942
** to read or write that page.  The pending byte page is set aside
Packit 87b942
** for use by the VFS layers as space for managing file locks.
Packit 87b942
**
Packit 87b942
** During testing, it is often desirable to move the pending byte to
Packit 87b942
** a different position in the file.  This allows code that has to
Packit 87b942
** deal with the pending byte to run on files that are much smaller
Packit 87b942
** than 1 GiB.  The sqlite3_test_control() interface can be used to
Packit 87b942
** move the pending byte.
Packit 87b942
**
Packit 87b942
** IMPORTANT:  Changing the pending byte to any value other than
Packit 87b942
** 0x40000000 results in an incompatible database file format!
Packit 87b942
** Changing the pending byte during operation will result in undefined
Packit 87b942
** and incorrect behavior.
Packit 87b942
*/
Packit 87b942
#ifndef SQLITE_OMIT_WSD
Packit 87b942
int sqlite3PendingByte = 0x40000000;
Packit 87b942
#endif
Packit 87b942
Packit 87b942
#include "opcodes.h"
Packit 87b942
/*
Packit 87b942
** Properties of opcodes.  The OPFLG_INITIALIZER macro is
Packit 87b942
** created by mkopcodeh.awk during compilation.  Data is obtained
Packit 87b942
** from the comments following the "case OP_xxxx:" statements in
Packit 87b942
** the vdbe.c file.  
Packit 87b942
*/
Packit 87b942
const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER;
Packit 87b942
Packit 87b942
/*
Packit 87b942
** Name of the default collating sequence
Packit 87b942
*/
Packit 87b942
const char sqlite3StrBINARY[] = "BINARY";